WebSocket connection with proxy

Issue #86 closed
jjoannes created an issue

Hi Christian,

Our clients need to access the XMPP server through a proxy with authentication. And I'm facing two issues. The first one is that using:

WebSocketConnectionConfiguration.builder().proxy(proxy) with:
InetSocketAddress socketAddress = new InetSocketAddress(
                "xxx.245.192.7", 8080);
            Proxy proxy = new Proxy(Type.HTTP, socketAddress);

results in a "(JdkClientContainer.java:398) Invalid proxy 'http:///xxx.245.192.7:8080'" (please notice the triple "/").

The second one is that I can't see how to set a proxy login/password. Did I miss something? Or should I use Authenticator.setDefault() or something like that?

Comments (6)

  1. Christian Schudt repo owner

    The third slash is due to some weird (inconstistent) behavior in JDKs toString() implementations. (Happens only when using an IP address, not a hostname).

    As a workaround, try

    InetSocketAddress socketAddress = InetSocketAddress.createUnresolved(
                    "123.245.192.7", 8080);
    

    It's better to use anyway, since the Proxy is only used to carry the host information, but not to resolve it. (it's transferred into an HTTP URI, and used internally by the WebSocket library - Tyrus).

    As far as Proxy authentication is concerned: I've never actually had the ability to test it, but I guess, you could try basic Java HTTP authentication. E.g. with Authenticator, like here: http://stackoverflow.com/q/1626549

    Let me know, if this works.

  2. jjoannes reporter

    Thanks. I'll try to test the authentication method as soon as our infrastructure is operational.

  3. Log in to comment