You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/09/29 10:37:34 UTC

svn commit: r451163 - in /incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src: main/java/org/apache/servicemix/jms/ main/java/org/apache/servicemix/jms/jca/ test/java/org/apache/servicemix/jms/ test/resources/

Author: gnodet
Date: Fri Sep 29 01:37:33 2006
New Revision: 451163

URL: http://svn.apache.org/viewvc?view=rev&rev=451163
Log:
SM-603: NPE in StandardConsumerProcessor

Added:
    incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsStandardTest.java
Modified:
    incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
    incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java
    incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/resources/jndi.properties

Modified: incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java?view=diff&rev=451163&r1=451162&r2=451163
==============================================================================
--- incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java (original)
+++ incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/AbstractJmsProcessor.java Fri Sep 29 01:37:33 2006
@@ -67,11 +67,10 @@
     }
 
     public void start() throws Exception {
-        InitialContext ctx = null;
-        ConnectionFactory connectionFactory = null;
         try {
-            // First check configured connectionFactory on the endpoint
-            connectionFactory = getConnectionFactory();
+            InitialContext ctx = getInitialContext();
+            ConnectionFactory connectionFactory = null;
+            connectionFactory = getConnectionFactory(ctx);
             connection = connectionFactory.createConnection();
             connection.start();
             doStart(ctx);
@@ -82,20 +81,14 @@
                 // TODO: log
             }
             throw e;
-        } finally {
-            if (ctx != null) {
-                ctx.close();
-            }
         }
     }
     
-    protected ConnectionFactory getConnectionFactory() throws NamingException {
-        InitialContext ctx = null;
+    protected ConnectionFactory getConnectionFactory(InitialContext ctx) throws NamingException {
         // First check configured connectionFactory on the endpoint
         ConnectionFactory connectionFactory = endpoint.getConnectionFactory();
         // Then, check for jndi connection factory name on the endpoint
         if (connectionFactory == null && endpoint.getJndiConnectionFactoryName() != null) {
-            ctx = getInitialContext();
             connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getJndiConnectionFactoryName());
         }
         // Check for a configured connectionFactory on the configuration
@@ -104,7 +97,6 @@
         }
         // Check for jndi connection factory name on the configuration
         if (connectionFactory == null && endpoint.getConfiguration().getJndiConnectionFactoryName() != null) {
-            ctx = getInitialContext();
             connectionFactory = (ConnectionFactory) ctx.lookup(endpoint.getConfiguration().getJndiConnectionFactoryName());
         }
         return connectionFactory;

Modified: incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java?view=diff&rev=451163&r1=451162&r2=451163
==============================================================================
--- incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java (original)
+++ incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/main/java/org/apache/servicemix/jms/jca/JcaProviderProcessor.java Fri Sep 29 01:37:33 2006
@@ -49,12 +49,12 @@
     }
 
     public void start() throws Exception {
-        connectionFactory = getConnectionFactory();
+        InitialContext ctx = getInitialContext();
+        connectionFactory = getConnectionFactory(ctx);
         channel = endpoint.getServiceUnit().getComponent().getComponentContext().getDeliveryChannel();
         destination = endpoint.getDestination();
         if (destination == null) {
             if (endpoint.getJndiDestinationName() != null) {
-                InitialContext ctx = getInitialContext();
                 destination = (Destination) ctx.lookup(endpoint.getJndiDestinationName());
             } else if (endpoint.getJmsProviderDestinationName() == null) {
                 throw new IllegalStateException("No destination provided");

Added: incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsStandardTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsStandardTest.java?view=auto&rev=451163
==============================================================================
--- incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsStandardTest.java (added)
+++ incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/java/org/apache/servicemix/jms/JmsStandardTest.java Fri Sep 29 01:37:33 2006
@@ -0,0 +1,82 @@
+/*
+ * 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.servicemix.jms;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.xml.namespace.QName;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.jndi.ActiveMQInitialContextFactory;
+import org.apache.activemq.xbean.BrokerFactoryBean;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.springframework.core.io.ClassPathResource;
+
+import junit.framework.TestCase;
+
+public class JmsStandardTest extends TestCase {
+
+    protected JBIContainer container;
+    protected BrokerService broker;
+    protected ActiveMQConnectionFactory connectionFactory;
+    
+    protected void setUp() throws Exception {
+        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, ActiveMQInitialContextFactory.class.getName());
+        System.setProperty(Context.PROVIDER_URL, "tcp://localhost:61216");
+
+      
+        BrokerFactoryBean bfb = new BrokerFactoryBean(new ClassPathResource("org/apache/servicemix/jms/activemq.xml"));
+        bfb.afterPropertiesSet();
+        broker = bfb.getBroker();
+        broker.start();
+        
+        container = new JBIContainer();
+        container.setUseMBeanServer(true);
+        container.setCreateMBeanServer(true);
+        container.setMonitorInstallationDirectory(false);
+        container.setNamingContext(new InitialContext());
+        container.init();
+        
+        connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61216");
+    }
+    
+    protected void tearDown() throws Exception {
+        if (container != null) {
+            container.shutDown();
+        }
+        if (broker != null) {
+            broker.stop();
+        }
+    }
+
+    public void test() throws Exception {
+        JmsSpringComponent jms = new JmsSpringComponent();
+        JmsEndpoint ep = new JmsEndpoint();
+        ep.setInitialContextFactory(ActiveMQInitialContextFactory.class.getName());
+        ep.setJndiProviderURL("tcp://localhost:61216");
+        ep.setJndiConnectionFactoryName("ConnectionFactory");
+        ep.setJndiDestinationName("MyQueue");
+        ep.setProcessorName("standard");
+        ep.setRoleAsString("provider");
+        ep.setService(new QName("service"));
+        ep.setEndpoint("endpoint");
+        jms.setEndpoints(new JmsEndpoint[] { ep });
+        container.activateComponent(jms, "jms");
+        container.start();
+    }
+}

Modified: incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/resources/jndi.properties
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/resources/jndi.properties?view=diff&rev=451163&r1=451162&r2=451163
==============================================================================
--- incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/resources/jndi.properties (original)
+++ incubator/servicemix/branches/servicemix-3.0/servicemix-jms/src/test/resources/jndi.properties Fri Sep 29 01:37:33 2006
@@ -23,4 +23,6 @@
 java.naming.factory.initial = org.apache.xbean.spring.jndi.SpringInitialContextFactory
 java.naming.provider.url = jndi.xml
 
+queue.MyQueue = MyQueue
+
 # END SNIPPET: jndi