Author: rmannibucau
Date: Wed Aug 22 00:51:40 2012
New Revision: 1375867
URL: http://svn.apache.org/viewvc?rev=1375867&view=rev
Log:
TOMEE-393 adding a sample for client jndi tree
Added:
openejb/trunk/openejb/examples/client-resource-lookup-preview/
openejb/trunk/openejb/examples/client-resource-lookup-preview/pom.xml
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/client/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/client/Sender.java
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/Listener.java
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/MessageServlet.java
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/resources/
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/resources/arquillian.xml
Modified:
openejb/trunk/openejb/examples/pom.xml
Added: openejb/trunk/openejb/examples/client-resource-lookup-preview/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/client-resource-lookup-preview/pom.xml?rev=1375867&view=auto
==============================================================================
--- openejb/trunk/openejb/examples/client-resource-lookup-preview/pom.xml
(added)
+++ openejb/trunk/openejb/examples/client-resource-lookup-preview/pom.xml Wed
Aug 22 00:51:40 2012
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+ -->
+
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.superbiz</groupId>
+ <artifactId>client-resource-lookup-preview</artifactId>
+ <packaging>jar</packaging>
+ <version>1.1-SNAPSHOT</version>
+ <name>OpenEJB :: Examples :: Client Resource Lookup</name>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <defaultGoal>install</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.4</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>apache-m2-snapshot</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://repository.apache.org/snapshots</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>javaee-api</artifactId>
+ <version>6.0-4</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-client</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>openejb-ejbd</artifactId>
+ <version>4.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <version>5.6.0</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.10</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>arquillian-tomee-remote</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.arquillian.junit</groupId>
+ <artifactId>arquillian-junit-container</artifactId>
+ <version>1.0.1.Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openejb</groupId>
+ <artifactId>ziplock</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <!-- This section allows you to configure where to publish libraries for
+ sharing. It is not required and may be deleted. For more information see:
+ http://maven.apache.org/plugins/maven-deploy-plugin/ -->
+ <distributionManagement>
+ <repository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/repo/</url>
+ </repository>
+ <snapshotRepository>
+ <id>localhost</id>
+ <url>file://${basedir}/target/snapshot-repo/</url>
+ </snapshotRepository>
+ </distributionManagement>
+
+ </project>
\ No newline at end of file
Added:
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/client/Sender.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/client/Sender.java?rev=1375867&view=auto
==============================================================================
---
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/client/Sender.java
(added)
+++
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/main/java/org/superbiz/client/Sender.java
Wed Aug 22 00:51:40 2012
@@ -0,0 +1,65 @@
+/**
+ * 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.client;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.util.Properties;
+
+public class Sender {
+ private Sender() {
+ // no-op
+ }
+
+ public static void send(final String providerUrl, final String message)
throws Exception {
+ final Properties properties = new Properties();
+ properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.RemoteInitialContextFactory");
+ properties.setProperty(Context.PROVIDER_URL, providerUrl);
+ final Context context = new InitialContext(properties);
+
+ final Queue destination = (Queue) context.lookup("java:aQueue");
+ final ConnectionFactory connectionFactory = (ConnectionFactory)
context.lookup("java:aConnectionFactory");
+
+ Connection connection = null;
+ Session session = null;
+ MessageProducer producer = null;
+ try {
+ connection = connectionFactory.createConnection();
+ session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
+ producer = session.createProducer(destination);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ producer.send(session.createTextMessage(message));
+ } finally {
+ if (producer != null) {
+ producer.close();
+ }
+ if (session != null) {
+ session.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ }
+ }
+}
Added:
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java?rev=1375867&view=auto
==============================================================================
---
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java
(added)
+++
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/SenderTest.java
Wed Aug 22 00:51:40 2012
@@ -0,0 +1,89 @@
+/**
+ * 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.client;
+
+import org.apache.ziplock.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.superbiz.client.app.Listener;
+
+import java.net.URL;
+
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+
+@RunAsClient
+@RunWith(Arquillian.class)
+public class SenderTest {
+ private static final String APP_NAME = "app-server";
+ private static final String MESSAGE = "sender test message";
+
+ // this sample is just about configuration so
+ // to avoid complicated code in this demo we use sleep
+ // shouldn't be done this way in real life
+ private static final int RETRY = 10;
+ private static final int SLEEP_RETRY = 500;
+
+ @ArquillianResource
+ private URL url;
+
+ @Deployment
+ public static WebArchive war() {
+ return ShrinkWrap.create(WebArchive.class, APP_NAME + ".war")
+ .addPackage(Listener.class.getPackage());
+
+ }
+
+ @BeforeClass
+ public static void configureClientResources() {
+ // can be set this way or with the key Resource/<type>
+ // in fact we create on client side a mini jndi tree
+ // the key is the jndi name (the one used for the lookup)
+ System.setProperty("aConnectionFactory",
"connectionfactory:org.apache.activemq.ActiveMQConnectionFactory:tcp://localhost:61616");
+ System.setProperty("aQueue",
"queue:org.apache.activemq.command.ActiveMQQueue:LISTENER");
+ }
+
+ @Test
+ public void send() throws Exception {
+ final String rawUrl = url.toExternalForm(); // app-server webapp url
+ final String providerUrl = rawUrl.substring(0, rawUrl.length() -
APP_NAME.length() - 1) + "tomee/ejb";
+
+ // send the message
+ Sender.send(providerUrl, MESSAGE);
+
+ // check the message was received, we can need to wait a bit
+ for (int i = 0; i < RETRY; i++) {
+ final String message = IO.slurp(new URL(rawUrl + "messages")); //
the servlet URL
+ System.out.println("Server received: " + message);
+ try {
+ assertThat(message, containsString(MESSAGE));
+ return; // done!
+ } catch (AssertionError ae) {
+ Thread.sleep(SLEEP_RETRY); // wait a bit that the message was
received
+ }
+ }
+ fail();
+ }
+}
Added:
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/Listener.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/Listener.java?rev=1375867&view=auto
==============================================================================
---
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/Listener.java
(added)
+++
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/Listener.java
Wed Aug 22 00:51:40 2012
@@ -0,0 +1,46 @@
+/**
+ * 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.client.app;
+
+import javax.ejb.ActivationConfigProperty;
+import javax.ejb.MessageDriven;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.TextMessage;
+import java.util.ArrayList;
+import java.util.List;
+
+@MessageDriven(activationConfig = {
+ @ActivationConfigProperty(propertyName = "destination", propertyValue
= "LISTENER"),
+ @ActivationConfigProperty(propertyName = "destinationType",
propertyValue = "javax.jms.Queue")
+})
+public class Listener implements MessageListener {
+ public static List<String> MESSAGES = new ArrayList<String>();
+
+ @Override
+ public void onMessage(final Message message) {
+ System.out.println(">>> Got '" + message + "'");
+ if (message instanceof TextMessage) {
+ try {
+ MESSAGES.add(((TextMessage) message).getText());
+ } catch (JMSException ignored) {
+ // no-op
+ }
+ }
+ }
+}
Added:
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/MessageServlet.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/MessageServlet.java?rev=1375867&view=auto
==============================================================================
---
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/MessageServlet.java
(added)
+++
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/java/org/superbiz/client/app/MessageServlet.java
Wed Aug 22 00:51:40 2012
@@ -0,0 +1,32 @@
+/**
+ * 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.client.app;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+@WebServlet(urlPatterns = "/messages")
+public class MessageServlet extends HttpServlet {
+ @Override
+ protected void service(final HttpServletRequest req, final
HttpServletResponse resp) throws ServletException, IOException {
+ resp.getWriter().write(Listener.MESSAGES.toString());
+ }
+}
Added:
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/resources/arquillian.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/resources/arquillian.xml?rev=1375867&view=auto
==============================================================================
---
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/resources/arquillian.xml
(added)
+++
openejb/trunk/openejb/examples/client-resource-lookup-preview/src/test/resources/arquillian.xml
Wed Aug 22 00:51:40 2012
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+-->
+<arquillian xmlns="http://jboss.org/schema/arquillian"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+ <container qualifier="tomee-remote" default="true">
+ <configuration>
+ <property name="classifier">plus</property> <!-- we need JMS -->
+ <property name="httpPort">-1</property>
+ <property name="ajpPort">-1</property>
+ <property name="stopPort">-1</property>
+ <property name="dir">target/apache-tomee-remote</property>
+ <property
name="appWorkingDir">target/arquillian-test-working-dir</property>
+ <property name="properties">
+ aResourceAdapter = new://Resource?type=ActiveMQResourceAdapter
+ aResourceAdapter.BrokerXmlConfig =
broker:(tcp://localhost:61616?daemon=true)?persistent=false&deleteAllMessagesOnStartup=true
+ aResourceAdapter.DataSource =
+
+ aConnectionFactory = new://Resource?type=javax.jms.ConnectionFactory
+ aConnectionFactory.ResourceAdapter = aResourceAdapter
+
+ aMdbContainer = new://Container?type=MESSAGE
+ aMdbContainer.ResourceAdapter = aResourceAdapter
+
+ aQueue = new://Resource?type=javax.jms.Queue
+ </property>
+ </configuration>
+ </container>
+</arquillian>
\ No newline at end of file
Modified: openejb/trunk/openejb/examples/pom.xml
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb/examples/pom.xml?rev=1375867&r1=1375866&r2=1375867&view=diff
==============================================================================
--- openejb/trunk/openejb/examples/pom.xml (original)
+++ openejb/trunk/openejb/examples/pom.xml Wed Aug 22 00:51:40 2012
@@ -49,6 +49,7 @@
<module>cdi-query</module>
<module>change-jaxws-url</module>
<module>component-interfaces</module>
+ <module>client-resource-lookup-preview</module>
<module>cucumber-jvm</module>
<module>custom-injection</module>
<module>datasource-ciphered-password</module>