cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jp...@apache.org
Subject cxf git commit: CXF-6136 add support for disabling all exception propogation when tranactions are enabled
Date Fri, 05 Dec 2014 23:24:47 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 0b8a12c3c -> 6b5acabe8


CXF-6136 add support for disabling all exception propogation when tranactions are enabled


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/6b5acabe
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/6b5acabe
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/6b5acabe

Branch: refs/heads/2.7.x-fixes
Commit: 6b5acabe808d32d99a52a35f6a987ef547053af9
Parents: 0b8a12c
Author: Jason Pell <jpell@apache.org>
Authored: Sat Dec 6 04:58:51 2014 +1100
Committer: Jason Pell <jpell@apache.org>
Committed: Sat Dec 6 10:12:04 2014 +1100

----------------------------------------------------------------------
 .../cxf/transport/jms/JMSConfiguration.java     | 13 +++++
 .../cxf/transport/jms/JMSDestination.java       |  3 +-
 .../jms/tx/JMSTransactionClientServerTest.java  | 61 ++++++++++++++++----
 3 files changed, 64 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/6b5acabe/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
index dcfc329..f84f3e8 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
@@ -68,6 +68,7 @@ public class JMSConfiguration implements InitializingBean {
     private int priority = Message.DEFAULT_PRIORITY;
     private long timeToLive = Message.DEFAULT_TIME_TO_LIVE;
     private boolean sessionTransacted;
+    private boolean propogateExceptions = true;
 
     private int concurrentConsumers = 1;
     private int maxConcurrentConsumers = 1;
@@ -117,6 +118,18 @@ public class JMSConfiguration implements InitializingBean {
         }
     }
 
+    /**
+     * if any exceptions encountered executing the service impl should be propagated
+     * to initiate a transaction roll back.
+     */
+    public boolean isPropogateExceptions() {
+        return propogateExceptions;
+    }
+
+    public void setPropogateExceptions(boolean propogateExceptions) {
+        this.propogateExceptions = propogateExceptions;
+    }
+    
     public boolean isCreateSecurityContext() {
         return createSecurityContext;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/6b5acabe/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
----------------------------------------------------------------------
diff --git a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
index 1a81687..c641fcc 100644
--- a/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
+++ b/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
@@ -248,7 +248,8 @@ public class JMSDestination extends AbstractMultiplexDestination
             }
             //need to propagate any exceptions back to Spring container 
             //so transactions can occur
-            if (inMessage.getContent(Exception.class) != null && session != null)
{
+            if (inMessage.getContent(Exception.class) != null && session != null
+                    && jmsConfig.isPropogateExceptions()) {
                 PlatformTransactionManager m = jmsConfig.getTransactionManager();
                 if (m != null) {
                     TransactionStatus status = m.getTransaction(null);

http://git-wip-us.apache.org/repos/asf/cxf/blob/6b5acabe/systests/transport-jms/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
----------------------------------------------------------------------
diff --git a/systests/transport-jms/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
b/systests/transport-jms/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
index 714e250..466d644 100644
--- a/systests/transport-jms/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
+++ b/systests/transport-jms/src/test/java/org/apache/cxf/systest/jms/tx/JMSTransactionClientServerTest.java
@@ -46,21 +46,28 @@ public class JMSTransactionClientServerTest extends AbstractBusClientServerTestB
     static EmbeddedJMSBrokerLauncher broker;
 
     public static 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();
             
+            ConnectionFactory connectionFactory
+                = context.getBean("jmsConnectionFactory", ConnectionFactory.class);
+            
+            publishEndpoint(connectionFactory, "greeter.queue.noaop", true);
+            publishEndpoint(connectionFactory, "greeter.queue.noaop2", false);
+        }
+
+        private void publishEndpoint(ConnectionFactory connectionFactory, String queueName,

+                boolean propogateExceptions) {
             EndpointImpl endpoint = new EndpointImpl(new GreeterImplWithTransaction());
             endpoint.setAddress("jms://");
             JMSConfiguration jmsConfig = new JMSConfiguration();
     
-            ConnectionFactory connectionFactory
-                = context.getBean("jmsConnectionFactory", ConnectionFactory.class);
+            jmsConfig.setPropogateExceptions(propogateExceptions);
             jmsConfig.setConnectionFactory(connectionFactory);
-            jmsConfig.setTargetDestination("greeter.queue.noaop");
+            jmsConfig.setTargetDestination(queueName);
             jmsConfig.setSessionTransacted(true);
             jmsConfig.setPubSubDomain(false);
             jmsConfig.setUseJms11(true);
@@ -111,8 +118,40 @@ public class JMSTransactionClientServerTest extends AbstractBusClientServerTestB
         Greeter greeter = service.getPort(portName, Greeter.class);
         doService(greeter, true);
     }
+    
     @Test
     public void testNonAopTransaction() throws Exception {
+        Greeter greeter = getServiceClient("greeter.queue.noaop");
+        doService(greeter, false);
+    }
+    
+    @Test
+    public void testNonAopTransactionNoPropogation() throws Exception {
+        Greeter greeter = getServiceClient("greeter.queue.noaop2");
+        
+        String response1 = new String("Hello ");
+        
+        String greeting = greeter.greetMe("Good guy");
+        assertNotNull("No response received from service", greeting);
+        String exResponse = response1 + "Good guy";
+        assertEquals("Get unexpected result", exResponse, greeting);
+
+        try {
+            greeter.greetMe("Bad guy");
+            fail("Should have thrown Exception");
+        } catch (Exception e) {
+            assertTrue(e.getMessage().contains("Got a bad guy call for greetMe"));
+        }
+        
+        try {
+            greeter.pingMe();
+            fail("Should have thrown FaultException");
+        } catch (PingMeFault ex) {
+            assertNotNull(ex.getFaultInfo());
+        }
+    }
+    
+    private Greeter getServiceClient(String queueName) {
         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
         factory.setServiceClass(Greeter.class);
         factory.setAddress("jms://");
@@ -121,7 +160,7 @@ public class JMSTransactionClientServerTest extends AbstractBusClientServerTestB
         ConnectionFactory connectionFactory
             = new PooledConnectionFactory(broker.getBrokerURL());
         jmsConfig.setConnectionFactory(connectionFactory);
-        jmsConfig.setTargetDestination("greeter.queue.noaop");
+        jmsConfig.setTargetDestination(queueName);
         jmsConfig.setPubSubDomain(false);
         jmsConfig.setUseJms11(true);
 
@@ -129,11 +168,10 @@ public class JMSTransactionClientServerTest extends AbstractBusClientServerTestB
         jmsConfigFeature.setJmsConfig(jmsConfig);
         factory.getFeatures().add(jmsConfigFeature);
 
-        Greeter greeter = (Greeter)factory.create();
-        doService(greeter, false);
-    }    
+        return (Greeter)factory.create();
+    }
+    
     public void doService(Greeter greeter, boolean doEx) throws Exception {
-
         String response1 = new String("Hello ");
         
         try {
@@ -141,12 +179,12 @@ public class JMSTransactionClientServerTest extends AbstractBusClientServerTestB
             String greeting = greeter.greetMe("Good guy");
             assertNotNull("No response received from service", greeting);
             String exResponse = response1 + "Good guy";
-            assertEquals("Get unexcpeted result", exResponse, greeting);
+            assertEquals("Get unexpected 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);
+            assertEquals("Get unexpected result", exResponse, greeting);
             
             if (doEx) {
                 try {
@@ -160,5 +198,4 @@ public class JMSTransactionClientServerTest extends AbstractBusClientServerTestB
             throw (Exception)ex.getCause();
         }
     }
-
 }


Mime
View raw message