camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [1/2] camel git commit: CAMEL-9950: Camel-Websocket: NPE in case minThreads, maxThreads and getThreadPool equals to null
Date Fri, 06 May 2016 11:16:21 GMT
Repository: camel
Updated Branches:
  refs/heads/master 426922a26 -> 5ae785204


CAMEL-9950: Camel-Websocket: NPE in case minThreads, maxThreads and getThreadPool equals to
null


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

Branch: refs/heads/master
Commit: 57aac0f5fd82c8ec6cf522943c6c3a653143688c
Parents: 426922a
Author: Andrea Cosentino <ancosen@gmail.com>
Authored: Fri May 6 13:13:10 2016 +0200
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Fri May 6 13:13:10 2016 +0200

----------------------------------------------------------------------
 .../component/websocket/WebsocketComponent.java |   3 +
 .../WebscoketEndpointConfigurationTest.java     |  64 -----------
 .../WebsocketEndpointConfigurationTest.java     | 107 +++++++++++++++++++
 3 files changed, 110 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/57aac0f5/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
index 271b75f..d721020 100644
--- a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
+++ b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
@@ -338,6 +338,9 @@ public class WebsocketComponent extends UriEndpointComponent {
 
     protected Server createServer() throws Exception {
         Server server = null;
+        if (minThreads == null && maxThreads == null && getThreadPool() ==
null) {
+            throw new RuntimeCamelException("Error creating JettyWebSocketServer. MinThreads/MaxThreads
or ThreadPool must be defined");        	
+        }
         // configure thread pool if min/max given
         if (minThreads != null || maxThreads != null) {
             if (getThreadPool() != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/57aac0f5/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebscoketEndpointConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebscoketEndpointConfigurationTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebscoketEndpointConfigurationTest.java
deleted file mode 100644
index 27e01ba..0000000
--- a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebscoketEndpointConfigurationTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * 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.websocket;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.junit.Test;
-import org.mockito.Mock;
-
-public class WebscoketEndpointConfigurationTest extends CamelTestSupport {
-    
-    private int port;
-    
-    @Mock
-    private Processor processor;
-
-    @Override
-    public void setUp() throws Exception {
-        port = AvailablePortFinder.getNextAvailable(16330);
-        super.setUp();
-    }
-    
-    @Test
-    public void testSetServletInitalparameters() throws Exception {
-        String uri = "websocket://localhost:" + port + "/bar?bufferSize=65000&maxIdleTime=3000";
-        WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint)context.getEndpoint(uri);
-        WebsocketComponent component = websocketEndpoint.getComponent();
-        component.setMinThreads(1);
-        component.setMaxThreads(20);
-        Consumer consumer = websocketEndpoint.createConsumer(processor);
-        component.connect((WebsocketProducerConsumer) consumer);
-        
-        assertNotNull(consumer);
-        assertEquals(WebsocketConsumer.class, consumer.getClass());
-        
-        // just check the servlet initial parameters
-        ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
-        
-        ServletContextHandler context = (ServletContextHandler)conector.server.getHandler();
-        String buffersize = context.getInitParameter("bufferSize");
-        assertEquals("Get a wrong buffersize", "65000", buffersize);
-        String maxIdleTime = context.getInitParameter("maxIdleTime");
-        assertEquals("Get a worng maxIdleTime", "3000", maxIdleTime);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/57aac0f5/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointConfigurationTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointConfigurationTest.java
new file mode 100644
index 0000000..5e8a59b
--- /dev/null
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointConfigurationTest.java
@@ -0,0 +1,107 @@
+/**
+ * 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.websocket;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.component.websocket.WebsocketComponent.ConnectorRef;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.util.thread.QueuedThreadPool;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class WebsocketEndpointConfigurationTest extends CamelTestSupport {
+    
+    private int port;
+    
+    @Mock
+    private Processor processor;
+
+    @Override
+    public void setUp() throws Exception {
+        port = AvailablePortFinder.getNextAvailable(16330);
+        super.setUp();
+    }
+    
+    @Test
+    public void testSetServletInitalparameters() throws Exception {
+        String uri = "websocket://localhost:" + port + "/bar?bufferSize=65000&maxIdleTime=3000";
+        WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint)context.getEndpoint(uri);
+        WebsocketComponent component = websocketEndpoint.getComponent();
+        component.setMinThreads(1);
+        component.setMaxThreads(20);
+        Consumer consumer = websocketEndpoint.createConsumer(processor);
+        component.connect((WebsocketProducerConsumer) consumer);
+        
+        assertNotNull(consumer);
+        assertEquals(WebsocketConsumer.class, consumer.getClass());
+        
+        // just check the servlet initial parameters
+        ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
+        
+        ServletContextHandler context = (ServletContextHandler)conector.server.getHandler();
+        String buffersize = context.getInitParameter("bufferSize");
+        assertEquals("Get a wrong buffersize", "65000", buffersize);
+        String maxIdleTime = context.getInitParameter("maxIdleTime");
+        assertEquals("Get a worng maxIdleTime", "3000", maxIdleTime);
+    }
+    
+    @Test(expected=RuntimeException.class)
+    public void testSetServletNoMinThreadsNoMaxThreadsNoThreadPool() throws Exception {
+        String uri = "websocket://localhost:" + port + "/bar?bufferSize=65000&maxIdleTime=3000";
+        WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint)context.getEndpoint(uri);
+        WebsocketComponent component = websocketEndpoint.getComponent();
+        Consumer consumer = websocketEndpoint.createConsumer(processor);
+        component.connect((WebsocketProducerConsumer) consumer);
+        assertNotNull(consumer);
+        assertEquals(WebsocketConsumer.class, consumer.getClass());
+        
+        // just check the servlet initial parameters
+        ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
+        
+        ServletContextHandler context = (ServletContextHandler)conector.server.getHandler();
+        String buffersize = context.getInitParameter("bufferSize");
+        assertEquals("Get a wrong buffersize", "65000", buffersize);
+        String maxIdleTime = context.getInitParameter("maxIdleTime");
+        assertEquals("Get a worng maxIdleTime", "3000", maxIdleTime);
+    }
+    
+    @Test
+    public void testSetServletThreadPool() throws Exception {
+        String uri = "websocket://localhost:" + port + "/bar?bufferSize=65000&maxIdleTime=3000";
+        WebsocketEndpoint websocketEndpoint = (WebsocketEndpoint)context.getEndpoint(uri);
+        WebsocketComponent component = websocketEndpoint.getComponent();
+        QueuedThreadPool qtp = new QueuedThreadPool(20, 1);
+        component.setThreadPool(qtp);
+        Consumer consumer = websocketEndpoint.createConsumer(processor);
+        component.connect((WebsocketProducerConsumer) consumer);
+        assertNotNull(consumer);
+        assertEquals(WebsocketConsumer.class, consumer.getClass());
+        
+        // just check the servlet initial parameters
+        ConnectorRef conector = WebsocketComponent.getConnectors().values().iterator().next();
+        
+        ServletContextHandler context = (ServletContextHandler)conector.server.getHandler();
+        String buffersize = context.getInitParameter("bufferSize");
+        assertEquals("Get a wrong buffersize", "65000", buffersize);
+        String maxIdleTime = context.getInitParameter("maxIdleTime");
+        assertEquals("Get a worng maxIdleTime", "3000", maxIdleTime);
+    }
+
+}


Mime
View raw message