You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2008/12/15 08:50:19 UTC

svn commit: r726639 - in /cxf/trunk: rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/ systests/src/test/java/org/apache/cxf/systest/jms/tx/

Author: ningjiang
Date: Sun Dec 14 23:50:18 2008
New Revision: 726639

URL: http://svn.apache.org/viewvc?rev=726639&view=rev
Log:
CXF-180 added an example to show how to use spring transaction framework with jms transport

Added:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml   (with props)
Modified:
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java?rev=726639&r1=726638&r2=726639&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java (original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java Sun Dec 14 23:50:18 2008
@@ -33,7 +33,6 @@
 import org.springframework.jms.connection.SingleConnectionFactory;
 import org.springframework.jms.connection.SingleConnectionFactory102;
 import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;
-import org.springframework.jms.core.JmsTemplate;
 import org.springframework.jms.support.destination.JndiDestinationResolver;
 import org.springframework.jndi.JndiTemplate;
 
@@ -120,8 +119,11 @@
             if (address.isSetDestinationStyle()) {
                 pubSubDomain = DestinationStyleType.TOPIC == address.getDestinationStyle();
             }
-            ConnectionFactory cf = getConnectionFactoryFromJndi(jt, pubSubDomain);            
-            jmsConfig.setConnectionFactory(cf);
+            
+            if (jmsConfig.getConnectionFactory() == null) {
+                ConnectionFactory cf = getConnectionFactoryFromJndi(jt, pubSubDomain);
+                jmsConfig.setConnectionFactory(cf);
+            }
         
             jmsConfig.setDurableSubscriptionName(serverBehavior.getDurableSubscriberName());
             jmsConfig.setExplicitQosEnabled(true);        
@@ -131,22 +133,24 @@
             }        
             jmsConfig.setPubSubDomain(pubSubDomain);
             jmsConfig.setPubSubNoLocal(true);
-            if (jmsConfig.getReceiveTimeout() == JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT) {
-                jmsConfig.setReceiveTimeout(clientConfig.getClientReceiveTimeout());
-            }            
+            //if (clientConfig.isSetClientReceiveTimeout()) {
+            jmsConfig.setReceiveTimeout(clientConfig.getClientReceiveTimeout());
+            //}            
             jmsConfig.setSubscriptionDurable(serverBehavior.isSetDurableSubscriberName());       
             jmsConfig.setDurableSubscriptionName(serverBehavior.getDurableSubscriberName());        
         
             long timeToLive = isConduit ? clientConfig.getMessageTimeToLive() : serverConfig
                 .getMessageTimeToLive();
-            jmsConfig.setTimeToLive(timeToLive);
+            jmsConfig.setTimeToLive(timeToLive);            
             if (address.isSetUseJms11()) {                
                 jmsConfig.setUseJms11(address.isUseJms11());        
             }
             boolean useJndi = address.isSetJndiDestinationName();
             jmsConfig.setUseJndi(useJndi);
         
-            jmsConfig.setSessionTransacted(serverBehavior.isSetTransactional());
+            if (serverBehavior.isSetTransactional()) {
+                jmsConfig.setSessionTransacted(serverBehavior.isTransactional());                
+            }            
 
             if (useJndi) {
                 // Setup Destination jndi destination resolver

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java?rev=726639&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java Sun Dec 14 23:50:18 2008
@@ -0,0 +1,43 @@
+/**
+ * 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.apache.cxf.systest.jms.tx;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+
+import org.apache.cxf.systest.jms.GreeterImplDocBase;
+
+public class GreeterImplWithTransaction extends GreeterImplDocBase {
+    private AtomicBoolean flag = new AtomicBoolean(true);
+       
+    public String greetMe(String requestType) {
+        System.out.println("Reached here :" + requestType);
+        if ("Bad guy".equals(requestType)) {
+            if (flag.getAndSet(false)) {
+                System.out.println("Throw exception here :" + requestType);
+                throw new RuntimeException("Got a bad guy call for greetMe");
+            } else {
+                requestType = "[Bad guy]";
+                flag.set(true);
+            }
+        }
+        return "Hello " + requestType;
+    }
+    
+}

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/GreeterImplWithTransaction.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java?rev=726639&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java Sun Dec 14 23:50:18 2008
@@ -0,0 +1,99 @@
+/**
+ * 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.apache.cxf.systest.jms.tx;
+
+import java.lang.reflect.UndeclaredThrowableException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.systest.jms.EmbeddedJMSBrokerLauncher;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.hello_world_doc_lit.Greeter;
+import org.apache.hello_world_doc_lit.SOAPService2;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JMSTransactionClientServerTest extends AbstractBusClientServerTestBase {
+    
+    protected static boolean serversStarted;
+
+    @Before
+    public void startServers() throws Exception {
+        if (serversStarted) {
+            return;
+        }
+        Map<String, String> props = new HashMap<String, String>();                
+        if (System.getProperty("activemq.store.dir") != null) {
+            props.put("activemq.store.dir", System.getProperty("activemq.store.dir"));
+        }
+        props.put("java.util.logging.config.file", 
+                  System.getProperty("java.util.logging.config.file"));
+        
+        assertTrue("server did not launch correctly", 
+                   launchServer(EmbeddedJMSBrokerLauncher.class, props, null));
+
+        assertTrue("server did not launch correctly", 
+                   launchServer(Server.class, false));
+        serversStarted = true;
+    }
+    
+    public URL getWSDLURL(String s) throws Exception {
+        return getClass().getResource(s);
+    }
+    public QName getServiceName(QName q) {
+        return q;
+    }
+    public QName getPortName(QName q) {
+        return q;
+    }
+    
+    @Test
+    public void testDocBasicConnection() throws Exception {
+        QName serviceName = getServiceName(new QName("http://apache.org/hello_world_doc_lit", 
+                                 "SOAPService2"));
+        QName portName = getPortName(new QName("http://apache.org/hello_world_doc_lit", "SoapPort2"));
+        URL wsdl = getWSDLURL("/wsdl/hello_world_doc_lit.wsdl");
+        assertNotNull(wsdl);
+
+        SOAPService2 service = new SOAPService2(wsdl, serviceName);
+        assertNotNull(service);
+
+        String response1 = new String("Hello ");
+        
+        try {
+            Greeter greeter = service.getPort(portName, Greeter.class);
+                          
+            String greeting = greeter.greetMe("Good guy");
+            assertNotNull("No response received from service", greeting);
+            String exResponse = response1 + "Good guy";
+            assertEquals("Get unexcpeted result", exResponse, greeting);
+
+            greeting = greeter.greetMe("Bad guy");
+            assertNotNull("No response received from service", greeting);
+            exResponse = response1 + "[Bad guy]";
+            assertEquals("Get unexcpeted result", exResponse, greeting);
+        } catch (UndeclaredThrowableException ex) {
+            throw (Exception)ex.getCause();
+        }
+    }
+
+}

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java?rev=726639&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java Sun Dec 14 23:50:18 2008
@@ -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.apache.cxf.systest.jms.tx;
+
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class Server extends AbstractBusTestServerBase {
+
+
+    protected void run()  {
+        // create the application context
+        ClassPathXmlApplicationContext context = 
+            new ClassPathXmlApplicationContext("org/apache/cxf/systest/jms/tx/jms_server_config.xml");
+        context.start();
+    }
+
+
+    public static void main(String[] args) {
+        try {
+            Server s = new Server();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/Server.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml?rev=726639&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml Sun Dec 14 23:50:18 2008
@@ -0,0 +1,81 @@
+<?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.
+-->
+
+<beans 
+    xmlns="http://www.springframework.org/schema/beans"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:ct="http://cxf.apache.org/configuration/types"
+    xmlns:jms="http://cxf.apache.org/transports/jms"
+    xmlns:p="http://www.springframework.org/schema/p"
+    xmlns:jaxws="http://cxf.apache.org/jaxws"    
+    xsi:schemaLocation="
+http://cxf.apache.org/transports/jms http://cxf.apache.org/schemas/configuration/jms.xsd
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
+    
+ <import resource="classpath:META-INF/cxf/cxf.xml" />
+ <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" /> 
+ <import resource="classpath:META-INF/cxf/cxf-extension-jms.xml" />
+ 
+ <jaxws:endpoint implementor="#transactionalImplementor" 
+ 	implementorClass="org.apache.hello_world_doc_lit.Greeter"
+ 	wsdlLocation="testutils/hello_world_doc_lit.wsdl"
+ 	serviceName="s:SOAPService2" 
+    endpointName="s:SoapPort2"
+    xmlns:s= "http://apache.org/hello_world_doc_lit" />
+    
+    <jms:destination name="{http://apache.org/hello_world_doc_lit}SoapPort2.jms-destination">      
+      <jms:jmsConfig-ref>jmsConf</jms:jmsConfig-ref>
+    </jms:destination>
+    
+  
+  <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"
+  	p:brokerURL="tcp://localhost:61500"
+  />
+  
+  <bean id="singleConnectionFactory"
+    class="org.springframework.jms.connection.SingleConnectionFactory" destroy-method="destroy">
+    <property name="targetConnectionFactory" ref="jmsConnectionFactory"/>
+  </bean>
+  
+  <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
+     <property name="connectionFactory" ref="singleConnectionFactory"/>
+  </bean>
+  
+  <bean id="implementor" class="org.apache.cxf.systest.jms.tx.GreeterImplWithTransaction"/>
+  
+  <bean id="transactionalImplementor"
+     class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
+  	<property name="transactionManager" ref="jmsTransactionManager" />
+  	<property name="target" ref="implementor" />
+  	<property name="transactionAttributes">
+  	  <props>
+  	  	<prop key="greetMe">PROPAGATION_REQUIRED</prop>  	  	
+  	  </props>
+    </property>
+  </bean>  
+  
+  <bean id="jmsConf" class="org.apache.cxf.transport.jms.JMSConfiguration"
+  	p:connectionFactory-ref="singleConnectionFactory"
+  	p:sessionTransacted="true"
+  	p:transactionManager-ref="jmsTransactionManager"  	
+  	p:usingEndpointInfo="true"/>
+
+</beans>

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jms/tx/jms_server_config.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml