camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1210783 - in /camel/trunk/components/camel-cometd: ./ src/main/java/org/apache/camel/component/cometd/ src/test/java/org/apache/camel/component/cometd/
Date Tue, 06 Dec 2011 05:08:08 GMT
Author: ningjiang
Date: Tue Dec  6 05:08:07 2011
New Revision: 1210783

URL: http://svn.apache.org/viewvc?rev=1210783&view=rev
Log:
CAMEL-4730 Changed cometd SslSocketConnetor to use SslSelectChannelConnector

Added:
    camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
  (with props)
    camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java
  (with props)
Modified:
    camel/trunk/components/camel-cometd/pom.xml
    camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
    camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
    camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdProducer.java

Modified: camel/trunk/components/camel-cometd/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/pom.xml?rev=1210783&r1=1210782&r2=1210783&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/pom.xml (original)
+++ camel/trunk/components/camel-cometd/pom.xml Tue Dec  6 05:08:07 2011
@@ -65,6 +65,11 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+			<groupId>org.mockito</groupId>
+			<artifactId>mockito-core</artifactId>
+			<scope>test</scope>
+		</dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <scope>test</scope>

Modified: camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java?rev=1210783&r1=1210782&r2=1210783&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
(original)
+++ camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
Tue Dec  6 05:08:07 2011
@@ -39,6 +39,8 @@ import org.eclipse.jetty.server.handler.
 import org.eclipse.jetty.server.nio.SelectChannelConnector;
 import org.eclipse.jetty.server.session.HashSessionManager;
 import org.eclipse.jetty.server.session.SessionHandler;
+import org.eclipse.jetty.server.ssl.SslConnector;
+import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
 import org.eclipse.jetty.server.ssl.SslSocketConnector;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
@@ -58,7 +60,6 @@ public class CometdComponent extends Def
     private String sslKeyPassword;
     private String sslPassword;
     private String sslKeystore;
-    private SslSocketConnector sslSocketConnector;
     private SecurityPolicy securityPolicy;
     private List<BayeuxServer.Extension> extensions;
     private SSLContextParameters sslContextParameters;
@@ -202,28 +203,29 @@ public class CometdComponent extends Def
         return servlet;
     }
 
-    public synchronized SslSocketConnector getSslSocketConnector() {
-        if (sslContextParameters != null && sslSocketConnector == null) {
+    protected SslConnector getSslSocketConnector() {
+        SslSelectChannelConnector sslSocketConnector = null;
+        if (sslContextParameters != null) {
             SslContextFactory sslContextFactory = new CometdComponentSslContextFactory();
             try {
                 sslContextFactory.setSslContext(sslContextParameters.createSSLContext());
             } catch (Exception e) {
                 throw new RuntimeCamelException("Error initiating SSLContext.", e);
             }
-            sslSocketConnector = new SslSocketConnector(sslContextFactory);
+            sslSocketConnector = new SslSelectChannelConnector(sslContextFactory);
         } else {
-            if (sslSocketConnector == null) {
-                sslSocketConnector = new SslSocketConnector();
-                // with default null values, jetty ssl system properties
-                // and console will be read by jetty implementation
-                sslSocketConnector.getSslContextFactory().setKeyManagerPassword(sslPassword);
-                sslSocketConnector.getSslContextFactory().setKeyStorePassword(sslKeyPassword);
-                if (sslKeystore != null) {
-                    sslSocketConnector.getSslContextFactory().setKeyStore(sslKeystore);
-                }
+
+            sslSocketConnector = new SslSelectChannelConnector();
+            // with default null values, jetty ssl system properties
+            // and console will be read by jetty implementation
+            sslSocketConnector.getSslContextFactory().setKeyManagerPassword(sslPassword);
+            sslSocketConnector.getSslContextFactory().setKeyStorePassword(sslKeyPassword);
+            if (sslKeystore != null) {
+                sslSocketConnector.getSslContextFactory().setKeyStore(sslKeystore);
             }
+
         }
-        
+
         return sslSocketConnector;
     }
 

Modified: camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java?rev=1210783&r1=1210782&r2=1210783&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
(original)
+++ camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
Tue Dec  6 05:08:07 2011
@@ -46,7 +46,10 @@ public class CometdConsumer extends Defa
         super.start();
         // must connect first
         endpoint.connect(this);
-        service = new ConsumerService(endpoint.getPath(), bayeux, this);
+        // should probably look into synchronization for this.
+        if (service == null) {
+            service = new ConsumerService(endpoint.getPath(), bayeux, this);
+        }
     }
 
     @Override

Modified: camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdProducer.java?rev=1210783&r1=1210782&r2=1210783&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdProducer.java
(original)
+++ camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdProducer.java
Tue Dec  6 05:08:07 2011
@@ -46,8 +46,12 @@ public class CometdProducer extends Defa
     public void start() throws Exception {
         super.start();
         // must connect first
+
         endpoint.connect(this);
-        service = new ProducerService(getBayeux(), new CometdBinding(bayeux), endpoint.getPath(),
this);
+        // should probably look into synchronization for this.
+        if (service == null) {
+            service = new ProducerService(getBayeux(), new CometdBinding(bayeux), endpoint.getPath(),
this);
+        }
     }
 
     @Override
@@ -68,6 +72,10 @@ public class CometdProducer extends Defa
         return bayeux;
     }
 
+    protected ProducerService getProducerService() {
+        return service;
+    }
+
     public void setBayeux(BayeuxServerImpl bayeux) {
         this.bayeux = bayeux;
     }
@@ -77,7 +85,8 @@ public class CometdProducer extends Defa
         private final CometdProducer producer;
         private final CometdBinding binding;
 
-        public ProducerService(BayeuxServer bayeux, CometdBinding cometdBinding, String channel,
CometdProducer producer) {
+        public ProducerService(BayeuxServer bayeux, CometdBinding cometdBinding, String channel,
+                               CometdProducer producer) {
             super(bayeux, channel);
             this.producer = producer;
             this.binding = cometdBinding;
@@ -91,7 +100,8 @@ public class CometdProducer extends Defa
 
             if (channel != null) {
                 logDelivery(exchange, channel);
-                ServerMessage.Mutable mutable = binding.createCometdMessage(channel, serverSession,
exchange.getIn());
+                ServerMessage.Mutable mutable = binding.createCometdMessage(channel, serverSession,
+                                                                            exchange.getIn());
                 channel.publish(serverSession, mutable);
             }
         }
@@ -99,7 +109,7 @@ public class CometdProducer extends Defa
         private void logDelivery(Exchange exchange, ServerChannel channel) {
             if (LOG.isTraceEnabled()) {
                 LOG.trace(String.format("Delivering to clients %s path: %s exchange: %s",
-                        channel.getSubscribers(), channel, exchange));
+                                        channel.getSubscribers(), channel, exchange));
             }
         }
     }

Added: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java?rev=1210783&view=auto
==============================================================================
--- camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
(added)
+++ camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
Tue Dec  6 05:08:07 2011
@@ -0,0 +1,75 @@
+/**
+ * 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.camel.component.cometd;
+
+import org.apache.camel.Processor;
+import org.apache.camel.component.cometd.CometdConsumer.ConsumerService;
+import org.cometd.bayeux.server.LocalSession;
+import org.cometd.bayeux.server.ServerChannel;
+import org.cometd.server.BayeuxServerImpl;
+import org.eclipse.jetty.util.log.Logger;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CometdConsumerTest {
+
+    private CometdConsumer testObj;
+    @Mock
+    private CometdEndpoint endpoint;
+    @Mock
+    private Processor processor;
+    @Mock
+    private BayeuxServerImpl bayeuxServerImpl;
+    @Mock
+    private LocalSession localSession;
+    @Mock
+    private Logger logger;
+    @Mock
+    private ServerChannel serverChannel;
+
+    @Before
+    public void before() {
+        when(bayeuxServerImpl.newLocalSession(anyString())).thenReturn(localSession);
+        when(bayeuxServerImpl.getLogger()).thenReturn(logger);
+        when(bayeuxServerImpl.getChannel(anyString())).thenReturn(serverChannel);
+
+        testObj = new CometdConsumer(endpoint, processor);
+        testObj.setBayeux(bayeuxServerImpl);
+    }
+
+    @Test
+    public void testStartDoesntCreateMultipleServices() throws Exception {
+        // setup
+        testObj.start();
+        ConsumerService expectedService = testObj.getConsumerService();
+        testObj.start();
+
+        // act
+        ConsumerService result = testObj.getConsumerService();
+
+        // assert
+        assertEquals(expectedService, result);
+    }
+}

Propchange: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java?rev=1210783&view=auto
==============================================================================
--- camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java
(added)
+++ camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java
Tue Dec  6 05:08:07 2011
@@ -0,0 +1,64 @@
+/**
+ * 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.camel.component.cometd;
+
+import org.apache.camel.component.cometd.CometdProducer.ProducerService;
+import org.cometd.bayeux.server.LocalSession;
+import org.cometd.server.BayeuxServerImpl;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CometdProducerTest {
+
+    private CometdProducer testObj;
+    @Mock
+    private CometdEndpoint endpoint;
+    @Mock
+    private BayeuxServerImpl bayeuxServerImpl;
+    @Mock
+    private LocalSession localSession;
+
+    @Before
+    public void before() {
+        when(bayeuxServerImpl.newLocalSession(anyString())).thenReturn(localSession);
+        testObj = new CometdProducer(endpoint);
+        testObj.setBayeux(bayeuxServerImpl);
+    }
+
+    @Test
+    public void testStartDoesNotCreateNewProducerService() throws Exception {
+        // setup
+        testObj.start();
+        ProducerService expectedService = testObj.getProducerService();
+        testObj.start();
+
+        // act
+        ProducerService result = testObj.getProducerService();
+
+        // assert
+
+        assertEquals(expectedService, result);
+    }
+}

Propchange: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message