[
https://issues.apache.org/jira/browse/CAMEL-12005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16288965#comment-16288965
]
ASF GitHub Bot commented on CAMEL-12005:
----------------------------------------
davsclaus commented on a change in pull request #2144: CAMEL-12005: Add
websocket support to camel-undertow
URL: https://github.com/apache/camel/pull/2144#discussion_r156602166
##########
File path:
components/camel-undertow/src/test/java/org/apache/camel/component/undertow/ws/UndertowWssRouteTest.java
##########
@@ -0,0 +1,176 @@
+/**
+ * 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.undertow.ws;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.ssl.SslProvider;
+import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.SSLContextParametersAware;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.component.undertow.UndertowHttpsSpringTest;
+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.asynchttpclient.AsyncHttpClient;
+import org.asynchttpclient.AsyncHttpClientConfig;
+import org.asynchttpclient.DefaultAsyncHttpClient;
+import org.asynchttpclient.DefaultAsyncHttpClientConfig;
+import org.asynchttpclient.ws.WebSocket;
+import org.asynchttpclient.ws.WebSocketTextListener;
+import org.asynchttpclient.ws.WebSocketUpgradeHandler;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class UndertowWssRouteTest extends BaseUndertowTest {
+
+ @BeforeClass
+ public static void setUpJaas() throws Exception {
+ URL trustStoreUrl =
UndertowHttpsSpringTest.class.getClassLoader().getResource("ssl/keystore.jks");
+ System.setProperty("javax.net.ssl.trustStore",
trustStoreUrl.toURI().getPath());
+ }
+
+ @AfterClass
+ public static void tearDownJaas() throws Exception {
+ System.clearProperty("java.security.auth.login.config");
+ }
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+ KeyStoreParameters ksp = new KeyStoreParameters();
+ ksp.setResource("ssl/keystore.jks");
+ ksp.setPassword("password");
+
+ KeyManagersParameters kmp = new KeyManagersParameters();
+ kmp.setKeyPassword("password");
+ 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();
+
+ SSLContextParameters sslContextParameters = new SSLContextParameters();
+ sslContextParameters.setKeyManagers(kmp);
+ sslContextParameters.setTrustManagers(tmp);
+ sslContextParameters.setServerParameters(scsp);
+ context.setSSLContextParameters(sslContextParameters);
+
+ ((SSLContextParametersAware)
context.getComponent("undertow")).setUseGlobalSslContextParameters(true);
+ return context;
+ }
+
+ protected AsyncHttpClient createAsyncHttpSSLClient() throws IOException,
GeneralSecurityException {
+
+ AsyncHttpClient c;
+ AsyncHttpClientConfig config;
+
+ DefaultAsyncHttpClientConfig.Builder builder =
+ new DefaultAsyncHttpClientConfig.Builder();
+
+ SslContext sslContext = SslContextBuilder
+ .forClient()
+ .sslProvider(SslProvider.JDK)
+ .trustManager(InsecureTrustManagerFactory.INSTANCE)
+ .build();
+ builder.setSslContext(sslContext);
+ builder.setAcceptAnyCertificate(true);
+ config = builder.build();
+ c = new DefaultAsyncHttpClient(config);
+
+ return c;
+ }
+
+ @Test
+ public void testWSHttpCall() throws Exception {
+ final List<String> received = new ArrayList<String>();
+ final CountDownLatch latch = new CountDownLatch(10);
+
+ AsyncHttpClient c = createAsyncHttpSSLClient();
+ WebSocket websocket = c.prepareGet("wss://localhost:" + getPort() +
"/test").execute(
+ new WebSocketUpgradeHandler.Builder()
+ .addWebSocketListener(new WebSocketTextListener() {
+ @Override
+ public void onMessage(String message) {
+ received.add(message);
+ log.info("received --> " + message);
+ latch.countDown();
+ }
Review comment:
Remove all the extra empty lines below
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Add websocket support to camel-undertow
> ---------------------------------------
>
> Key: CAMEL-12005
> URL: https://issues.apache.org/jira/browse/CAMEL-12005
> Project: Camel
> Issue Type: New Feature
> Reporter: Thomas Diesler
> Assignee: Peter Palaga
>
> CrossRef: https://github.com/wildfly-extras/wildfly-camel/issues/2298
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)