apache camel jetty websocket java.net.BindException

huangapple go评论76阅读模式
英文:

apache camel jetty websocket java.net.BindException

问题

以下是您提供的内容的中文翻译:

我尝试使用Apache Camel Jetty Websocket Component连接到一个WebSocket。
WebSocket的URL是:wss://echo.websocket.org

我遇到了以下错误:

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]

我还没有真正理解他是如何在ws和wss之间进行选择的,我尝试使用自签名的sslContextParameters。

以下是我的代码:

@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];
    }
}
英文:

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];
    }





    }

答案1

得分: 1

Jetty WebSocket组件(以及Atmosphere WebSocket组件)旨在公开新的WebSocket服务器。如果您需要作为客户端连接到远程WebSocket服务器,则应使用AHC WebSocket组件

> AHC-WS组件为客户端提供基于WebSocket的端点,用于与外部服务器通过WebSocket进行通信(作为客户端打开与外部服务器的WebSocket连接)。

英文:

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).

huangapple
  • 本文由 发表于 2020年7月26日 19:27:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/63099494.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定