servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r390987 - in /incubator/servicemix/trunk/servicemix-jms/src: main/java/org/apache/servicemix/jms/ test/java/org/apache/servicemix/jms/ test/resources/org/apache/servicemix/jms/
Date Mon, 03 Apr 2006 09:22:31 GMT
Author: gnodet
Date: Mon Apr  3 02:22:21 2006
New Revision: 390987

URL: http://svn.apache.org/viewcvs?rev=390987&view=rev
Log:
Allow configuring the connectionFactory and destination from spring on the jms endpoint .
Add spring example.

Added:
    incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java
    incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring.xml
Modified:
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
    incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingProviderProcessor.java

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java?rev=390987&r1=390986&r2=390987&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
Mon Apr  3 02:22:21 2006
@@ -37,14 +37,19 @@
     }
 
     public void start() throws Exception {
-        Hashtable props = new Hashtable();
-        if (endpoint.getInitialContextFactory() != null && endpoint.getJndiProviderURL()
!= null) {
-            props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getInitialContextFactory());
-            props.put(Context.PROVIDER_URL, endpoint.getJndiProviderURL());
-        }
-        InitialContext ctx = new InitialContext(props);
+        InitialContext ctx = null;
+        ConnectionFactory connectionFactory = null;
         try {
-            ConnectionFactory connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getJndiConnectionFactoryName());
+            connectionFactory = endpoint.getConnectionFactory();
+            if (connectionFactory == null) {
+                Hashtable props = new Hashtable();
+                if (endpoint.getInitialContextFactory() != null && endpoint.getJndiProviderURL()
!= null) {
+                    props.put(Context.INITIAL_CONTEXT_FACTORY, endpoint.getInitialContextFactory());
+                    props.put(Context.PROVIDER_URL, endpoint.getJndiProviderURL());
+                }
+                ctx = new InitialContext(props);
+                connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getJndiConnectionFactoryName());
+            }
             connection = connectionFactory.createConnection();
             connection.start();
             doStart(ctx);
@@ -56,7 +61,9 @@
             }
             throw e;
         } finally {
-            ctx.close();
+            if (ctx != null) {
+                ctx.close();
+            }
         }
     }
 

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java?rev=390987&r1=390986&r2=390987&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/JmsEndpoint.java
Mon Apr  3 02:22:21 2006
@@ -18,6 +18,8 @@
 import java.util.Iterator;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
 import javax.wsdl.Definition;
 import javax.wsdl.Port;
 import javax.wsdl.Service;
@@ -44,6 +46,9 @@
     protected String jndiConnectionFactoryName;
     protected String jndiDestinationName;
     protected String jmsProviderDestinationName;
+    // Spring configuration
+    protected ConnectionFactory connectionFactory;
+    protected Destination destination;
     
     public JmsEndpoint() {
     }
@@ -146,6 +151,34 @@
     }
 
     /**
+     * @return Returns the connectionFactory.
+     */
+    public ConnectionFactory getConnectionFactory() {
+        return connectionFactory;
+    }
+
+    /**
+     * @param connectionFactory The connectionFactory to set.
+     */
+    public void setConnectionFactory(ConnectionFactory connectionFactory) {
+        this.connectionFactory = connectionFactory;
+    }
+    
+    /**
+     * @return Returns the destination.
+     */
+    public Destination getDestination() {
+        return destination;
+    }
+
+    /**
+     * @param destination The destination to set.
+     */
+    public void setDestination(Destination destination) {
+        this.destination = destination;
+    }
+
+    /**
      * @org.apache.xbean.Property alias="role"
      * @param role
      */
@@ -216,4 +249,5 @@
                 "address: " + jndiDestinationName + "(" + destinationStyle + "), " + 
                 "soap: " + soap + "]";
     }
+
 }

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java?rev=390987&r1=390986&r2=390987&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingConsumerProcessor.java
Mon Apr  3 02:22:21 2006
@@ -73,16 +73,19 @@
 
     protected void doStart(InitialContext ctx) throws Exception {
         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        if (endpoint.getJndiDestinationName() != null) {
-            destination = (Destination) ctx.lookup(endpoint.getJndiDestinationName());
-        } else if (endpoint.getJmsProviderDestinationName() != null) {
-            if (STYLE_QUEUE.equals(endpoint.getDestinationStyle())) {
-                destination = session.createQueue(endpoint.getJmsProviderDestinationName());
+        destination = endpoint.getDestination();
+        if (destination == null) {
+            if (endpoint.getJndiDestinationName() != null) {
+                destination = (Destination) ctx.lookup(endpoint.getJndiDestinationName());
+            } else if (endpoint.getJmsProviderDestinationName() != null) {
+                if (STYLE_QUEUE.equals(endpoint.getDestinationStyle())) {
+                    destination = session.createQueue(endpoint.getJmsProviderDestinationName());
+                } else {
+                    destination = session.createTopic(endpoint.getJmsProviderDestinationName());
+                }
             } else {
-                destination = session.createTopic(endpoint.getJmsProviderDestinationName());
+                throw new IllegalStateException("No destination provided");
             }
-        } else {
-            throw new IllegalStateException("No destination provided");
         }
         consumer = session.createConsumer(destination);
         consumer.setMessageListener(this);

Modified: incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingProviderProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingProviderProcessor.java?rev=390987&r1=390986&r2=390987&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingProviderProcessor.java
(original)
+++ incubator/servicemix/trunk/servicemix-jms/src/main/java/org/apache/servicemix/jms/MultiplexingProviderProcessor.java
Mon Apr  3 02:22:21 2006
@@ -75,16 +75,19 @@
     protected void doStart(InitialContext ctx) throws Exception {
         channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel();
         session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
-        if (endpoint.getJndiDestinationName() != null) {
-            destination = (Destination) ctx.lookup(endpoint.getJndiDestinationName());
-        } else if (endpoint.getJmsProviderDestinationName() != null) {
-            if (STYLE_QUEUE.equals(endpoint.getDestinationStyle())) {
-                destination = session.createQueue(endpoint.getJmsProviderDestinationName());
+        destination = endpoint.getDestination();
+        if (destination == null) {
+            if (endpoint.getJndiDestinationName() != null) {
+                destination = (Destination) ctx.lookup(endpoint.getJndiDestinationName());
+            } else if (endpoint.getJmsProviderDestinationName() != null) {
+                if (STYLE_QUEUE.equals(endpoint.getDestinationStyle())) {
+                    destination = session.createQueue(endpoint.getJmsProviderDestinationName());
+                } else {
+                    destination = session.createTopic(endpoint.getJmsProviderDestinationName());
+                }
             } else {
-                destination = session.createTopic(endpoint.getJmsProviderDestinationName());
+                throw new IllegalStateException("No destination provided");
             }
-        } else {
-            throw new IllegalStateException("No destination provided");
         }
         if (destination instanceof Queue) {
             replyToDestination = session.createTemporaryQueue();

Added: incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java?rev=390987&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java
(added)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsSpringTest.java
Mon Apr  3 02:22:21 2006
@@ -0,0 +1,47 @@
+package org.apache.servicemix.jms;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.naming.Context;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.apache.xbean.spring.jndi.SpringInitialContextFactory;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class JmsSpringTest extends SpringTestSupport {
+
+    private static Log logger =  LogFactory.getLog(JmsSpringTest.class);
+
+    public void test() throws Exception {
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+        InOut me = client.createInOutExchange();
+        me.setService(new QName("http://test", "MyProviderService"));
+        me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
+        client.sendSync(me);
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getFault() != null) {
+                fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+            } else if (me.getError() != null) {
+                throw me.getError();
+            } else {
+                fail("Received ERROR status");
+            }
+        } else {
+            logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
+        }
+    }
+
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, SpringInitialContextFactory.class.getName());
+        System.setProperty(Context.PROVIDER_URL, "org/apache/servicemix/jms/jndi.xml");
+        return new ClassPathXmlApplicationContext("org/apache/servicemix/jms/spring.xml");
+    }
+
+}

Added: incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring.xml?rev=390987&view=auto
==============================================================================
--- incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring.xml
(added)
+++ incubator/servicemix/trunk/servicemix-jms/src/test/resources/org/apache/servicemix/jms/spring.xml
Mon Apr  3 02:22:21 2006
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0" 
+	   xmlns:jms="http://servicemix.apache.org/jms/1.0"
+	   xmlns:amq="http://activemq.org/config/1.0"
+	   xmlns:test="http://test">
+
+  <!-- the JBI container -->
+  <sm:container id="jbi" embedded="true" depends-on="jndi,broker">
+    <sm:activationSpecs>
+
+      <!-- START SNIPPET: lightweight -->
+      <sm:activationSpec>
+      	<sm:component>
+            <jms:component>
+            	<jms:endpoints>
+            		<jms:endpoint service="test:MyConsumerService"
+            					  endpoint="myConsumer"
+            		              role="consumer" 
+            		              defaultMep="http://www.w3.org/2004/08/wsdl/in-out"
+				                  destinationStyle="queue"
+				                  jmsProviderDestinationName="queue/A"
+				                  jndiConnectionFactoryName="jms/ConnectionFactory" />
+				                  
+            		<jms:endpoint service="test:MyProviderService"
+            					  endpoint="myProvider"
+            		              role="provider" 
+				                  destinationStyle="queue"
+				                  jmsProviderDestinationName="queue/A"
+				                  connectionFactory="#connectionFactory" />
+            	</jms:endpoints>
+            </jms:component>
+        </sm:component>
+      </sm:activationSpec>
+      <!-- END SNIPPET: lightweight -->
+      
+      <sm:activationSpec service="test:MyConsumerService" endpoint="myConsumer">
+        <sm:component>
+          <bean class="org.apache.servicemix.components.util.EchoComponent" />
+        </sm:component>
+      </sm:activationSpec>
+
+    </sm:activationSpecs>
+  </sm:container>
+  
+  <bean id="jndi" 
+        class="org.apache.xbean.spring.jndi.SpringInitialContextFactory" 
+        factory-method="makeInitialContext"
+        singleton="true">
+    <property name="entries">
+      <map>
+        <entry key="jms/ConnectionFactory" value-ref="connectionFactory" />
+      </map>
+    </property>
+  </bean>
+  
+  <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+    <property name="brokerURL" value="tcp://localhost:61216" />
+  </bean>
+  
+  <amq:broker id="broker" persistent="false" depends-on="jndi">
+
+    <amq:transportConnectors>
+      <amq:transportConnector uri="tcp://localhost:61216" />
+    </amq:transportConnectors>
+
+  </amq:broker>
+
+</beans>



Mime
View raw message