camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/2] git commit: CAMEL-7150 Provides options to setup the parameter on the WebSocketServlet
Date Sat, 08 Feb 2014 06:03:15 GMT
CAMEL-7150 Provides options to setup the parameter on the WebSocketServlet


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

Branch: refs/heads/camel-2.11.x
Commit: 0e5304ca4061aee400fbb31a3e97cb571f786266
Parents: 55774b3
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Sat Feb 8 13:55:40 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Sat Feb 8 13:58:52 2014 +0800

----------------------------------------------------------------------
 .../component/websocket/WebsocketComponent.java | 21 +++++++
 .../component/websocket/WebsocketEndpoint.java  | 47 +++++++++++++++
 .../WebscoketEndpointConfigurationTest.java     | 62 ++++++++++++++++++++
 3 files changed, 130 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/0e5304ca/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 31bc5c0..0f65935 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
@@ -55,6 +55,7 @@ import org.eclipse.jetty.servlets.CrossOriginFilter;
 import org.eclipse.jetty.util.resource.Resource;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.eclipse.jetty.util.thread.ThreadPool;
+import org.eclipse.jetty.websocket.WebSocketFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -157,6 +158,8 @@ public class WebsocketComponent extends DefaultComponent {
 
                 // Create ServletContextHandler
                 ServletContextHandler context = createContext(server, connector, endpoint.getHandlers());
+                // setup the WebSocketComponentServlet initial parameters 
+                setWebSocketComponentServletInitialParameter(context, endpoint);
                 server.setHandler(context);
 
                 // Apply CORS (http://www.w3.org/TR/cors/)
@@ -300,6 +303,24 @@ public class WebsocketComponent extends DefaultComponent {
         setProperties(endpoint, parameters);
         return endpoint;
     }
+    
+    protected void setWebSocketComponentServletInitialParameter(ServletContextHandler context,
WebsocketEndpoint endpoint) {
+        if (endpoint.getBufferSize() != null) {
+            context.setInitParameter("bufferSize", endpoint.getBufferSize().toString());
+        }
+        if (endpoint.getMaxIdleTime() != null) {
+            context.setInitParameter("maxIdleTime", endpoint.getMaxIdleTime().toString());
+        }
+        if (endpoint.getMaxTextMessageSize() != null) {
+            context.setInitParameter("maxTextMessageSize", endpoint.getMaxTextMessageSize().toString());
+        }
+        if (endpoint.getMaxBinaryMessageSize() != null) {
+            context.setInitParameter("maxBinaryMessageSize", endpoint.getMaxBinaryMessageSize().toString());
+        }
+        if (endpoint.getMinVersion() != null) {
+            context.setInitParameter("minVersion", endpoint.getMinVersion().toString());
+        }
+    }
 
     protected Server createServer() throws Exception {
         Server server = new Server();

http://git-wip-us.apache.org/repos/asf/camel/blob/0e5304ca/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
index 9c4226e..d32a0a3 100644
--- a/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
+++ b/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
@@ -54,6 +54,13 @@ public class WebsocketEndpoint extends DefaultEndpoint {
     private String staticResources;
 
     private Integer port;
+    // Here are the configuration on the WebSocketComponentServlet
+    private Integer bufferSize;
+    private Integer maxIdleTime;
+    private Integer maxTextMessageSize;
+    private Integer maxBinaryMessageSize;
+    private Integer minVersion;
+    
 
     public WebsocketEndpoint(WebsocketComponent component, String uri, String remaining,
Map<String, Object> parameters) {
         super(uri, component);
@@ -164,6 +171,46 @@ public class WebsocketEndpoint extends DefaultEndpoint {
         return sessionSupport;
     }
 
+    public Integer getBufferSize() {
+        return bufferSize;
+    }
+
+    public void setBufferSize(Integer bufferSize) {
+        this.bufferSize = bufferSize;
+    }
+
+    public Integer getMaxIdleTime() {
+        return maxIdleTime;
+    }
+
+    public void setMaxIdleTime(Integer maxIdleTime) {
+        this.maxIdleTime = maxIdleTime;
+    }
+
+    public Integer getMaxTextMessageSize() {
+        return maxTextMessageSize;
+    }
+
+    public void setMaxTextMessageSize(Integer maxTextMessageSize) {
+        this.maxTextMessageSize = maxTextMessageSize;
+    }
+
+    public Integer getMaxBinaryMessageSize() {
+        return maxBinaryMessageSize;
+    }
+
+    public void setMaxBinaryMessageSize(Integer maxBinaryMessageSize) {
+        this.maxBinaryMessageSize = maxBinaryMessageSize;
+    }
+
+    public Integer getMinVersion() {
+        return minVersion;
+    }
+
+    public void setMinVersion(Integer minVersion) {
+        this.minVersion = minVersion;
+    }
+
     public List<Handler> getHandlers() {
         return handlers;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/0e5304ca/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
new file mode 100644
index 0000000..b74848f
--- /dev/null
+++ b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebscoketEndpointConfigurationTest.java
@@ -0,0 +1,62 @@
+/**
+ * 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();
+        Consumer consumer = websocketEndpoint.createConsumer(processor);
+        component.connect((WebsocketProducerConsumer) consumer);
+        
+        assertNotNull(consumer);
+        assertEquals(WebsocketConsumer.class, consumer.getClass());
+        
+        // just check the servlet initial parameters
+        ConnectorRef conector = component.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