You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ay...@apache.org on 2014/03/27 22:21:41 UTC
[2/2] git commit: CAMEL-7316: change the name from ws to ahc-ws
CAMEL-7316: change the name from ws to ahc-ws
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0f6f2e32
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0f6f2e32
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0f6f2e32
Branch: refs/heads/master
Commit: 0f6f2e32b760c8fc2bcfcc1eeea4104040c90ff3
Parents: e135e2e
Author: Akitoshi Yoshida <ay...@apache.org>
Authored: Thu Mar 27 22:19:23 2014 +0100
Committer: Akitoshi Yoshida <ay...@apache.org>
Committed: Thu Mar 27 22:19:23 2014 +0100
----------------------------------------------------------------------
apache-camel/pom.xml | 8 +-
.../src/main/descriptors/common-bin.xml | 2 +-
components/camel-ahc-ws/pom.xml | 87 +++++++
.../camel/component/ahc/ws/WsComponent.java | 46 ++++
.../camel/component/ahc/ws/WsConstants.java | 33 +++
.../camel/component/ahc/ws/WsConsumer.java | 83 +++++++
.../camel/component/ahc/ws/WsEndpoint.java | 246 +++++++++++++++++++
.../camel/component/ahc/ws/WsProducer.java | 138 +++++++++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../services/org/apache/camel/component/ahc-ws | 18 ++
.../services/org/apache/camel/component/ahc-wss | 18 ++
.../camel/component/ahc/ws/TestServlet.java | 105 ++++++++
.../ahc/ws/WsProducerConsumerTest.java | 97 ++++++++
.../camel/component/ahc/ws/WsProducerTest.java | 40 +++
.../component/ahc/ws/WsProducerTestBase.java | 217 ++++++++++++++++
.../ahc/ws/WsProducerUsingStreamingTest.java | 52 ++++
.../camel/component/ahc/ws/WssProducerTest.java | 92 +++++++
.../src/test/resources/jsse/localhost.ks | Bin 0 -> 1265 bytes
.../src/test/resources/log4j.properties | 43 ++++
components/camel-ws/pom.xml | 87 -------
.../apache/camel/component/ws/WsComponent.java | 45 ----
.../apache/camel/component/ws/WsConstants.java | 33 ---
.../apache/camel/component/ws/WsConsumer.java | 83 -------
.../apache/camel/component/ws/WsEndpoint.java | 246 -------------------
.../apache/camel/component/ws/WsProducer.java | 138 -----------
.../src/main/resources/META-INF/LICENSE.txt | 203 ---------------
.../src/main/resources/META-INF/NOTICE.txt | 11 -
.../services/org/apache/camel/component/ws | 18 --
.../services/org/apache/camel/component/wss | 18 --
.../apache/camel/component/ws/TestServlet.java | 105 --------
.../component/ws/WsProducerConsumerTest.java | 97 --------
.../camel/component/ws/WsProducerTest.java | 40 ---
.../camel/component/ws/WsProducerTestBase.java | 217 ----------------
.../ws/WsProducerUsingStreamingTest.java | 52 ----
.../camel/component/ws/WssProducerTest.java | 91 -------
.../src/test/resources/jsse/localhost.ks | Bin 1265 -> 0 bytes
.../src/test/resources/log4j.properties | 43 ----
components/pom.xml | 2 +-
parent/pom.xml | 10 +-
.../features/src/main/resources/features.xml | 10 +-
41 files changed, 1545 insertions(+), 1543 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index d61eb3d..e4128f6 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -57,6 +57,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-ahc-ws</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-amqp</artifactId>
</dependency>
<dependency>
@@ -648,10 +652,6 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-ws</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
<artifactId>camel-xmlbeans</artifactId>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index ee39c06..b4bf6c1 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -25,6 +25,7 @@
<scope>runtime</scope>
<includes>
<include>org.apache.camel:camel-ahc</include>
+ <include>org.apache.camel:camel-ahc-ws</include>
<include>org.apache.camel:camel-amqp</include>
<include>org.apache.camel:camel-apns</include>
<include>org.apache.camel:camel-atom</include>
@@ -173,7 +174,6 @@
<include>org.apache.camel:camel-vertx</include>
<include>org.apache.camel:camel-weather</include>
<include>org.apache.camel:camel-websocket</include>
- <include>org.apache.camel:camel-ws</include>
<include>org.apache.camel:camel-xmlbeans</include>
<include>org.apache.camel:camel-xmljson</include>
<include>org.apache.camel:camel-xmlrpc</include>
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/pom.xml b/components/camel-ahc-ws/pom.xml
new file mode 100644
index 0000000..553e199
--- /dev/null
+++ b/components/camel-ahc-ws/pom.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.14-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-ahc-ws</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: AHC-WS</name>
+ <description>Camel Websocket Client support</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.ahc.ws.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=ahc-ws</camel.osgi.export.service>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-ahc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.grizzly</groupId>
+ <artifactId>grizzly-websockets</artifactId>
+ <version>2.3.11</version>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- Jetty for testing-->
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-websocket</artifactId>
+ <version>${jetty-version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-servlet</artifactId>
+ <version>${jetty-version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsComponent.java b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsComponent.java
new file mode 100644
index 0000000..eb29502
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsComponent.java
@@ -0,0 +1,46 @@
+/**
+ * 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.ahc.ws;
+
+import java.net.URI;
+
+import org.apache.camel.component.ahc.AhcComponent;
+import org.apache.camel.component.ahc.AhcEndpoint;
+
+/**
+ * Defines the <a href="http://camel.apache.org/ws.html">WebSocket Client Component</a>
+ */
+public class WsComponent extends AhcComponent {
+
+ /* (non-Javadoc)
+ * @see org.apache.camel.component.ahc.AhcComponent#createAddressUri(java.lang.String, java.lang.String)
+ */
+ @Override
+ protected String createAddressUri(String uri, String remaining) {
+ // remove "ahc-"
+ return uri.substring(4);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.camel.component.ahc.AhcComponent#createAhcEndpoint(java.lang.String, org.apache.camel.component.ahc.AhcComponent, java.net.URI)
+ */
+ @Override
+ protected AhcEndpoint createAhcEndpoint(String endpointUri, AhcComponent component, URI httpUri) {
+ return new WsEndpoint(endpointUri, (WsComponent)component);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConstants.java b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConstants.java
new file mode 100644
index 0000000..fbd8bc3
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConstants.java
@@ -0,0 +1,33 @@
+/**
+ * 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.ahc.ws;
+
+/**
+ *
+ */
+public final class WsConstants {
+
+ public static final String CONTENT_TYPE_JAVA_SERIALIZED_OBJECT = "application/x-java-serialized-object";
+ public static final String CONTENT_TYPE_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
+
+ public static final String WS_PROTOCOL = "ahc-ws";
+ public static final String WSS_PROTOCOL = "ahc-wss";
+
+ private WsConstants() {
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConsumer.java b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConsumer.java
new file mode 100644
index 0000000..ab8b5a5
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsConsumer.java
@@ -0,0 +1,83 @@
+/**
+ * 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.ahc.ws;
+
+import java.io.InputStream;
+import java.io.Reader;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+public class WsConsumer extends DefaultConsumer {
+
+ public WsConsumer(WsEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ @Override
+ public void start() throws Exception {
+ super.start();
+ getEndpoint().connect(this);
+ }
+
+ @Override
+ public void stop() throws Exception {
+ getEndpoint().disconnect(this);
+ super.stop();
+ }
+
+ @Override
+ public WsEndpoint getEndpoint() {
+ return (WsEndpoint) super.getEndpoint();
+ }
+
+ public void sendMessage(String message) {
+ sendMessageInternal(message);
+ }
+
+ public void sendMessage(byte[] message) {
+ sendMessageInternal(message);
+ }
+
+ public void sendMessage(InputStream message) {
+ sendMessageInternal(message);
+ }
+
+ public void sendMessage(Reader message) {
+ sendMessageInternal(message);
+ }
+
+ private void sendMessageInternal(Object message) {
+ final Exchange exchange = getEndpoint().createExchange();
+
+ //TODO may set some headers with some meta info (e.g., socket info, unique-id for correlation purpose, etc0
+ // set the body
+ exchange.getIn().setBody(message);
+
+ // send exchange using the async routing engine
+ getAsyncProcessor().process(exchange, new AsyncCallback() {
+ public void done(boolean doneSync) {
+ if (exchange.getException() != null) {
+ getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
+ }
+ }
+ });
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsEndpoint.java b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsEndpoint.java
new file mode 100644
index 0000000..7a66432
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsEndpoint.java
@@ -0,0 +1,246 @@
+/**
+ * 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.ahc.ws;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.CharArrayReader;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
+import com.ning.http.client.AsyncHttpClient;
+import com.ning.http.client.AsyncHttpClientConfig;
+import com.ning.http.client.AsyncHttpProvider;
+import com.ning.http.client.providers.grizzly.GrizzlyAsyncHttpProvider;
+import com.ning.http.client.websocket.WebSocket;
+import com.ning.http.client.websocket.WebSocketByteListener;
+import com.ning.http.client.websocket.WebSocketTextListener;
+import com.ning.http.client.websocket.WebSocketUpgradeHandler;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.ahc.AhcEndpoint;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class WsEndpoint extends AhcEndpoint {
+ private static final transient Logger LOG = LoggerFactory.getLogger(WsEndpoint.class);
+
+ // for using websocket streaming/fragments
+ private static final boolean GRIZZLY_AVAILABLE =
+ probeClass("com.ning.http.client.providers.grizzly.GrizzlyAsyncHttpProvider");
+
+ private WebSocket websocket;
+ private Set<WsConsumer> consumers;
+ private boolean useStreaming;
+
+ private static boolean probeClass(String name) {
+ try {
+ Class.forName(name, true, WsEndpoint.class.getClassLoader());
+ return true;
+ } catch (Throwable t) {
+ return false;
+ }
+ }
+
+ public WsEndpoint(String endpointUri, WsComponent component) {
+ super(endpointUri, component, null);
+ this.consumers = new HashSet<WsConsumer>();
+ }
+
+ @Override
+ public WsComponent getComponent() {
+ return (WsComponent) super.getComponent();
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ return new WsProducer(this);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ return new WsConsumer(this, processor);
+ }
+
+ WebSocket getWebSocket() {
+ synchronized (this) {
+ if (websocket == null) {
+ try {
+ connect();
+ } catch (Exception e) {
+ LOG.error("Failed to connect", e);
+ }
+ }
+ }
+ return websocket;
+ }
+
+ void setWebSocket(WebSocket websocket) {
+ this.websocket = websocket;
+ }
+
+ /**
+ * @return the useStreaming
+ */
+ public boolean isUseStreaming() {
+ return useStreaming;
+ }
+
+ /**
+ * @param useStreaming the useStreaming to set
+ */
+ public void setUseStreaming(boolean useStreaming) {
+ this.useStreaming = useStreaming;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.camel.component.ahc.AhcEndpoint#createClient(com.ning.http.client.AsyncHttpClientConfig)
+ */
+ @Override
+ protected AsyncHttpClient createClient(AsyncHttpClientConfig config) {
+ AsyncHttpClient client;
+ if (config == null) {
+ config = new AsyncHttpClientConfig.Builder().build();
+ }
+ AsyncHttpProvider ahp = getAsyncHttpProvider(config);
+ if (ahp == null) {
+ client = new AsyncHttpClient(config);
+ } else {
+ client = new AsyncHttpClient(ahp, config);
+ }
+ return client;
+ }
+
+ public void connect() throws InterruptedException, ExecutionException, IOException {
+ websocket = getClient().prepareGet(getHttpUri().toASCIIString()).execute(
+ new WebSocketUpgradeHandler.Builder()
+ .addWebSocketListener(new WsListener()).build()).get();
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ if (websocket != null && websocket.isOpen()) {
+ websocket.close();
+ }
+ super.doStop();
+ }
+
+ void connect(WsConsumer wsConsumer) {
+ consumers.add(wsConsumer);
+ }
+
+ void disconnect(WsConsumer wsConsumer) {
+ consumers.remove(wsConsumer);
+ }
+
+ class WsListener implements WebSocketTextListener, WebSocketByteListener {
+ private ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
+ private StringBuffer textBuffer = new StringBuffer();
+
+ @Override
+ public void onOpen(WebSocket websocket) {
+ LOG.info("websocket opened");
+ }
+
+ @Override
+ public void onClose(WebSocket websocket) {
+ LOG.info("websocket closed");
+ }
+
+ @Override
+ public void onError(Throwable t) {
+ LOG.error("websocket on error", t);
+ }
+
+ @Override
+ public void onMessage(byte[] message) {
+ LOG.info("received message --> {}", message);
+ for (WsConsumer consumer : consumers) {
+ consumer.sendMessage(message);
+ }
+ }
+
+ @Override
+ public void onFragment(byte[] fragment, boolean last) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("received fragment({}) --> {}", last, fragment);
+ }
+ // for now, construct a memory based stream. In future, we provide a fragmented stream that can
+ // be consumed before the final fragment is added.
+ synchronized (byteBuffer) {
+ try {
+ byteBuffer.write(fragment);
+ } catch (IOException e) {
+ //ignore
+ }
+ if (last) {
+ //REVIST avoid using baos/bais that waste memory
+ byte[] msg = byteBuffer.toByteArray();
+ for (WsConsumer consumer : consumers) {
+ consumer.sendMessage(new ByteArrayInputStream(msg));
+ }
+ byteBuffer.reset();
+ }
+ }
+ }
+
+
+ @Override
+ public void onMessage(String message) {
+ LOG.info("received message --> {}", message);
+ for (WsConsumer consumer : consumers) {
+ consumer.sendMessage(message);
+ }
+ }
+
+ @Override
+ public void onFragment(String fragment, boolean last) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info("received fragment({}) --> {}", last, fragment);
+ }
+ // for now, construct a memory based stream. In future, we provide a fragmented stream that can
+ // be consumed before the final fragment is added.
+ synchronized (textBuffer) {
+ textBuffer.append(fragment);
+ if (last) {
+ //REVIST avoid using sb/car that waste memory
+ char[] msg = new char[textBuffer.length()];
+ textBuffer.getChars(0, msg.length, msg, 0);
+ for (WsConsumer consumer : consumers) {
+ consumer.sendMessage(new CharArrayReader(msg));
+ }
+ textBuffer.setLength(0);
+ }
+ }
+ }
+
+ }
+
+ protected AsyncHttpProvider getAsyncHttpProvider(AsyncHttpClientConfig config) {
+ if (GRIZZLY_AVAILABLE) {
+ return new GrizzlyAsyncHttpProvider(config);
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsProducer.java b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsProducer.java
new file mode 100644
index 0000000..3503530
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/java/org/apache/camel/component/ahc/ws/WsProducer.java
@@ -0,0 +1,138 @@
+/**
+ * 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.ahc.ws;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.impl.DefaultProducer;
+
+import com.ning.http.client.websocket.WebSocket;
+
+/**
+ *
+ */
+public class WsProducer extends DefaultProducer {
+ private static final int DEFAULT_STREAM_BUFFER_SIZE = 127;
+
+ private int streamBufferSize = DEFAULT_STREAM_BUFFER_SIZE;
+
+ public WsProducer(WsEndpoint endpoint) {
+ super(endpoint);
+ }
+
+ @Override
+ public WsEndpoint getEndpoint() {
+ return (WsEndpoint) super.getEndpoint();
+ }
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ Message in = exchange.getIn();
+ Object message = in.getBody();
+ log.debug("Sending out {}", message);
+ if (message != null) {
+ if (message instanceof String) {
+ sendMessage(getWebSocket(), (String)message, ((WsEndpoint)getEndpoint()).isUseStreaming());
+ } else if (message instanceof byte[]) {
+ sendMessage(getWebSocket(), (byte[])message, ((WsEndpoint)getEndpoint()).isUseStreaming());
+ } else if (message instanceof InputStream) {
+ sendStreamMessage(getWebSocket(), (InputStream)message);
+ } else {
+ //TODO provide other binding option, for now use the converted string
+ getWebSocket().sendTextMessage(in.getMandatoryBody(String.class));
+ }
+ }
+ }
+
+ private void sendMessage(WebSocket webSocket, String msg, boolean streaming) {
+ if (streaming) {
+ int p = 0;
+ while (p < msg.length()) {
+ if (msg.length() - p < streamBufferSize) {
+ webSocket.streamText(msg.substring(p), true);
+ p = msg.length();
+ } else {
+ webSocket.streamText(msg.substring(p, streamBufferSize), false);
+ p += streamBufferSize;
+ }
+ }
+ } else {
+ webSocket.sendTextMessage(msg);
+ }
+ }
+
+ private void sendMessage(WebSocket webSocket, byte[] msg, boolean streaming) {
+ if (streaming) {
+ int p = 0;
+ byte[] writebuf = new byte[streamBufferSize];
+ while (p < msg.length) {
+ if (msg.length - p < streamBufferSize) {
+ int rest = msg.length - p;
+ // bug in grizzly? we need to create a byte array with the exact length
+ //webSocket.stream(msg, p, rest, true);
+ System.arraycopy(msg, p, writebuf, 0, rest);
+ byte[] tmpbuf = new byte[rest];
+ System.arraycopy(writebuf, 0, tmpbuf, 0, rest);
+ webSocket.stream(tmpbuf, 0, rest, true);
+ // ends
+ p = msg.length;
+ } else {
+ // bug in grizzly? we need to create a byte array with the exact length
+ //webSocket.stream(msg, p, streamBufferSize, false);
+ System.arraycopy(msg, p, writebuf, 0, streamBufferSize);
+ webSocket.stream(writebuf, 0, streamBufferSize, false);
+ // ends
+ p += streamBufferSize;
+ }
+ }
+ } else {
+ webSocket.sendMessage(msg);
+ }
+ }
+
+ private void sendStreamMessage(WebSocket webSocket, InputStream in) throws IOException {
+ byte[] readbuf = new byte[streamBufferSize];
+ byte[] writebuf = new byte[streamBufferSize];
+ int rn = 0;
+ int wn = 0;
+ try {
+ while ((rn = in.read(readbuf, 0, readbuf.length)) != -1) {
+ if (wn > 0) {
+ webSocket.stream(writebuf, 0, writebuf.length, false);
+ }
+ System.arraycopy(readbuf, 0, writebuf, 0, rn);
+ wn = rn;
+ }
+ // a bug in grizzly? we need to create a byte array with the exact length
+ if (wn < writebuf.length) {
+ byte[] tmpbuf = writebuf;
+ writebuf = new byte[wn];
+ System.arraycopy(tmpbuf, 0, writebuf, 0, wn);
+ } // ends
+ webSocket.stream(writebuf, 0, wn, true);
+ } finally {
+ in.close();
+ }
+ }
+
+ private WebSocket getWebSocket() {
+ return ((WsEndpoint)getEndpoint()).getWebSocket();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/resources/META-INF/LICENSE.txt b/components/camel-ahc-ws/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/resources/META-INF/NOTICE.txt b/components/camel-ahc-ws/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-ws
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-ws b/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-ws
new file mode 100644
index 0000000..60c0ec7
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-ws
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.ahc.ws.WsComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-wss
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-wss b/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-wss
new file mode 100644
index 0000000..60c0ec7
--- /dev/null
+++ b/components/camel-ahc-ws/src/main/resources/META-INF/services/org/apache/camel/component/ahc-wss
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.ahc.ws.WsComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/TestServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/TestServlet.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/TestServlet.java
new file mode 100644
index 0000000..9a4347a
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/TestServlet.java
@@ -0,0 +1,105 @@
+package org.apache.camel.component.ahc.ws;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.eclipse.jetty.websocket.WebSocket;
+import org.eclipse.jetty.websocket.WebSocketServlet;
+
+public class TestServlet extends WebSocketServlet {
+ private static final byte OPCODE_CONTINUATION = 0x00;
+ private static final byte OPCODE_TEXT = 0x01;
+ private static final byte OPCODE_BINARY = 0x02;
+ private static final byte FLAGS_FINAL = 0x08;
+
+ private static final long serialVersionUID = 1L;
+
+ private List<Object> messages;
+
+ public TestServlet(List<Object> messages) {
+ this.messages = messages;
+ }
+
+ @Override
+ public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
+ return new TestWsSocket();
+ }
+
+ private class TestWsSocket implements WebSocket.OnTextMessage, WebSocket.OnBinaryMessage,
+ WebSocket.OnFrame {
+ protected Connection con;
+ protected ByteArrayOutputStream frameBuffer = new ByteArrayOutputStream();
+
+ @Override
+ public void onOpen(Connection connection) {
+ con = connection;
+ }
+
+ @Override
+ public void onClose(int i, String s) {
+ }
+
+ @Override
+ public void onMessage(String data) {
+ try {
+ messages.add(data);
+ con.sendMessage(data);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onMessage(byte[] data, int offset, int length) {
+ try {
+ if (length < data.length) {
+ byte[] odata = data;
+ data = new byte[length];
+ System.arraycopy(odata, offset, data, 0, length);
+ offset = 0;
+ }
+ messages.add(data);
+ con.sendMessage(data, offset, length);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ public void onMessage(byte[] data, int offset, int length, boolean last) {
+ frameBuffer.write(data, offset, length);
+ if (last) {
+ data = frameBuffer.toByteArray();
+ frameBuffer.reset();
+ messages.add(data);
+ try {
+ con.sendMessage(data, 0, data.length);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ @Override
+ public boolean onFrame(byte flags, byte opcode, byte[] data, int offset, int length) {
+ if (OPCODE_TEXT == opcode || OPCODE_BINARY == opcode) {
+ if (0 != (FLAGS_FINAL & flags)) {
+ // a non-framed text or binary
+ return false;
+ }
+ onMessage(data, offset, length, false);
+ return true;
+ } else if (OPCODE_CONTINUATION == opcode) {
+ boolean f = 0 != (FLAGS_FINAL & flags);
+ onMessage(data, offset, length, f);
+ return !f;
+ }
+ return false;
+ }
+
+ @Override
+ public void onHandshake(FrameConnection connection) {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java
new file mode 100644
index 0000000..efefa1f
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerConsumerTest.java
@@ -0,0 +1,97 @@
+/**
+ *
+ */
+package org.apache.camel.component.ahc.ws;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class WsProducerConsumerTest extends CamelTestSupport {
+ protected static final String TEST_MESSAGE = "Hello World!";
+
+ protected Server server;
+ protected int PORT = AvailablePortFinder.getNextAvailable();
+ protected List<Object> messages;
+
+ public void startTestServer() throws Exception {
+ // start a simple websocket echo service
+ server = new Server();
+ Connector connector = new SelectChannelConnector();
+ connector.setHost("localhost");
+ connector.setPort(PORT);
+ server.addConnector(connector);
+
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/");
+ server.setHandler(context);
+
+ messages = new ArrayList<Object>();
+ ServletHolder servletHolder = new ServletHolder(new TestServlet(messages));
+ context.addServlet(servletHolder, "/*");
+
+ server.start();
+ System.out.println("started");
+ assertTrue(server.isStarted());
+
+ }
+
+ public void stopTestServer() throws Exception {
+ server.stop();
+ server.destroy();
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ startTestServer();
+ super.setUp();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ stopTestServer();
+ }
+
+ @Test
+ public void testTwoRoutes() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived(TEST_MESSAGE);
+
+ template.sendBody("direct:input", TEST_MESSAGE);
+
+ mock.assertIsSatisfied();
+ }
+
+
+ @Override
+ protected RouteBuilder[] createRouteBuilders() throws Exception {
+ RouteBuilder[] rbs = new RouteBuilder[2];
+ rbs[0] = new RouteBuilder() {
+ public void configure() {
+ from("direct:input")
+ .to("ahc-ws://localhost:" + PORT);
+ }
+ };
+ rbs[1] = new RouteBuilder() {
+ public void configure() {
+ from("ahc-ws://localhost:" + PORT)
+ .to("mock:result");
+ }
+ };
+ return rbs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTest.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTest.java
new file mode 100644
index 0000000..3a69f59
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.ahc.ws;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+
+/**
+ * @version
+ */
+public class WsProducerTest extends WsProducerTestBase {
+
+ @Override
+ protected void setUpComponent() throws Exception {
+ }
+
+ @Override
+ protected Connector getConnector() throws Exception {
+ return new SelectChannelConnector();
+ }
+
+ @Override
+ protected String getTargetURL() {
+ return "ahc-ws://localhost:" + PORT;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java
new file mode 100644
index 0000000..06ae0c3
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerTestBase.java
@@ -0,0 +1,217 @@
+/**
+ * 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.ahc.ws;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.test.AvailablePortFinder;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public abstract class WsProducerTestBase extends Assert {
+
+ protected static final String TEST_MESSAGE = "Hello World!";
+
+ protected CamelContext camelContext;
+ protected ProducerTemplate template;
+ protected Server server;
+ protected int PORT = AvailablePortFinder.getNextAvailable();
+ protected List<Object> messages;
+
+ public void startTestServer() throws Exception {
+ // start a simple websocket echo service
+ server = new Server();
+ Connector connector = getConnector();
+ connector.setHost("localhost");
+ connector.setPort(PORT);
+ server.addConnector(connector);
+
+ ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
+ context.setContextPath("/");
+ server.setHandler(context);
+
+ messages = new ArrayList<Object>();
+ server.setHandler(context);
+ ServletHolder servletHolder = new ServletHolder(new TestServlet(messages));
+ context.addServlet(servletHolder, "/*");
+
+ server.start();
+ assertTrue(server.isStarted());
+
+ }
+
+ public void stopTestServer() throws Exception {
+ server.stop();
+ server.destroy();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ startTestServer();
+
+ camelContext = new DefaultCamelContext();
+ camelContext.start();
+
+ setUpComponent();
+ template = camelContext.createProducerTemplate();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ template.stop();
+ camelContext.stop();
+
+ stopTestServer();
+ }
+
+ protected abstract void setUpComponent() throws Exception;
+
+ protected abstract Connector getConnector() throws Exception;
+
+ protected abstract String getTargetURL();
+
+ protected String getTextTestMessage() {
+ return TEST_MESSAGE;
+ }
+
+ protected byte[] getByteTestMessage() throws UnsupportedEncodingException {
+ return TEST_MESSAGE.getBytes("utf-8");
+ }
+
+ @Test
+ public void testWriteToWebsocket() throws Exception {
+ String testMessage = getTextTestMessage();
+ testWriteToWebsocket(testMessage);
+ assertEquals(1, messages.size());
+ verifyMessage(testMessage, messages.get(0));
+ }
+
+ @Test
+ public void testWriteBytesToWebsocket() throws Exception {
+ byte[] testMessageBytes = getByteTestMessage();
+ testWriteToWebsocket(testMessageBytes);
+ assertEquals(1, messages.size());
+ verifyMessage(testMessageBytes, messages.get(0));
+ }
+
+ @Test
+ public void testWriteStreamToWebsocket() throws Exception {
+ byte[] testMessageBytes = createLongByteTestMessage();
+ testWriteToWebsocket(new ByteArrayInputStream(testMessageBytes));
+ assertEquals(1, messages.size());
+ verifyMessage(testMessageBytes, messages.get(0));
+ }
+
+ private void testWriteToWebsocket(Object message) throws Exception {
+ Exchange exchange = sendMessage(getTargetURL(), message);
+ assertNull(exchange.getException());
+
+ long towait = 5000;
+ while (towait > 0) {
+ if (messages.size() == 1) {
+ break;
+ }
+ towait -= 500;
+ Thread.sleep(500);
+ }
+ }
+
+ private Exchange sendMessage(String endpointUri, final Object msg) {
+ Exchange exchange = template.request(endpointUri, new Processor() {
+ public void process(final Exchange exchange) {
+ exchange.getIn().setBody(msg);
+ }
+ });
+ return exchange;
+
+ }
+
+ private void verifyMessage(Object original, Object result) {
+ if (original instanceof String && result instanceof String) {
+ assertEquals(original, result);
+ } else if (original instanceof byte[] && result instanceof byte[]) {
+ // use string-equals as our bytes are string'able
+ assertEquals(new String((byte[])original), new String((byte[])result));
+ } else if (original instanceof InputStream) {
+ assertTrue(result instanceof byte[] || result instanceof InputStream);
+ if (result instanceof byte[]) {
+ result = new ByteArrayInputStream((byte[])result);
+ }
+ try {
+ int oc = 0;
+ int or = 0;
+ while (oc != -1) {
+ oc = ((InputStream)original).read();
+ or = ((InputStream)result).read();
+ assertEquals(oc, or);
+ }
+ assertEquals(-1, or);
+ } catch (Exception e) {
+ fail("unable to verify data: " + e);
+ }
+ } else {
+ fail("unexpected message type for input " + original + ": " + result);
+ }
+ }
+
+ protected byte[] createLongByteTestMessage() {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ byte[] bs = TEST_MESSAGE.getBytes();
+ try {
+ for (int i = 1; i <= 100; i++) {
+ baos.write(Integer.toString(i).getBytes());
+ baos.write(0x20);
+ baos.write(bs);
+ baos.write(';');
+ }
+ } catch (IOException e) {
+ // ignore
+ }
+ return baos.toByteArray();
+ }
+
+ protected String createLongTextTestMessage() throws Exception {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 1; i <= 100; i++) {
+ sb.append(Integer.toString(i));
+ sb.append(' ');
+ sb.append(TEST_MESSAGE);
+ sb.append(';');
+ }
+ return sb.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerUsingStreamingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerUsingStreamingTest.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerUsingStreamingTest.java
new file mode 100644
index 0000000..5da4891
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WsProducerUsingStreamingTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.ahc.ws;
+
+import java.io.UnsupportedEncodingException;
+
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.nio.SelectChannelConnector;
+
+/**
+ * @version
+ */
+public class WsProducerUsingStreamingTest extends WsProducerTestBase {
+
+ @Override
+ protected void setUpComponent() throws Exception {
+ }
+
+ @Override
+ protected Connector getConnector() throws Exception {
+ return new SelectChannelConnector();
+ }
+
+ @Override
+ protected String getTextTestMessage() {
+ return super.getTextTestMessage();
+ }
+
+ @Override
+ protected byte[] getByteTestMessage() throws UnsupportedEncodingException {
+ return createLongByteTestMessage();
+ }
+
+ @Override
+ protected String getTargetURL() {
+ return "ahc-ws://localhost:" + PORT + "?useStreaming=true";
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java
new file mode 100644
index 0000000..60ff7de
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/java/org/apache/camel/component/ahc/ws/WssProducerTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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.ahc.ws;
+
+import org.apache.camel.component.ahc.ws.WsComponent;
+import org.apache.camel.util.jsse.ClientAuthentication;
+import org.apache.camel.util.jsse.KeyManagersParameters;
+import org.apache.camel.util.jsse.KeyStoreParameters;
+import org.apache.camel.util.jsse.SSLContextParameters;
+import org.apache.camel.util.jsse.SSLContextServerParameters;
+import org.apache.camel.util.jsse.TrustManagersParameters;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.ssl.SslSelectChannelConnector;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
+
+/**
+ */
+public class WssProducerTest extends WsProducerTestBase {
+ protected static final String PW = "changeit";
+
+ @Override
+ protected Connector getConnector() throws Exception {
+ SslContextFactory sslContextFactory = new SslContextFactory();
+ sslContextFactory.setSslContext(defineSSLContextServerParameters().createSSLContext());
+ return new SslSelectChannelConnector(sslContextFactory);
+ }
+
+ @Override
+ protected String getTargetURL() {
+ return "ahc-wss://localhost:" + PORT;
+ }
+
+ @Override
+ protected void setUpComponent() throws Exception {
+ WsComponent wsComponent = (WsComponent) camelContext.getComponent("ahc-wss");
+ wsComponent.setSslContextParameters(defineSSLContextClientParameters());
+ }
+
+ private static SSLContextParameters defineSSLContextServerParameters() {
+
+ KeyStoreParameters ksp = new KeyStoreParameters();
+ ksp.setResource("jsse/localhost.ks");
+ ksp.setPassword(PW);
+
+ KeyManagersParameters kmp = new KeyManagersParameters();
+ kmp.setKeyPassword(PW);
+ kmp.setKeyStore(ksp);
+
+ TrustManagersParameters tmp = new TrustManagersParameters();
+ tmp.setKeyStore(ksp);
+
+ // NOTE: Needed since the client uses a loose trust configuration when no ssl context
+ // is provided. We turn on WANT client-auth to prefer using authentication
+ SSLContextServerParameters scsp = new SSLContextServerParameters();
+ scsp.setClientAuthentication(ClientAuthentication.WANT.name());
+
+ SSLContextParameters sslContextParameters = new SSLContextParameters();
+ sslContextParameters.setKeyManagers(kmp);
+ sslContextParameters.setTrustManagers(tmp);
+ sslContextParameters.setServerParameters(scsp);
+
+ return sslContextParameters;
+ }
+
+ private static SSLContextParameters defineSSLContextClientParameters() {
+ KeyStoreParameters ksp = new KeyStoreParameters();
+ ksp.setResource("jsse/localhost.ks");
+ ksp.setPassword(PW);
+
+ TrustManagersParameters tmp = new TrustManagersParameters();
+ tmp.setKeyStore(ksp);
+
+ SSLContextParameters sslContextParameters = new SSLContextParameters();
+ sslContextParameters.setTrustManagers(tmp);
+
+ return sslContextParameters;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/resources/jsse/localhost.ks
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/resources/jsse/localhost.ks b/components/camel-ahc-ws/src/test/resources/jsse/localhost.ks
new file mode 100644
index 0000000..f285418
Binary files /dev/null and b/components/camel-ahc-ws/src/test/resources/jsse/localhost.ks differ
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ahc-ws/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/components/camel-ahc-ws/src/test/resources/log4j.properties b/components/camel-ahc-ws/src/test/resources/log4j.properties
new file mode 100644
index 0000000..89fc1bd
--- /dev/null
+++ b/components/camel-ahc-ws/src/test/resources/log4j.properties
@@ -0,0 +1,43 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for testing.
+#
+log4j.rootLogger=INFO, file
+
+# uncomment the following to enable camel debugging
+#log4j.logger.org.apache.camel.component.ahc=TRACE
+#log4j.logger.org.apache.camel.util.jsse=DEBUG
+#log4j.logger.com.ning=TRACE
+
+# CONSOLE appender not used by default
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+# MDC
+#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camelexchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n
+
+# File appender
+log4j.appender.file=org.apache.log4j.FileAppender
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.file=target/camel-ahc-test.log
+log4j.appender.file.append=true
+log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+# MDC
+#log4j.appender.file.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %-10.10X{camel.breadcrumbId} - %-10.10X{camel.exchangeId} - %-10.10X{camel.correlationId} - %-10.10X{camel.routeId} - %m%n
+
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ws/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-ws/pom.xml b/components/camel-ws/pom.xml
deleted file mode 100644
index a5b7b41..0000000
--- a/components/camel-ws/pom.xml
+++ /dev/null
@@ -1,87 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.14-SNAPSHOT</version>
- </parent>
-
- <artifactId>camel-ws</artifactId>
- <packaging>bundle</packaging>
- <name>Camel :: WS</name>
- <description>Camel Websocket Client support</description>
-
- <properties>
- <camel.osgi.export.pkg>org.apache.camel.component.ws.*</camel.osgi.export.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=ws</camel.osgi.export.service>
- </properties>
-
- <dependencies>
-
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-ahc</artifactId>
- </dependency>
- <dependency>
- <groupId>org.glassfish.grizzly</groupId>
- <artifactId>grizzly-websockets</artifactId>
- <version>2.3.11</version>
- <optional>true</optional>
- </dependency>
-
- <!-- testing -->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
-
- <!-- Jetty for testing-->
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-websocket</artifactId>
- <version>${jetty-version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.eclipse.jetty</groupId>
- <artifactId>jetty-servlet</artifactId>
- <version>${jetty-version}</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsComponent.java b/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsComponent.java
deleted file mode 100644
index e6832d7..0000000
--- a/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsComponent.java
+++ /dev/null
@@ -1,45 +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.ws;
-
-import java.net.URI;
-
-import org.apache.camel.component.ahc.AhcComponent;
-import org.apache.camel.component.ahc.AhcEndpoint;
-
-/**
- * Defines the <a href="http://camel.apache.org/ws.html">WebSocket Client Component</a>
- */
-public class WsComponent extends AhcComponent {
-
- /* (non-Javadoc)
- * @see org.apache.camel.component.ahc.AhcComponent#createAddressUri(java.lang.String, java.lang.String)
- */
- @Override
- protected String createAddressUri(String uri, String remaining) {
- return uri;
- }
-
- /* (non-Javadoc)
- * @see org.apache.camel.component.ahc.AhcComponent#createAhcEndpoint(java.lang.String, org.apache.camel.component.ahc.AhcComponent, java.net.URI)
- */
- @Override
- protected AhcEndpoint createAhcEndpoint(String endpointUri, AhcComponent component, URI httpUri) {
- return new WsEndpoint(endpointUri, (WsComponent)component);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConstants.java b/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConstants.java
deleted file mode 100644
index 621cae5..0000000
--- a/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConstants.java
+++ /dev/null
@@ -1,33 +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.ws;
-
-/**
- *
- */
-public final class WsConstants {
-
- public static final String CONTENT_TYPE_JAVA_SERIALIZED_OBJECT = "application/x-java-serialized-object";
- public static final String CONTENT_TYPE_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";
-
- public static final String WS_PROTOCOL = "ws";
- public static final String WSS_PROTOCOL = "wss";
-
- private WsConstants() {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/0f6f2e32/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConsumer.java b/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConsumer.java
deleted file mode 100644
index c47a04c..0000000
--- a/components/camel-ws/src/main/java/org/apache/camel/component/ws/WsConsumer.java
+++ /dev/null
@@ -1,83 +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.ws;
-
-import java.io.InputStream;
-import java.io.Reader;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.Exchange;
-import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultConsumer;
-
-public class WsConsumer extends DefaultConsumer {
-
- public WsConsumer(WsEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
-
- @Override
- public void start() throws Exception {
- super.start();
- getEndpoint().connect(this);
- }
-
- @Override
- public void stop() throws Exception {
- getEndpoint().disconnect(this);
- super.stop();
- }
-
- @Override
- public WsEndpoint getEndpoint() {
- return (WsEndpoint) super.getEndpoint();
- }
-
- public void sendMessage(String message) {
- sendMessageInternal(message);
- }
-
- public void sendMessage(byte[] message) {
- sendMessageInternal(message);
- }
-
- public void sendMessage(InputStream message) {
- sendMessageInternal(message);
- }
-
- public void sendMessage(Reader message) {
- sendMessageInternal(message);
- }
-
- private void sendMessageInternal(Object message) {
- final Exchange exchange = getEndpoint().createExchange();
-
- //TODO may set some headers with some meta info (e.g., socket info, unique-id for correlation purpose, etc0
- // set the body
- exchange.getIn().setBody(message);
-
- // send exchange using the async routing engine
- getAsyncProcessor().process(exchange, new AsyncCallback() {
- public void done(boolean doneSync) {
- if (exchange.getException() != null) {
- getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
- }
- }
- });
- }
-
-}