cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r739799 - in /cxf/trunk/rt/transports/jms/src: main/java/org/apache/cxf/transport/jms/ test/java/org/apache/cxf/transport/jms/
Date Sun, 01 Feb 2009 17:54:15 GMT
Author: cschneider
Date: Sun Feb  1 17:54:15 2009
New Revision: 739799

URL: http://svn.apache.org/viewvc?rev=739799&view=rev
Log:
CXF-2018 Wrap connectionfactory into a SingleConnectionFactory by default. Added a config
element to make this configurable. Moved jndi config stuff to own class so it is more transparent
that this should normally not be set when using the new style config.

Added:
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JNDIConfiguration.java
  (with props)
Modified:
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
    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
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
    cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSOldConfigHolder.java
    cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java?rev=739799&r1=739798&r2=739799&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSConduit.java
Sun Feb  1 17:54:15 2009
@@ -35,7 +35,6 @@
 import javax.jms.Session;
 
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.ConfigurationException;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -83,11 +82,10 @@
      * JMSOutputStream will then call back the sendExchange method of this class. {@inheritDoc}
      */
     public void prepare(Message message) throws IOException {
-        if (jmsConfig.getTargetDestination() == null || jmsConfig.getConnectionFactory()
== null) {
-            String name =  endpointInfo.getName().toString() + ".jms-conduit";
-            throw new ConfigurationException(
-                new org.apache.cxf.common.i18n.Message("INSUFFICIENT_CONFIGURATION_CONDUIT",
LOG, name));
-        }
+        String name =  endpointInfo.getName().toString() + ".jms-conduit";
+        org.apache.cxf.common.i18n.Message msg = 
+            new org.apache.cxf.common.i18n.Message("INSUFFICIENT_CONFIGURATION_CONDUIT",
LOG, name);
+        jmsConfig.ensureProperlyConfigured(msg);
         boolean isTextPayload = JMSConstants.TEXT_MESSAGE_TYPE.equals(jmsConfig.getMessageType());
         JMSOutputStream out = new JMSOutputStream(this, message.getExchange(), isTextPayload);
         message.setContent(OutputStream.class, out);

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=739799&r1=739798&r2=739799&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
Sun Feb  1 17:54:15 2009
@@ -20,14 +20,13 @@
 
 import javax.jms.ConnectionFactory;
 import javax.jms.Message;
-import javax.naming.NamingException;
 
+import org.apache.cxf.configuration.ConfigurationException;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Required;
 import org.springframework.core.task.TaskExecutor;
 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.DestinationResolver;
 import org.springframework.jndi.JndiTemplate;
@@ -43,11 +42,19 @@
     static final boolean DEFAULT_USEJMS11 = true;
     
     private boolean usingEndpointInfo = true;
+    
+    /**
+     * Use jndi to resolve destinations
+     */
+    private boolean useJndi;
+    private JndiTemplate jndiTemplate;
     private ConnectionFactory connectionFactory;
     private DestinationResolver destinationResolver;
     private PlatformTransactionManager transactionManager;
+    private boolean wrapInSingleConnectionFactory = true;
     private TaskExecutor taskExecutor;
     private boolean useJms11 = DEFAULT_USEJMS11;
+    private boolean reconnectOnException;
     private boolean messageIdEnabled = true;
     private boolean messageTimestampEnabled = true;
     private boolean pubSubNoLocal;
@@ -57,15 +64,6 @@
     private int priority = Message.DEFAULT_PRIORITY;
     private long timeToLive = Message.DEFAULT_TIME_TO_LIVE;
     private boolean sessionTransacted;
-
-    //Stuff for JNDI based and old configs
-    private boolean useJndi;
-    private JndiTemplate jndiTemplate;
-    private String jndiConnectionFactoryName;
-    private String connectionUserName;
-    private String connectionPassword;
-    private Boolean reconnectOnException;
-    
     
     private int concurrentConsumers = 1;
     private int maxConcurrentConsumers = 1;
@@ -85,6 +83,16 @@
     private int cacheLevel = DEFAULT_VALUE;
     private String cacheLevelName;
     
+    private ConnectionFactory wrappedConnectionFactory;
+    
+    private JNDIConfiguration jndiConfig;
+    
+    public void ensureProperlyConfigured(org.apache.cxf.common.i18n.Message msg) {
+        if (targetDestination == null || getOrCreateWrappedConnectionFactory() == null) {
+            throw new ConfigurationException(msg);
+        }
+    }
+    
     public String getCacheLevelName() {
         return cacheLevelName;
     }
@@ -227,47 +235,6 @@
         }
     }
 
-    
-    public ConnectionFactory getConnectionFactory() {
-        if (connectionFactory == null && jndiTemplate != null  && jndiConnectionFactoryName
!= null) {
-            connectionFactory = getConnectionFactoryFromJndi();
-        }
-        return connectionFactory;
-    }
-    private ConnectionFactory getConnectionFactoryFromJndi() {
-        
-        String connectionFactoryName = getJndiConnectionFactoryName();
-        String userName = getConnectionUserName();
-        String password = getConnectionPassword();
-            
-            
-        if (connectionFactoryName == null) {
-            return null;
-        }
-        try {
-            ConnectionFactory cf = (ConnectionFactory)jndiTemplate.lookup(connectionFactoryName);
-            UserCredentialsConnectionFactoryAdapter uccf = new UserCredentialsConnectionFactoryAdapter();
-            uccf.setUsername(userName);
-            uccf.setPassword(password);
-            uccf.setTargetConnectionFactory(cf);
-
-            if (this.useJms11) {
-                SingleConnectionFactory scf = new SingleConnectionFactory(uccf);
-                if (isSetReconnectOnException() && isReconnectOnException()) {
-                    scf.setReconnectOnException(true);
-                }
-                return scf;
-            }
-            SingleConnectionFactory102 scf = new SingleConnectionFactory102(uccf, pubSubDomain);
-            if (isSetReconnectOnException() && isReconnectOnException()) {
-                scf.setReconnectOnException(true);
-            }
-            return scf;
-        } catch (NamingException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
     @Required
     public void setConnectionFactory(ConnectionFactory connectionFactory) {
         this.connectionFactory = connectionFactory;
@@ -385,39 +352,58 @@
         return jndiTemplate;
     }
 
-    public String getJndiConnectionFactoryName() {
-        return jndiConnectionFactoryName;
+    public JNDIConfiguration getJndiConfig() {
+        return jndiConfig;
     }
 
-    public void setJndiConnectionFactoryName(String jndiConnectionFactoryName) {
-        this.jndiConnectionFactoryName = jndiConnectionFactoryName;
+    public void setJndiConfig(JNDIConfiguration jndiConfig) {
+        this.jndiConfig = jndiConfig;
     }
 
-    public String getConnectionUserName() {
-        return connectionUserName;
+    public boolean isReconnectOnException() {
+        return reconnectOnException;
     }
 
-    public void setConnectionUserName(String connectionUserName) {
-        this.connectionUserName = connectionUserName;
+    public void setReconnectOnException(boolean reconnectOnException) {
+        this.reconnectOnException = reconnectOnException;
     }
 
-    public String getConnectionPassword() {
-        return connectionPassword;
+    public ConnectionFactory getOrCreateWrappedConnectionFactory() {
+        if (wrappedConnectionFactory == null) {
+            if (connectionFactory == null) {
+                connectionFactory = JMSFactory.getConnectionFactoryFromJndi(this);
+            }
+            if (wrapInSingleConnectionFactory) {
+                if (useJms11) {
+                    wrappedConnectionFactory = new SingleConnectionFactory(connectionFactory);
+                } else {
+                    wrappedConnectionFactory = new SingleConnectionFactory102(connectionFactory,

+                                                                              pubSubDomain);
+                }
+                if (reconnectOnException) {
+                    ((SingleConnectionFactory)wrappedConnectionFactory).setReconnectOnException(true);
+                }
+            } else {
+                wrappedConnectionFactory = connectionFactory;
+            }
+        }
+        return wrappedConnectionFactory;
     }
 
-    public void setConnectionPassword(String connectionPassword) {
-        this.connectionPassword = connectionPassword;
+    /**
+     * Only for tests
+     * @return
+     */
+    protected ConnectionFactory getConnectionFactory() {
+        return connectionFactory;
     }
 
-    public boolean isSetReconnectOnException() {
-        return reconnectOnException != null;
-    }
-    public boolean isReconnectOnException() {
-        return reconnectOnException;
+    public boolean isWrapInSingleConnectionFactory() {
+        return wrapInSingleConnectionFactory;
     }
 
-    public void setReconnectOnException(boolean reconnectOnException) {
-        this.reconnectOnException = reconnectOnException;
+    public void setWrapInSingleConnectionFactory(boolean wrapInSingleConnectionFactory) {
+        this.wrapInSingleConnectionFactory = wrapInSingleConnectionFactory;
     }
 
 }

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=739799&r1=739798&r2=739799&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
Sun Feb  1 17:54:15 2009
@@ -45,7 +45,6 @@
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.configuration.ConfigurationException;
 import org.apache.cxf.continuations.ContinuationProvider;
 import org.apache.cxf.continuations.SuspendedInvocationException;
 import org.apache.cxf.helpers.CastUtils;
@@ -100,10 +99,9 @@
     public void activate() {
         getLogger().log(Level.INFO, "JMSDestination activate().... ");
         String name = endpointInfo.getName().toString() + ".jms-destination";
-        if (jmsConfig.getTargetDestination() == null || jmsConfig.getConnectionFactory()
== null) {
-            throw new ConfigurationException(
-                new org.apache.cxf.common.i18n.Message("INSUFFICIENT_CONFIGURATION_DESTINATION",
LOG, name));
-        }
+        org.apache.cxf.common.i18n.Message msg = 
+            new org.apache.cxf.common.i18n.Message("INSUFFICIENT_CONFIGURATION_DESTINATION",
LOG, name);
+        jmsConfig.ensureProperlyConfigured(msg);
         jmsListener = JMSFactory.createJmsListener(jmsConfig, this, jmsConfig.getTargetDestination(),
null);
     }
 

Modified: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java?rev=739799&r1=739798&r2=739799&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
(original)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSFactory.java
Sun Feb  1 17:54:15 2009
@@ -18,13 +18,16 @@
  */
 package org.apache.cxf.transport.jms;
 
+import javax.jms.ConnectionFactory;
 import javax.jms.Destination;
 import javax.jms.JMSException;
 import javax.jms.MessageListener;
 import javax.jms.QueueSession;
 import javax.jms.Session;
+import javax.naming.NamingException;
 
 import org.springframework.core.task.SimpleAsyncTaskExecutor;
+import org.springframework.jms.connection.UserCredentialsConnectionFactoryAdapter;
 import org.springframework.jms.core.JmsTemplate;
 import org.springframework.jms.core.JmsTemplate102;
 import org.springframework.jms.core.SessionCallback;
@@ -36,11 +39,44 @@
  * Factory to create JmsTemplates and JmsListeners from configuration and context information
  */
 public final class JMSFactory {
-    
+
     private JMSFactory() {
     }
 
     /**
+     * Retreive connection factory from jndi, wrap it in a UserCredentialsConnectionFactoryAdapter,
+     * set username and password and return the ConnectionFactory
+     * 
+     * @param jmsConfig
+     * @param jndiConfig
+     * @return
+     */
+    static ConnectionFactory getConnectionFactoryFromJndi(JMSConfiguration jmsConfig) {
+        JNDIConfiguration jndiConfig = jmsConfig.getJndiConfig();
+        if (jndiConfig == null) {
+            return null;
+        }
+        String connectionFactoryName = jndiConfig.getJndiConnectionFactoryName();
+        if (connectionFactoryName == null) {
+            return null;
+        }
+        String userName = jndiConfig.getConnectionUserName();
+        String password = jndiConfig.getConnectionPassword();
+        try {
+            ConnectionFactory cf = (ConnectionFactory)jmsConfig.getJndiTemplate().
+                lookup(connectionFactoryName);
+            UserCredentialsConnectionFactoryAdapter uccf = new UserCredentialsConnectionFactoryAdapter();
+            uccf.setUsername(userName);
+            uccf.setPassword(password);
+            uccf.setTargetConnectionFactory(cf);
+            
+            return uccf;
+        } catch (NamingException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    /**
      * Create JmsTemplate from configuration information. Most settings are taken from jmsConfig.
The QoS
      * settings in headers override the settings from jmsConfig
      * 
@@ -50,7 +86,7 @@
      */
     public static JmsTemplate createJmsTemplate(JMSConfiguration jmsConfig, JMSMessageHeadersType
headers) {
         JmsTemplate jmsTemplate = jmsConfig.isUseJms11() ? new JmsTemplate() : new JmsTemplate102();
-        jmsTemplate.setConnectionFactory(jmsConfig.getConnectionFactory());
+        jmsTemplate.setConnectionFactory(jmsConfig.getOrCreateWrappedConnectionFactory());
         jmsTemplate.setPubSubDomain(jmsConfig.isPubSubDomain());
         jmsTemplate.setReceiveTimeout(jmsConfig.getReceiveTimeout());
         jmsTemplate.setTimeToLive(jmsConfig.getTimeToLive());
@@ -88,7 +124,7 @@
         jmsListener.setMaxConcurrentConsumers(jmsConfig.getMaxConcurrentConsumers());
         jmsListener.setPubSubDomain(jmsConfig.isPubSubDomain());
         jmsListener.setAutoStartup(true);
-        jmsListener.setConnectionFactory(jmsConfig.getConnectionFactory());
+        jmsListener.setConnectionFactory(jmsConfig.getOrCreateWrappedConnectionFactory());
         jmsListener.setMessageSelector(jmsConfig.getMessageSelector());
         jmsListener.setDurableSubscriptionName(jmsConfig.getDurableSubscriptionName());
         jmsListener.setSessionTransacted(jmsConfig.isSessionTransacted());

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=739799&r1=739798&r2=739799&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 Feb  1 17:54:15 2009
@@ -76,14 +76,14 @@
             if (address.isSetDestinationStyle()) {
                 pubSubDomain = DestinationStyleType.TOPIC == address.getDestinationStyle();
             }
-            if (jmsConfig.getConnectionFactory() == null) {
-                jmsConfig.setJndiConnectionFactoryName(address.getJndiConnectionFactoryName());
-                jmsConfig.setJndiTemplate(jt);
-                jmsConfig.setConnectionUserName(address.getConnectionUserName());
-                jmsConfig.setConnectionPassword(address.getConnectionPassword());
-                if (address.isSetReconnectOnException()) {
-                    jmsConfig.setReconnectOnException(address.isReconnectOnException());
-                }
+            JNDIConfiguration jndiConfig = new JNDIConfiguration();
+            jndiConfig.setJndiConnectionFactoryName(address.getJndiConnectionFactoryName());
+            jmsConfig.setJndiTemplate(jt);
+            jndiConfig.setConnectionUserName(address.getConnectionUserName());
+            jndiConfig.setConnectionPassword(address.getConnectionPassword());
+            jmsConfig.setJndiConfig(jndiConfig);
+            if (address.isSetReconnectOnException()) {
+                jmsConfig.setReconnectOnException(address.isReconnectOnException());
             }
             jmsConfig.setDurableSubscriptionName(serverBehavior.getDurableSubscriberName());
             jmsConfig.setExplicitQosEnabled(true);

Added: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JNDIConfiguration.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JNDIConfiguration.java?rev=739799&view=auto
==============================================================================
--- cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JNDIConfiguration.java
(added)
+++ cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JNDIConfiguration.java
Sun Feb  1 17:54:15 2009
@@ -0,0 +1,70 @@
+/**
+ * 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 java.util.Properties;
+
+import org.springframework.jndi.JndiTemplate;
+
+
+public class JNDIConfiguration {
+    private Properties environment;
+    private String jndiConnectionFactoryName;
+    private String connectionUserName;
+    private String connectionPassword;
+    
+    public JndiTemplate createJndiTemple() {
+        JndiTemplate jt = new JndiTemplate();
+        jt.setEnvironment(environment);
+        return jt;
+    }
+
+    public String getJndiConnectionFactoryName() {
+        return jndiConnectionFactoryName;
+    }
+
+    public void setJndiConnectionFactoryName(String jndiConnectionFactoryName) {
+        this.jndiConnectionFactoryName = jndiConnectionFactoryName;
+    }
+
+    public String getConnectionUserName() {
+        return connectionUserName;
+    }
+
+    public void setConnectionUserName(String connectionUserName) {
+        this.connectionUserName = connectionUserName;
+    }
+
+    public String getConnectionPassword() {
+        return connectionPassword;
+    }
+
+    public void setConnectionPassword(String connectionPassword) {
+        this.connectionPassword = connectionPassword;
+    }
+
+    public Properties getEnvironment() {
+        return environment;
+    }
+
+    public void setEnvironment(Properties environment) {
+        this.environment = environment;
+    }
+
+}

Propchange: cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JNDIConfiguration.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java?rev=739799&r1=739798&r2=739799&view=diff
==============================================================================
--- cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
(original)
+++ cxf/trunk/rt/transports/jms/src/test/java/org/apache/cxf/transport/jms/JMSConduitTest.java
Sun Feb  1 17:54:15 2009
@@ -172,7 +172,7 @@
         final byte[] testBytes = testMsg.getBytes(Charset.defaultCharset().name()); // TODO
encoding
         JMSConfiguration jmsConfig = conduit.getJmsConfig();
         JmsTemplate jmsTemplate = new JmsTemplate();
-        jmsTemplate.setConnectionFactory(jmsConfig.getConnectionFactory());
+        jmsTemplate.setConnectionFactory(jmsConfig.getOrCreateWrappedConnectionFactory());
         javax.jms.Message message = (javax.jms.Message)jmsTemplate.execute(new SessionCallback()
{
             public Object doInJms(Session session) throws JMSException {
                 return JMSUtils.createAndSetPayload(testBytes, session, JMSConstants.BYTE_MESSAGE_TYPE);



Mime
View raw message