camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [3/4] camel git commit: CAMEL-8637: Upgrade Jetty version to 9.x in Camel-CometD
Date Thu, 21 Apr 2016 13:41:17 GMT
CAMEL-8637: Upgrade Jetty version to 9.x in Camel-CometD


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2a2505f6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2a2505f6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2a2505f6

Branch: refs/heads/master
Commit: 2a2505f69c5676d77601342fcbcceaed4850fd5a
Parents: 25461f9
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Thu Apr 21 14:21:32 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Thu Apr 21 15:18:40 2016 +0200

----------------------------------------------------------------------
 components/camel-cometd/pom.xml                 | 12 ++---
 .../camel/component/cometd/CometdComponent.java | 53 ++++++++------------
 .../camel/component/cometd/CometdConsumer.java  |  4 +-
 .../component/cometd/CometdConsumerTest.java    | 10 +++-
 4 files changed, 39 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/2a2505f6/components/camel-cometd/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-cometd/pom.xml b/components/camel-cometd/pom.xml
index 82a94f5..814e1c7 100644
--- a/components/camel-cometd/pom.xml
+++ b/components/camel-cometd/pom.xml
@@ -52,32 +52,32 @@
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-server</artifactId>
-            <version>${jetty8-version}</version>
+            <version>${jetty9-version}</version>
         </dependency>
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-servlet</artifactId>
-            <version>${jetty8-version}</version>
+            <version>${jetty9-version}</version>
         </dependency>
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-servlets</artifactId>
-            <version>${jetty8-version}</version>
+            <version>${jetty9-version}</version>
         </dependency>
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-util</artifactId>
-            <version>${jetty8-version}</version>
+            <version>${jetty9-version}</version>
         </dependency>
         <dependency>
             <groupId>org.eclipse.jetty</groupId>
             <artifactId>jetty-jmx</artifactId>
-            <version>${jetty8-version}</version>
+            <version>${jetty9-version}</version>
         </dependency>
         <dependency>
             <groupId>org.cometd.java</groupId>
             <artifactId>cometd-java-server</artifactId>
-            <version>${cometd-java-server}</version>
+            <version>3.0.9</version>
         </dependency>
 
         <!-- Test Dependencies -->

http://git-wip-us.apache.org/repos/asf/camel/blob/2a2505f6/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
b/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
index 50e3b53..61179c7 100644
--- a/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
+++ b/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
@@ -26,21 +26,18 @@ import javax.net.ssl.SSLContext;
 import javax.servlet.DispatcherType;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.impl.UriEndpointComponent;
 import org.apache.camel.util.jsse.SSLContextParameters;
 import org.cometd.bayeux.server.BayeuxServer;
 import org.cometd.bayeux.server.SecurityPolicy;
 import org.cometd.server.BayeuxServerImpl;
-import org.cometd.server.CometdServlet;
+import org.cometd.server.CometDServlet;
 import org.eclipse.jetty.server.Connector;
 import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
-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.servlet.FilterHolder;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
@@ -68,11 +65,11 @@ public class CometdComponent extends UriEndpointComponent {
 
     class ConnectorRef {
         Connector connector;
-        CometdServlet servlet;
+        CometDServlet servlet;
         Server server;
         int refCount;
 
-        public ConnectorRef(Connector connector, CometdServlet servlet, Server server) {
+        public ConnectorRef(Connector connector, CometDServlet servlet, Server server) {
             this.connector = connector;
             this.servlet = servlet;
             this.server = server;
@@ -103,6 +100,7 @@ public class CometdComponent extends UriEndpointComponent {
      * Connects the URL specified on the endpoint to the specified processor.
      */
     public void connect(CometdProducerConsumer prodcon) throws Exception {
+    	Server server = null;
         // Make sure that there is a connector for the requested endpoint.
         CometdEndpoint endpoint = prodcon.getEndpoint();
         String connectorKey = endpoint.getProtocol() + ":" + endpoint.getUri().getHost()
+ ":" + endpoint.getPort();
@@ -110,11 +108,12 @@ public class CometdComponent extends UriEndpointComponent {
         synchronized (connectors) {
             ConnectorRef connectorRef = connectors.get(connectorKey);
             if (connectorRef == null) {
-                Connector connector;
+                ServerConnector connector;
+                server = createServer();
                 if ("cometds".equals(endpoint.getProtocol())) {
-                    connector = getSslSocketConnector();
+                    connector = getSslSocketConnector(server);
                 } else {
-                    connector = new SelectChannelConnector();
+                    connector = new ServerConnector(server);
                 }
                 connector.setPort(endpoint.getPort());
                 connector.setHost(endpoint.getUri().getHost());
@@ -122,10 +121,10 @@ public class CometdComponent extends UriEndpointComponent {
                     LOG.warn("You use localhost interface! It means that no external connections
will be available."
                             + " Don't you want to use 0.0.0.0 instead (all network interfaces)?");
                 }
-                Server server = createServer();
+                
                 server.addConnector(connector);
 
-                CometdServlet servlet = createServletForConnector(server, connector, endpoint);
+                CometDServlet servlet = createServletForConnector(server, connector, endpoint);
                 connectorRef = new ConnectorRef(connector, servlet, server);
                 server.start();
 
@@ -175,11 +174,10 @@ public class CometdComponent extends UriEndpointComponent {
         }
     }
 
-    protected CometdServlet createServletForConnector(Server server, Connector connector,
CometdEndpoint endpoint) throws Exception {
-        CometdServlet servlet = new CometdServlet();
+    protected CometDServlet createServletForConnector(Server server, Connector connector,
CometdEndpoint endpoint) throws Exception {
+    	CometDServlet servlet = new CometDServlet();
 
         ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.NO_SECURITY
| ServletContextHandler.NO_SESSIONS);
-        context.setConnectorNames(new String[]{connector.getName()});
 
         ServletHolder holder = new ServletHolder();
         holder.setServlet(servlet);
@@ -218,29 +216,22 @@ public class CometdComponent extends UriEndpointComponent {
         return servlet;
     }
 
-    protected SslConnector getSslSocketConnector() {
-        SslSelectChannelConnector sslSocketConnector = null;
+    protected ServerConnector getSslSocketConnector(Server server) throws Exception {
+        ServerConnector 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 SslSelectChannelConnector(sslContextFactory);
+            sslContextFactory.setSslContext(sslContextParameters.createSSLContext());
+            sslSocketConnector = new ServerConnector(server, sslContextFactory);
         } else {
-
-            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);
+            SslContextFactory sslContextFactory = new SslContextFactory();
+            sslContextFactory.setKeyStorePassword(sslKeyPassword);
+            sslContextFactory.setKeyManagerPassword(sslPassword);
             if (sslKeystore != null) {
-                sslSocketConnector.getSslContextFactory().setKeyStorePath(sslKeystore);
+                sslContextFactory.setKeyStorePath(sslKeystore);
             }
+            sslSocketConnector = new ServerConnector(server, sslContextFactory);
 
         }
-
         return sslSocketConnector;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/2a2505f6/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
b/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
index 3ddf9f6..175715a 100644
--- a/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
+++ b/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdConsumer.java
@@ -75,12 +75,14 @@ public class CometdConsumer extends DefaultConsumer implements CometdProducerCon
         private final CometdEndpoint endpoint;
         private final CometdConsumer consumer;
         private final CometdBinding binding;
+        private final String channelName;
 
         public ConsumerService(String channel, BayeuxServerImpl bayeux, CometdConsumer consumer)
{
             super(bayeux, channel);
             this.endpoint = consumer.getEndpoint();
             this.binding = createBinding(bayeux);
             this.consumer = consumer;
+            this.channelName = channel;
             addService(channel, "push");
         }
 
@@ -89,7 +91,7 @@ public class CometdConsumer extends DefaultConsumer implements CometdProducerCon
             return new CometdBinding(bayeux, enableSessionHeaders);
         }
 
-        public void push(ServerSession remote, String channelName, ServerMessage cometdMessage,
String messageId) throws Exception {
+        public void push(ServerSession remote, ServerMessage cometdMessage) throws Exception
{
             Object data = null;
 
             Message message = binding.createCamelMessage(remote, cometdMessage, data);

http://git-wip-us.apache.org/repos/asf/camel/blob/2a2505f6/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
b/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
index 9e5c6ba..8cd8bd2 100644
--- a/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
+++ b/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdConsumerTest.java
@@ -23,6 +23,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.component.cometd.CometdConsumer.ConsumerService;
+import org.cometd.bayeux.MarkedReference;
 import org.cometd.bayeux.server.LocalSession;
 import org.cometd.bayeux.server.ServerChannel;
 import org.cometd.bayeux.server.ServerMessage;
@@ -38,6 +39,7 @@ import org.mockito.runners.MockitoJUnitRunner;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.anyObject;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
@@ -62,12 +64,16 @@ public class CometdConsumerTest {
     private ServerChannel serverChannel;
     @Mock
     private ServerSession remote;
+    @Mock
+    private MarkedReference<ServerChannel> markedReferenceServerChannel;
 
     @Before
     public void before() {
         when(bayeuxServerImpl.newLocalSession(anyString())).thenReturn(localSession);
-        when(bayeuxServerImpl.getLogger()).thenReturn(logger);
+        //when(bayeuxServerImpl.get).thenReturn(logger);
         when(bayeuxServerImpl.getChannel(anyString())).thenReturn(serverChannel);
+        when(bayeuxServerImpl.createChannelIfAbsent(anyString())).thenReturn(markedReferenceServerChannel);
+        when(markedReferenceServerChannel.getReference()).thenReturn(serverChannel);
 
         testObj = new CometdConsumer(endpoint, processor);
         testObj.setBayeux(bayeuxServerImpl);
@@ -104,7 +110,7 @@ public class CometdConsumerTest {
         ArgumentCaptor<Message> transferredMessage = ArgumentCaptor.forClass(Message.class);
 
         // act
-        testObj.getConsumerService().push(remote, "channelName", cometdMessage, "messageId");
+        testObj.getConsumerService().push(remote, cometdMessage);
 
         // verify
         verify(exchange).setIn(transferredMessage.capture());


Mime
View raw message