cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1037791 - in /cxf/trunk/rt/transports/jms/src: main/java/org/apache/cxf/transport/jms/JMSConfiguration.java main/java/org/apache/cxf/transport/jms/JMSDestination.java test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
Date Mon, 22 Nov 2010 17:36:26 GMT
Author: dkulp
Date: Mon Nov 22 17:36:25 2010
New Revision: 1037791

URL: http://svn.apache.org/viewvc?rev=1037791&view=rev
Log:
[CXF-3096] JMS shouldn't close pre-configured SingleCOnnectionFactories
Patch from Hartmut Lang applied

Added:
    cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
  (with props)
Modified:
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java?rev=1037791&r1=1037790&r2=1037791&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConfiguration.java
Mon Nov 22 17:36:25 2010
@@ -97,11 +97,11 @@ public class JMSConfiguration implements
     private String requestURI;
 
     private ConnectionFactory wrappedConnectionFactory;
-
+    private boolean autoWrappedConnectionFactory;
     private JNDIConfiguration jndiConfig;
 
     public void ensureProperlyConfigured(org.apache.cxf.common.i18n.Message msg) {
-        if (targetDestination == null ||  getOrCreateWrappedConnectionFactory() == null)
{
+        if (targetDestination == null || getOrCreateWrappedConnectionFactory() == null) {
             throw new ConfigurationException(msg);
         }
     }
@@ -138,7 +138,6 @@ public class JMSConfiguration implements
         this.autoResolveDestination = autoResolveDestination;
     }
 
-
     public boolean isUsingEndpointInfo() {
         return this.usingEndpointInfo;
     }
@@ -383,6 +382,7 @@ public class JMSConfiguration implements
         }
         return useConduitIdSelector;
     }
+
     public boolean isSetUseConduitIdSelector() {
         return useConduitIdSelector != null;
     }
@@ -440,6 +440,7 @@ public class JMSConfiguration implements
                     } else {
                         scf = new SingleConnectionFactory(connectionFactory);
                     }
+                    autoWrappedConnectionFactory = true;
                 } else {
                     @SuppressWarnings("deprecation")
                     SingleConnectionFactory scf2
@@ -458,17 +459,21 @@ public class JMSConfiguration implements
         }
         return wrappedConnectionFactory;
     }
+
     public ConnectionFactory getWrappedConnectionFactory() {
         return wrappedConnectionFactory;
     }
 
     public synchronized void destroyWrappedConnectionFactory() {
-        if (wrappedConnectionFactory instanceof SingleConnectionFactory) {
-            ((SingleConnectionFactory)wrappedConnectionFactory).destroy();
+        if (autoWrappedConnectionFactory
+            &&
+            wrappedConnectionFactory instanceof SingleConnectionFactory) {
+            ((SingleConnectionFactory) wrappedConnectionFactory).destroy();
             if (connectionFactory == wrappedConnectionFactory) {
                 connectionFactory = null;
             }
             wrappedConnectionFactory = null;
+            autoWrappedConnectionFactory = false;
         }
     }
 

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?rev=1037791&r1=1037790&r2=1037791&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
Mon Nov 22 17:36:25 2010
@@ -59,7 +59,6 @@ import org.apache.cxf.transport.jms.cont
 import org.apache.cxf.ws.addressing.EndpointReferenceType;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
 import org.springframework.jms.connection.JmsResourceHolder;
-import org.springframework.jms.connection.SingleConnectionFactory;
 import org.springframework.jms.core.JmsTemplate;
 import org.springframework.jms.core.MessageCreator;
 import org.springframework.jms.core.SessionCallback;
@@ -119,9 +118,7 @@ public class JMSDestination extends Abst
             // CXF-2788: SingleConnectionFactory ignores the call to
             // javax.jms.Connection#close(),
             // use this to really close the target connection.
-            if (jmsListener.getConnectionFactory() instanceof SingleConnectionFactory) {
-                ((SingleConnectionFactory)jmsListener.getConnectionFactory()).destroy();
-            }
+            jmsConfig.destroyWrappedConnectionFactory();
         }
     }
 

Added: cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java?rev=1037791&view=auto
==============================================================================
--- cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
(added)
+++ cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
Mon Nov 22 17:36:25 2010
@@ -0,0 +1,83 @@
+/**
+ * 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.transport.jms;
+
+import javax.jms.ConnectionFactory;
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.jms.connection.SingleConnectionFactory;
+
+public class JMSConfigurationTest extends Assert {
+
+    @Test
+    public void testDestroyAutoWrappedConnectionFactory() {
+        // create an empty configuration
+        JMSConfiguration jmsConfig = new JMSConfiguration();
+        // create the connectionFactory to wrap
+        ActiveMQConnectionFactory amqCf = new ActiveMQConnectionFactory();
+        jmsConfig.setConnectionFactory(amqCf);
+        // get the connectionFactory
+        assertTrue("Should get the instance of ActiveMQConnectionFactory",
+                   jmsConfig.getConnectionFactory() instanceof ActiveMQConnectionFactory);
+        // get the wrapped connectionFactory
+        ConnectionFactory wrappingCf = jmsConfig.getOrCreateWrappedConnectionFactory();
+        assertTrue("Should get the instance of SingleConnectionFactory",
+                   wrappingCf instanceof SingleConnectionFactory);
+        SingleConnectionFactory scf = (SingleConnectionFactory)wrappingCf;
+        assertSame("Should get the wrapped ActiveMQConnectionFactory",
+                    amqCf, scf.getTargetConnectionFactory());
+        // destroy the wrapping
+        jmsConfig.destroyWrappedConnectionFactory();
+        // get the wrapping cf
+        assertNull("Should be null after destroy", jmsConfig.getWrappedConnectionFactory());
+        // original connectionFactory should be unchanged
+        assertSame("Should be the same with original connectionFactory",
+                    amqCf, jmsConfig.getConnectionFactory());
+    }
+
+    @Test
+    public void testDestroySuppliedConnectionFactory() {
+        // create an empty configuration
+        JMSConfiguration jmsConfig = new JMSConfiguration();
+        // create the connectionFactory to wrap
+        ActiveMQConnectionFactory amqCf = new ActiveMQConnectionFactory();
+        // wrap into SingleConnectionFactory
+        SingleConnectionFactory scf = new SingleConnectionFactory(amqCf);
+        // set the connectionFactory to reuse
+        jmsConfig.setConnectionFactory(scf);
+        // get the connectionFactory
+        assertTrue("Should get the instance of SingleConnectionFactory",
+                   jmsConfig.getConnectionFactory() instanceof SingleConnectionFactory);
+        // get the wrapped connectionFactory
+        ConnectionFactory wrappingCf = jmsConfig.getOrCreateWrappedConnectionFactory();
+        assertTrue("Should get the instance of SingleConnectionFactory",
+                   wrappingCf instanceof SingleConnectionFactory);
+        assertSame("Should not be wrapped again",
+                    scf, wrappingCf);
+        // destroy the wrapping
+        jmsConfig.destroyWrappedConnectionFactory();
+        // get the wrapping cf
+        assertNotNull("Should be not null after destroy", jmsConfig.getWrappedConnectionFactory());
+        // original connectionFactory should be unchanged
+        assertSame("Should be the same with supplied connectionFactory",
+                    scf, jmsConfig.getConnectionFactory());
+    }
+}

Propchange: cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConfigurationTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message