Reputation: 1336
I try to connect a websocket with Apache Camel Jetty Websocket Component
The Websocket's url is : wss://echo.websocket.org
I'am stuck with this error :
org.apache.camel.RuntimeCamelException: MultiException[java.io.IOException: Failed to bind to echo.websocket.org/174.129.224.73:443, java.io.IOException: Failed to bind to echo.websocket.org/174.129.224.73:443]
I havent really understand how he choose between ws and wss , i Try to put a self signed sslContextParameters/
Here si my code :
@Configuration
public class EipConfiguration extends RouteBuilder {
@Override
public void configure() {
CamelContext context = new DefaultCamelContext();
String server = "echo.websocket.org";
int port = 443;
String uri = "websocket://"+server+":"+port+"/?sslContextParameters=#sslContextParameters";
from(uri)
.log(">>> Message received from WebSocket Client : ${body}");
}
@Bean(name = "sslContextParameters")
public SSLContextParameters sslContextParameters() throws Exception {
TrustManagersParameters trustManagersParameters = new TrustManagersParameters();
X509ExtendedTrustManager extendedTrustManager = new InsecureX509TrustManager();
trustManagersParameters.setTrustManager(extendedTrustManager);
SSLContextParameters sslContextParameters = new SSLContextParameters();
sslContextParameters.setTrustManagers(trustManagersParameters);
return sslContextParameters;
}
}
InsecureX509TrustManager
public class InsecureX509TrustManager extends X509ExtendedTrustManager {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
//Do nothing
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s, Socket socket) throws CertificateException {
//Do nothing
}
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
//Do nothing
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s, SSLEngine sslEngine) throws CertificateException {
//Do nothing
}
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
//Do nothing
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
//Do nothing
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
}
Upvotes: 0
Views: 575
Reputation: 4929
Jetty WebSocket Component (and Atmosphere WebSocket component) is intended to expose new WebSocket server. If you need to connect as client to remote WebSocket server, you should use AHC Websocket component
The AHC-WS component provides Websocket based endpoints for a client communicating with external servers over Websocket (as a client opening a websocket connection to an external server).
Upvotes: 1