Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id F0D8D200D5B for ; Tue, 28 Nov 2017 21:54:15 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id EF541160C07; Tue, 28 Nov 2017 20:54:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 71B41160C19 for ; Tue, 28 Nov 2017 21:54:13 +0100 (CET) Received: (qmail 31800 invoked by uid 500); 28 Nov 2017 20:54:12 -0000 Mailing-List: contact commits-help@tomee.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tomee.apache.org Delivered-To: mailing list commits@tomee.apache.org Received: (qmail 31514 invoked by uid 99); 28 Nov 2017 20:54:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 28 Nov 2017 20:54:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0A106F6015; Tue, 28 Nov 2017 20:54:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jgallimore@apache.org To: commits@tomee.apache.org Date: Tue, 28 Nov 2017 20:54:17 -0000 Message-Id: In-Reply-To: <3ca5d27837894204a279e3dbaac9c534@git.apache.org> References: <3ca5d27837894204a279e3dbaac9c534@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/11] tomee git commit: TOMEE-2151 Use correct classloader for creating application resources specified in resources.xml. Added examples and arquillian tests. archived-at: Tue, 28 Nov 2017 20:54:16 -0000 http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Receiver.java ---------------------------------------------------------------------- diff --git a/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Receiver.java b/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Receiver.java new file mode 100644 index 0000000..5230129 --- /dev/null +++ b/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Receiver.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.application; + + +import org.superbiz.connector.api.InboundListener; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.MessageDriven; +import javax.ejb.MessageDrivenContext; + +@MessageDriven(name = "Receiver") +public class Receiver implements InboundListener { + + @EJB + private MessagesReceived messagesReceived; + + @Resource + private MessageDrivenContext context; + + @Override + public void receiveMessage(String message) { + messagesReceived.messageReceived(message); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Sender.java ---------------------------------------------------------------------- diff --git a/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Sender.java b/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Sender.java new file mode 100644 index 0000000..b51236d --- /dev/null +++ b/examples/connector-ear/connector-sample-war/src/main/java/org/superbiz/application/Sender.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.application; + +import org.superbiz.connector.api.SampleConnection; +import org.superbiz.connector.api.SampleConnectionFactory; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.Lock; +import javax.ejb.LockType; +import javax.ejb.Singleton; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.List; + +@Singleton +@Lock(LockType.READ) +@Path("") +public class Sender { + + @Resource + private SampleConnectionFactory cf; + + @EJB + private MessagesReceived messagesReceived; + + @POST + @Consumes(MediaType.TEXT_PLAIN) + public void sendMessage(final String message) { + try { + final SampleConnection connection = cf.getConnection(); + connection.sendMessage(message); + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getMessages() { + + final StringBuilder sb = new StringBuilder(); + + final List messages = this.messagesReceived.getMessagesReceived(); + for (int i = 0; i < messages.size(); i++) { + if (i > 0) { + sb.append("\n"); + } + + sb.append(messages.get(i)); + } + + return sb.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/LICENSE ---------------------------------------------------------------------- diff --git a/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/LICENSE b/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/LICENSE new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/NOTICE ---------------------------------------------------------------------- diff --git a/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/NOTICE b/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/NOTICE new file mode 100644 index 0000000..6631901 --- /dev/null +++ b/examples/connector-ear/connector-sample-war/src/main/resources/META-INF/NOTICE @@ -0,0 +1,7 @@ +Sample Connector :: Sample WAR +Copyright 2014 Tomitribe Corporation + +This product includes software developed at +Tomitribe Corporation (http://www.tomitribe.com/). + + http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-ear/connector-sample-war/src/main/webapp/WEB-INF/resources.xml ---------------------------------------------------------------------- diff --git a/examples/connector-ear/connector-sample-war/src/main/webapp/WEB-INF/resources.xml b/examples/connector-ear/connector-sample-war/src/main/webapp/WEB-INF/resources.xml new file mode 100644 index 0000000..8bcc6c8 --- /dev/null +++ b/examples/connector-ear/connector-sample-war/src/main/webapp/WEB-INF/resources.xml @@ -0,0 +1,30 @@ + + + + + + + + ResourceAdapter=SampleResourceAdapter + ActivationSpecClass=org.superbiz.connector.adapter.SampleActivationSpec + MessageListenerInterface=org.superbiz.connector.api.InboundListener + + + + ResourceAdapter=SampleResourceAdapter + TransactionSupport=none + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-ear/pom.xml ---------------------------------------------------------------------- diff --git a/examples/connector-ear/pom.xml b/examples/connector-ear/pom.xml new file mode 100644 index 0000000..ca27be5 --- /dev/null +++ b/examples/connector-ear/pom.xml @@ -0,0 +1,95 @@ + + + + + + + + 4.0.0 + + org.superbiz + connector-ear + pom + 1.1.1-SNAPSHOT + OpenEJB :: Connector Examples :: Connector in EAR + + + UTF-8 + 1.7.6-SNAPSHOT + 2.1.0 + + + + + apache-m2-snapshot + Apache Snapshot Repository + http://repository.apache.org/snapshots + + + + + + + junit + junit + 4.11 + test + + + org.apache.openejb + javaee-api + 6.0-6 + provided + + + + + + connector-sample-api + connector-sample-impl + connector-sample-rar + connector-sample-war + connector-sample-ear + connector-sample-functional-tests + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + 1.6 + 1.6 + + + + + + + + + + localhost + file://${basedir}/target/repo/ + + + localhost + file://${basedir}/target/snapshot-repo/ + + + http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/README.md ---------------------------------------------------------------------- diff --git a/examples/connector-war/README.md b/examples/connector-war/README.md new file mode 100644 index 0000000..37ccc5c --- /dev/null +++ b/examples/connector-war/README.md @@ -0,0 +1,340 @@ +Title: Movies Complete + +*Help us document this example! Click the blue pencil icon in the upper right to edit this page.* + +[![Try it out in Codenvy](https://tomitribe.github.io/codenvy/tryitout.svg)](https://codenvy.com/f?id=9er0fn1kh832sa35) + +## AddInterceptor + + package org.superbiz.injection.tx; + + import javax.interceptor.AroundInvoke; + import javax.interceptor.InvocationContext; + + /** + * @version $Revision$ $Date$ + */ + public class AddInterceptor { + + @AroundInvoke + public Object invoke(InvocationContext context) throws Exception { + // Log Add + return context.proceed(); + } + } + +## DeleteInterceptor + + package org.superbiz.injection.tx; + + import javax.interceptor.AroundInvoke; + import javax.interceptor.InvocationContext; + + /** + * @version $Revision$ $Date$ + */ + public class DeleteInterceptor { + + @AroundInvoke + public Object invoke(InvocationContext context) throws Exception { + // Log Delete + return context.proceed(); + } + } + +## Movie + + package org.superbiz.injection.tx; + + import javax.persistence.Entity; + + @Entity + public class Movie { + + private String director; + private String title; + private int year; + + public Movie() { + } + + public Movie(String director, String title, int year) { + this.director = director; + this.title = title; + this.year = year; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + } + +## Movies + + package org.superbiz.injection.tx; + + import javax.annotation.security.PermitAll; + import javax.annotation.security.RolesAllowed; + import javax.ejb.Stateful; + import javax.ejb.TransactionAttribute; + import javax.ejb.TransactionAttributeType; + import javax.interceptor.Interceptors; + import javax.persistence.EntityManager; + import javax.persistence.PersistenceContext; + import javax.persistence.PersistenceContextType; + import javax.persistence.Query; + import java.util.List; + + //START SNIPPET: code + @Stateful + public class Movies { + + @PersistenceContext(unitName = "movie-unit", type = PersistenceContextType.TRANSACTION) + private EntityManager entityManager; + + @RolesAllowed({"Employee", "Manager"}) + @TransactionAttribute(TransactionAttributeType.REQUIRED) + @Interceptors(AddInterceptor.class) + public void addMovie(Movie movie) throws Exception { + entityManager.persist(movie); + } + + @RolesAllowed({"Manager"}) + @TransactionAttribute(TransactionAttributeType.MANDATORY) + @Interceptors(DeleteInterceptor.class) + public void deleteMovie(Movie movie) throws Exception { + entityManager.remove(movie); + } + + @PermitAll + @TransactionAttribute(TransactionAttributeType.SUPPORTS) + public List getMovies() throws Exception { + Query query = entityManager.createQuery("SELECT m from Movie as m"); + return query.getResultList(); + } + } + +## ReadInterceptor + + package org.superbiz.injection.tx; + + import javax.interceptor.AroundInvoke; + import javax.interceptor.InvocationContext; + + /** + * @version $Revision$ $Date$ + */ + public class ReadInterceptor { + + @AroundInvoke + public Object invoke(InvocationContext context) throws Exception { + // Log Delete + return context.proceed(); + } + } + +## persistence.xml + + + + + movieDatabase + movieDatabaseUnmanaged + org.superbiz.injection.tx.Movie + + + + + + + +## MoviesTest + + package org.superbiz.injection.tx; + + import junit.framework.TestCase; + + import javax.annotation.security.RunAs; + import javax.ejb.EJB; + import javax.ejb.Stateless; + import javax.ejb.TransactionAttribute; + import javax.ejb.TransactionAttributeType; + import javax.ejb.embeddable.EJBContainer; + import java.util.List; + import java.util.Properties; + import java.util.concurrent.Callable; + + import static javax.ejb.TransactionAttributeType.REQUIRES_NEW; + + /** + * See the transaction-rollback example as it does the same thing + * via UserTransaction and shows more techniques for rollback + */ + //START SNIPPET: code + public class MoviesTest extends TestCase { + + @EJB + private Movies movies; + + @EJB(beanName = "TransactionBean") + private Caller transactionalCaller; + + @EJB(beanName = "NoTransactionBean") + private Caller nonTransactionalCaller; + + protected void setUp() throws Exception { + final Properties p = new Properties(); + p.put("movieDatabase", "new://Resource?type=DataSource"); + p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb"); + + EJBContainer.createEJBContainer(p).getContext().bind("inject", this); + } + + private void doWork() throws Exception { + + movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs", 1992)); + movies.addMovie(new Movie("Joel Coen", "Fargo", 1996)); + movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998)); + + List list = movies.getMovies(); + assertEquals("List.size()", 3, list.size()); + + for (Movie movie : list) { + movies.deleteMovie(movie); + } + + assertEquals("Movies.getMovies()", 0, movies.getMovies().size()); + } + + public void testWithTransaction() throws Exception { + transactionalCaller.call(new Callable() { + public Object call() throws Exception { + doWork(); + return null; + } + }); + } + + public void testWithoutTransaction() throws Exception { + try { + nonTransactionalCaller.call(new Callable() { + public Object call() throws Exception { + doWork(); + return null; + } + }); + fail("The Movies bean should be using TransactionAttributeType.MANDATORY"); + } catch (javax.ejb.EJBException e) { + // good, our Movies bean is using TransactionAttributeType.MANDATORY as we want + } + } + + + public static interface Caller { + public V call(Callable callable) throws Exception; + } + + /** + * This little bit of magic allows our test code to execute in + * the scope of a container controlled transaction. + */ + @Stateless + @RunAs("Manager") + @TransactionAttribute(REQUIRES_NEW) + public static class TransactionBean implements Caller { + + public V call(Callable callable) throws Exception { + return callable.call(); + } + } + + @Stateless + @RunAs("Manager") + @TransactionAttribute(TransactionAttributeType.NEVER) + public static class NoTransactionBean implements Caller { + + public V call(Callable callable) throws Exception { + return callable.call(); + } + } + } + +# Running + + + ------------------------------------------------------- + T E S T S + ------------------------------------------------------- + Running org.superbiz.injection.tx.MoviesTest + Apache OpenEJB 4.0.0-beta-1 build: 20111002-04:06 + http://tomee.apache.org/ + INFO - openejb.home = /Users/dblevins/examples/movies-complete + INFO - openejb.base = /Users/dblevins/examples/movies-complete + INFO - Using 'javax.ejb.embeddable.EJBContainer=true' + INFO - Configuring Service(id=Default Security Service, type=SecurityService, provider-id=Default Security Service) + INFO - Configuring Service(id=Default Transaction Manager, type=TransactionManager, provider-id=Default Transaction Manager) + INFO - Configuring Service(id=movieDatabase, type=Resource, provider-id=Default JDBC Database) + INFO - Found EjbModule in classpath: /Users/dblevins/examples/movies-complete/target/classes + INFO - Found EjbModule in classpath: /Users/dblevins/examples/movies-complete/target/test-classes + INFO - Beginning load: /Users/dblevins/examples/movies-complete/target/classes + INFO - Beginning load: /Users/dblevins/examples/movies-complete/target/test-classes + INFO - Configuring enterprise application: /Users/dblevins/examples/movies-complete + INFO - Configuring Service(id=Default Stateful Container, type=Container, provider-id=Default Stateful Container) + INFO - Auto-creating a container for bean Movies: Container(type=STATEFUL, id=Default Stateful Container) + INFO - Configuring Service(id=Default Stateless Container, type=Container, provider-id=Default Stateless Container) + INFO - Auto-creating a container for bean TransactionBean: Container(type=STATELESS, id=Default Stateless Container) + INFO - Configuring Service(id=Default Managed Container, type=Container, provider-id=Default Managed Container) + INFO - Auto-creating a container for bean org.superbiz.injection.tx.MoviesTest: Container(type=MANAGED, id=Default Managed Container) + INFO - Configuring PersistenceUnit(name=movie-unit) + INFO - Auto-creating a Resource with id 'movieDatabaseNonJta' of type 'DataSource for 'movie-unit'. + INFO - Configuring Service(id=movieDatabaseNonJta, type=Resource, provider-id=movieDatabase) + INFO - Adjusting PersistenceUnit movie-unit to Resource ID 'movieDatabaseNonJta' from 'movieDatabaseUnmanaged' + INFO - Enterprise application "/Users/dblevins/examples/movies-complete" loaded. + INFO - Assembling app: /Users/dblevins/examples/movies-complete + INFO - PersistenceUnit(name=movie-unit, provider=org.apache.openjpa.persistence.PersistenceProviderImpl) - provider time 402ms + INFO - Jndi(name="java:global/movies-complete/Movies!org.superbiz.injection.tx.Movies") + INFO - Jndi(name="java:global/movies-complete/Movies") + INFO - Jndi(name="java:global/movies-complete/TransactionBean!org.superbiz.injection.tx.MoviesTest$Caller") + INFO - Jndi(name="java:global/movies-complete/TransactionBean") + INFO - Jndi(name="java:global/movies-complete/NoTransactionBean!org.superbiz.injection.tx.MoviesTest$Caller") + INFO - Jndi(name="java:global/movies-complete/NoTransactionBean") + INFO - Jndi(name="java:global/EjbModule1013462002/org.superbiz.injection.tx.MoviesTest!org.superbiz.injection.tx.MoviesTest") + INFO - Jndi(name="java:global/EjbModule1013462002/org.superbiz.injection.tx.MoviesTest") + INFO - Created Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) + INFO - Created Ejb(deployment-id=NoTransactionBean, ejb-name=NoTransactionBean, container=Default Stateless Container) + INFO - Created Ejb(deployment-id=TransactionBean, ejb-name=TransactionBean, container=Default Stateless Container) + INFO - Created Ejb(deployment-id=org.superbiz.injection.tx.MoviesTest, ejb-name=org.superbiz.injection.tx.MoviesTest, container=Default Managed Container) + INFO - Started Ejb(deployment-id=Movies, ejb-name=Movies, container=Default Stateful Container) + INFO - Started Ejb(deployment-id=NoTransactionBean, ejb-name=NoTransactionBean, container=Default Stateless Container) + INFO - Started Ejb(deployment-id=TransactionBean, ejb-name=TransactionBean, container=Default Stateless Container) + INFO - Started Ejb(deployment-id=org.superbiz.injection.tx.MoviesTest, ejb-name=org.superbiz.injection.tx.MoviesTest, container=Default Managed Container) + INFO - Deployed Application(path=/Users/dblevins/examples/movies-complete) + INFO - EJBContainer already initialized. Call ejbContainer.close() to allow reinitialization + Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.418 sec + + Results : + + Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/pom.xml ---------------------------------------------------------------------- diff --git a/examples/connector-war/pom.xml b/examples/connector-war/pom.xml new file mode 100644 index 0000000..d07f36c --- /dev/null +++ b/examples/connector-war/pom.xml @@ -0,0 +1,165 @@ + + + + + + + 4.0.0 + org.superbiz + connector-war + war + 1.1.1-SNAPSHOT + OpenEJB :: Connector Examples :: Connector in WAR + + UTF-8 + 1.7.6-SNAPSHOT + 2.1.0 + + + + apache-m2-snapshot + Apache Snapshot Repository + http://repository.apache.org/snapshots + + + + connector-war + install + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.6 + 1.6 + + + + org.apache.openejb.maven + tomee-maven-plugin + 1.7.6-SNAPSHOT + + plus + -Xmx512m -XX:PermSize=256m + + + + maven-war-plugin + 2.2 + + + default-war + package + + war + + + + + false + + + + + + src/test/resources + true + + + + + + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-bom + ${version.shrinkwrap.resolver} + import + pom + + + + org.jboss.arquillian + arquillian-bom + 1.1.2.Final + import + pom + + + + + + org.apache.openejb + javaee-api + 6.0-6 + provided + + + junit + junit + 4.12 + test + + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-depchain + pom + test + + + org.apache.openejb + ziplock + ${tomee.version} + test + + + org.apache.openejb + tomee-jaxrs + ${tomee.version} + test + + + org.apache.openejb + arquillian-tomee-remote + ${tomee.version} + test + + + org.apache.openejb + apache-tomee + plus + ${tomee.version} + zip + provided + + + + + + localhost + file://${basedir}/target/repo/ + + + localhost + file://${basedir}/target/snapshot-repo/ + + + http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleActivationSpec.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleActivationSpec.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleActivationSpec.java new file mode 100644 index 0000000..466f13e --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleActivationSpec.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.connector.adapter; + +import org.superbiz.connector.api.InboundListener; + +import javax.resource.ResourceException; +import javax.resource.spi.Activation; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.InvalidPropertyException; +import javax.resource.spi.ResourceAdapter; + +@Activation(messageListeners = InboundListener.class) +public class SampleActivationSpec implements ActivationSpec { + + private ResourceAdapter resourceAdapter; + private Class beanClass; + + public Class getBeanClass() { + return beanClass; + } + + public void setBeanClass(Class beanClass) { + this.beanClass = beanClass; + } + + @Override + public void validate() throws InvalidPropertyException { + } + + @Override + public ResourceAdapter getResourceAdapter() { + return resourceAdapter; + } + + @Override + public void setResourceAdapter(ResourceAdapter ra) throws ResourceException { + this.resourceAdapter = ra; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionFactoryImpl.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionFactoryImpl.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionFactoryImpl.java new file mode 100755 index 0000000..2263787 --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionFactoryImpl.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.connector.adapter; + +import org.superbiz.connector.api.SampleConnection; +import org.superbiz.connector.api.SampleConnectionFactory; + +import javax.naming.NamingException; +import javax.naming.Reference; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionManager; +import java.util.logging.Logger; + +public class SampleConnectionFactoryImpl implements SampleConnectionFactory { + private static final long serialVersionUID = 1L; + + private static Logger log = Logger.getLogger(SampleConnectionFactoryImpl.class.getName()); + + private Reference reference; + + private SampleManagedConnectionFactory mcf; + + private ConnectionManager connectionManager; + + public SampleConnectionFactoryImpl() { + + } + + public SampleConnectionFactoryImpl(SampleManagedConnectionFactory mcf, ConnectionManager cxManager) { + this.mcf = mcf; + this.connectionManager = cxManager; + } + + @Override + public SampleConnection getConnection() throws ResourceException { + log.finest("getConnection()"); + return (SampleConnection) connectionManager.allocateConnection(mcf, null); + } + + @Override + public Reference getReference() throws NamingException { + log.finest("getReference()"); + return reference; + } + + @Override + public void setReference(Reference reference) { + log.finest("setReference()"); + this.reference = reference; + } + + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionImpl.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionImpl.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionImpl.java new file mode 100755 index 0000000..60ef137 --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleConnectionImpl.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.connector.adapter; + +import org.superbiz.connector.api.SampleConnection; + +import java.util.logging.Logger; + +public class SampleConnectionImpl implements SampleConnection { + private static Logger log = Logger.getLogger(SampleConnectionImpl.class.getName()); + + private SampleManagedConnection mc; + + private SampleManagedConnectionFactory mcf; + + public SampleConnectionImpl(SampleManagedConnection mc, SampleManagedConnectionFactory mcf) { + this.mc = mc; + this.mcf = mcf; + } + + public void sendMessage(final String message) { + mc.sendMessage(message); + } + + public void close() { + mc.closeHandle(this); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnection.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnection.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnection.java new file mode 100755 index 0000000..958b821 --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnection.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.connector.adapter; + +import org.superbiz.connector.api.SampleConnection; + +import javax.resource.NotSupportedException; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionEvent; +import javax.resource.spi.ConnectionEventListener; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.LocalTransaction; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionMetaData; +import javax.security.auth.Subject; +import javax.transaction.xa.XAResource; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.logging.Logger; + +public class SampleManagedConnection implements ManagedConnection { + + private static Logger log = Logger.getLogger(SampleManagedConnection.class.getName()); + + private PrintWriter logwriter; + + private SampleManagedConnectionFactory mcf; + + private List listeners; + + private SampleConnectionImpl connection; + + public SampleManagedConnection(SampleManagedConnectionFactory mcf) { + this.mcf = mcf; + this.logwriter = null; + this.listeners = Collections.synchronizedList(new ArrayList(1)); + this.connection = null; + } + + public Object getConnection(Subject subject, + ConnectionRequestInfo cxRequestInfo) throws ResourceException { + log.finest("getConnection()"); + connection = new SampleConnectionImpl(this, mcf); + return connection; + } + + public void associateConnection(Object connection) throws ResourceException { + log.finest("associateConnection()"); + + if (connection == null) + throw new ResourceException("Null connection handle"); + + if (!(connection instanceof SampleConnectionImpl)) + throw new ResourceException("Wrong connection handle"); + + this.connection = (SampleConnectionImpl) connection; + } + + public void cleanup() throws ResourceException { + log.finest("cleanup()"); + } + + public void destroy() throws ResourceException { + log.finest("destroy()"); + } + + public void addConnectionEventListener(ConnectionEventListener listener) { + log.finest("addConnectionEventListener()"); + + if (listener == null) { + throw new IllegalArgumentException("Listener is null"); + } + + listeners.add(listener); + } + + public void removeConnectionEventListener(ConnectionEventListener listener) { + log.finest("removeConnectionEventListener()"); + if (listener == null) + throw new IllegalArgumentException("Listener is null"); + listeners.remove(listener); + } + + void closeHandle(SampleConnection handle) { + ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED); + event.setConnectionHandle(handle); + for (ConnectionEventListener cel : listeners) { + cel.connectionClosed(event); + } + } + + public PrintWriter getLogWriter() throws ResourceException { + log.finest("getLogWriter()"); + return logwriter; + } + + public void setLogWriter(PrintWriter out) throws ResourceException { + log.finest("setLogWriter()"); + logwriter = out; + } + + public LocalTransaction getLocalTransaction() throws ResourceException { + throw new NotSupportedException("getLocalTransaction() not supported"); + } + + public XAResource getXAResource() throws ResourceException { + throw new NotSupportedException("getXAResource() not supported"); + } + + public ManagedConnectionMetaData getMetaData() throws ResourceException { + log.finest("getMetaData()"); + return new SampleManagedConnectionMetaData(); + } + + void sendMessage(final String message) { + log.finest("sendMessage()"); + + final SampleResourceAdapter resourceAdapter = (SampleResourceAdapter) mcf.getResourceAdapter(); + resourceAdapter.sendMessage(message); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionFactory.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionFactory.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionFactory.java new file mode 100755 index 0000000..cace75f --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionFactory.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.connector.adapter; + +import org.superbiz.connector.api.SampleConnection; +import org.superbiz.connector.api.SampleConnectionFactory; + +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionDefinition; +import javax.resource.spi.ConnectionManager; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionFactory; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterAssociation; +import javax.security.auth.Subject; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.Set; +import java.util.logging.Logger; + +@ConnectionDefinition(connectionFactory = SampleConnectionFactory.class, + connectionFactoryImpl = SampleConnectionFactoryImpl.class, + connection = SampleConnection.class, + connectionImpl = SampleConnectionImpl.class) +public class SampleManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation { + + private static final long serialVersionUID = 1L; + + private static Logger log = Logger.getLogger(SampleManagedConnectionFactory.class.getName()); + + private ResourceAdapter ra; + + private PrintWriter logwriter; + + public SampleManagedConnectionFactory() { + + } + + public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException { + log.finest("createConnectionFactory()"); + return new SampleConnectionFactoryImpl(this, cxManager); + } + + public Object createConnectionFactory() throws ResourceException { + throw new ResourceException("This resource adapter doesn't support non-managed environments"); + } + + public ManagedConnection createManagedConnection(Subject subject, + ConnectionRequestInfo cxRequestInfo) throws ResourceException { + log.finest("createManagedConnection()"); + return new SampleManagedConnection(this); + } + + public ManagedConnection matchManagedConnections(Set connectionSet, + Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { + log.finest("matchManagedConnections()"); + ManagedConnection result = null; + Iterator it = connectionSet.iterator(); + while (result == null && it.hasNext()) { + ManagedConnection mc = (ManagedConnection) it.next(); + if (mc instanceof SampleManagedConnection) { + result = mc; + } + + } + return result; + } + + public PrintWriter getLogWriter() throws ResourceException { + log.finest("getLogWriter()"); + return logwriter; + } + + public void setLogWriter(PrintWriter out) throws ResourceException { + log.finest("setLogWriter()"); + logwriter = out; + } + + public ResourceAdapter getResourceAdapter() { + log.finest("getResourceAdapter()"); + return ra; + } + + public void setResourceAdapter(ResourceAdapter ra) { + log.finest("setResourceAdapter()"); + this.ra = ra; + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionMetaData.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionMetaData.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionMetaData.java new file mode 100755 index 0000000..d7a0fa9 --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleManagedConnectionMetaData.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.connector.adapter; + +import javax.resource.ResourceException; +import javax.resource.spi.ManagedConnectionMetaData; +import java.util.logging.Logger; + +public class SampleManagedConnectionMetaData implements ManagedConnectionMetaData { + + private static Logger log = Logger.getLogger(SampleManagedConnectionMetaData.class.getName()); + + public SampleManagedConnectionMetaData() { + + } + + @Override + public String getEISProductName() throws ResourceException { + log.finest("getEISProductName()"); + return null; //TODO + } + + @Override + public String getEISProductVersion() throws ResourceException { + log.finest("getEISProductVersion()"); + return null; //TODO + } + + @Override + public int getMaxConnections() throws ResourceException { + log.finest("getMaxConnections()"); + return 0; //TODO + } + + @Override + public String getUserName() throws ResourceException { + log.finest("getUserName()"); + return null; //TODO + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleResourceAdapter.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleResourceAdapter.java b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleResourceAdapter.java new file mode 100644 index 0000000..ca1fc8f --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/adapter/SampleResourceAdapter.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.connector.adapter; + +import org.superbiz.connector.api.InboundListener; + +import javax.resource.ResourceException; +import javax.resource.spi.ActivationSpec; +import javax.resource.spi.BootstrapContext; +import javax.resource.spi.Connector; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterInternalException; +import javax.resource.spi.endpoint.MessageEndpoint; +import javax.resource.spi.endpoint.MessageEndpointFactory; +import javax.transaction.xa.XAResource; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.lang.IllegalStateException; + +@Connector(description = "Sample Resource Adapter", displayName = "Sample Resource Adapter", eisType = "Sample Resource Adapter", version = "1.0") +public class SampleResourceAdapter implements ResourceAdapter { + + final Map targets = new ConcurrentHashMap(); + + public void start(BootstrapContext bootstrapContext) throws ResourceAdapterInternalException { + } + + public void stop() { + } + + public void endpointActivation(final MessageEndpointFactory messageEndpointFactory, final ActivationSpec activationSpec) + throws ResourceException + { + final SampleActivationSpec sampleActivationSpec = (SampleActivationSpec) activationSpec; + + try { + final MessageEndpoint messageEndpoint = messageEndpointFactory.createEndpoint(null); + final EndpointTarget target = new EndpointTarget(messageEndpoint); + targets.put(sampleActivationSpec, target); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void endpointDeactivation(MessageEndpointFactory messageEndpointFactory, ActivationSpec activationSpec) { + final SampleActivationSpec sampleActivationSpec = (SampleActivationSpec) activationSpec; + + final EndpointTarget endpointTarget = targets.get(sampleActivationSpec); + if (endpointTarget == null) { + throw new IllegalStateException("No EndpointTarget to undeploy for ActivationSpec " + activationSpec); + } + + endpointTarget.messageEndpoint.release(); + } + + public XAResource[] getXAResources(ActivationSpec[] activationSpecs) throws ResourceException { + return new XAResource[0]; + } + + public void sendMessage(final String message) { + final Collection endpoints = this.targets.values(); + for (final EndpointTarget endpoint : endpoints) { + endpoint.invoke(message); + } + } + + public static class EndpointTarget { + private final MessageEndpoint messageEndpoint; + + public EndpointTarget(final MessageEndpoint messageEndpoint) { + this.messageEndpoint = messageEndpoint; + } + + public void invoke(final String message) { + ((InboundListener)this.messageEndpoint).receiveMessage(message); + } + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/api/InboundListener.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/api/InboundListener.java b/examples/connector-war/src/main/java/org/superbiz/connector/api/InboundListener.java new file mode 100644 index 0000000..1c80ebc --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/api/InboundListener.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.connector.api; + +/** + * @version $Revision$ $Date$ + */ +public interface InboundListener { + public void receiveMessage(final String message); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnection.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnection.java b/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnection.java new file mode 100755 index 0000000..990471f --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnection.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.superbiz.connector.api; + +public interface SampleConnection { + public void sendMessage(final String message); + + public void close(); +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnectionFactory.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnectionFactory.java b/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnectionFactory.java new file mode 100755 index 0000000..0ffa4f5 --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/api/SampleConnectionFactory.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.superbiz.connector.api; + +import javax.resource.Referenceable; +import javax.resource.ResourceException; +import java.io.Serializable; + +public interface SampleConnectionFactory extends Serializable, Referenceable { + public SampleConnection getConnection() throws ResourceException; + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/application/MessagesReceived.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/application/MessagesReceived.java b/examples/connector-war/src/main/java/org/superbiz/connector/application/MessagesReceived.java new file mode 100644 index 0000000..0adcb3f --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/application/MessagesReceived.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.connector.application; + +import javax.ejb.Singleton; +import java.util.ArrayList; +import java.util.List; + +@Singleton +public class MessagesReceived { + + private final List messagesReceived = new ArrayList(); + + public List getMessagesReceived() { + return messagesReceived; + } + + public void messageReceived(final String message) { + messagesReceived.add(message); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/application/Receiver.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/application/Receiver.java b/examples/connector-war/src/main/java/org/superbiz/connector/application/Receiver.java new file mode 100644 index 0000000..dab2d5e --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/application/Receiver.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.connector.application; + +import org.superbiz.connector.api.InboundListener; + +import javax.ejb.EJB; +import javax.ejb.MessageDriven; + + +import javax.annotation.Resource; +import javax.ejb.MessageDrivenContext; + +@MessageDriven(name = "Receiver") +public class Receiver implements InboundListener { + + @EJB + private MessagesReceived messagesReceived; + + @Resource + private MessageDrivenContext context; + + @Override + public void receiveMessage(String message) { + messagesReceived.messageReceived(message); + } +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/java/org/superbiz/connector/application/Sender.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/java/org/superbiz/connector/application/Sender.java b/examples/connector-war/src/main/java/org/superbiz/connector/application/Sender.java new file mode 100644 index 0000000..888f11b --- /dev/null +++ b/examples/connector-war/src/main/java/org/superbiz/connector/application/Sender.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.connector.application; + +import org.superbiz.connector.api.SampleConnection; +import org.superbiz.connector.api.SampleConnectionFactory; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.Lock; +import javax.ejb.LockType; +import javax.ejb.Singleton; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import java.util.List; + +@Singleton +@Lock(LockType.READ) +@Path("") +public class Sender { + + @Resource + private SampleConnectionFactory cf; + + @EJB + private MessagesReceived messagesReceived; + + @POST + @Consumes(MediaType.TEXT_PLAIN) + public void sendMessage(final String message) { + try { + final SampleConnection connection = cf.getConnection(); + connection.sendMessage(message); + connection.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getMessages() { + + final StringBuilder sb = new StringBuilder(); + + final List messages = this.messagesReceived.getMessagesReceived(); + for (int i = 0; i < messages.size(); i++) { + if (i > 0) { + sb.append("\n"); + } + + sb.append(messages.get(i)); + } + + return sb.toString(); + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/main/webapp/WEB-INF/resources.xml ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/main/webapp/WEB-INF/resources.xml b/examples/connector-war/src/main/webapp/WEB-INF/resources.xml new file mode 100644 index 0000000..8bcc6c8 --- /dev/null +++ b/examples/connector-war/src/main/webapp/WEB-INF/resources.xml @@ -0,0 +1,30 @@ + + + + + + + + ResourceAdapter=SampleResourceAdapter + ActivationSpecClass=org.superbiz.connector.adapter.SampleActivationSpec + MessageListenerInterface=org.superbiz.connector.api.InboundListener + + + + ResourceAdapter=SampleResourceAdapter + TransactionSupport=none + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/test/java/org/superbiz/moviefun/ConnectorInWarTest.java ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/test/java/org/superbiz/moviefun/ConnectorInWarTest.java b/examples/connector-war/src/test/java/org/superbiz/moviefun/ConnectorInWarTest.java new file mode 100644 index 0000000..ce48736 --- /dev/null +++ b/examples/connector-war/src/test/java/org/superbiz/moviefun/ConnectorInWarTest.java @@ -0,0 +1,59 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.superbiz.moviefun; + +import org.apache.cxf.jaxrs.client.WebClient; +import org.apache.ziplock.maven.Mvn; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.net.URL; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +public class ConnectorInWarTest { + + @ArquillianResource + private URL webappUrl; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + final WebArchive webArchive = new Mvn.Builder().build(WebArchive.class); + System.out.println(webArchive.toString(true)); + + return webArchive; + } + + @Test + public void testShouldMakeSureWebappIsWorking() throws Exception { + final WebClient webClient = WebClient.create(webappUrl.toURI()); + final Response response = webClient.path("").type(MediaType.TEXT_PLAIN_TYPE).post("Hello, world"); + + assertEquals(204, response.getStatus()); + final String result = webClient.path("").accept(MediaType.TEXT_PLAIN_TYPE).get(String.class); + + assertEquals("Hello, world", result); + } + +} http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/connector-war/src/test/resources/arquillian.xml ---------------------------------------------------------------------- diff --git a/examples/connector-war/src/test/resources/arquillian.xml b/examples/connector-war/src/test/resources/arquillian.xml new file mode 100644 index 0000000..4ec117e --- /dev/null +++ b/examples/connector-war/src/test/resources/arquillian.xml @@ -0,0 +1,34 @@ + + + + + + + -1 + -1 + ${tomee.version} + plus + ${tomee.version} + target/apache-tomee-remote + target/arquillian-test-working-dir + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/tomee/blob/b2d2cc08/examples/pom.xml ---------------------------------------------------------------------- diff --git a/examples/pom.xml b/examples/pom.xml index e15998c..9656e8b 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -59,6 +59,8 @@ change-jaxws-url component-interfaces client-resource-lookup-preview + connector-ear + connector-war cucumber-jvm custom-injection datasource-ciphered-password @@ -125,6 +127,7 @@ schedule-methods server-events simple-cdi-interceptor + simple-ear simple-cmp2 simple-mdb-and-cdi simple-mdb