2

Library in use: AsyncHtpClient Library: Version : 1.9.32 Location: https://github.com/AsyncHttpClient/async-http-client

Netty Version : 3.10.3.Final

Proxy: Squid Proxy

I am trying to create a websocket connection using AsyncHttpClinet library. It works fine when using without the proxy. But when I start a proxy and pass in the Host, port, username and password , I am unable to create a websocket connection.

It get a stack trace which says Invalid Status Code 400:

Caused by: java.lang.IllegalStateException: Invalid Status Code 400
    at com.ning.http.client.ws.WebSocketUpgradeHandler.onCompleted(WebSocketUpgradeHandler.java:76)
    at com.ning.http.client.ws.WebSocketUpgradeHandler.onCompleted(WebSocketUpgradeHandler.java:29)
    at com.ning.http.client.providers.netty.future.NettyResponseFuture.getContent(NettyResponseFuture.java:177)
    at com.ning.http.client.providers.netty.future.NettyResponseFuture.done(NettyResponseFuture.java:214)
    ... 35 more

I am setting the proxy object like this:

ProxyServer ps = new ProxyServer("host-name",portNo,"user_name","password");

AsyncHttpClientConfig cf = new AsyncHttpClientConfig.Builder().setProxyServer(ps).build();
WebSocket websocket = c.prepareGet(url) 
                .execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener( 
                        new WebSocketTextListener() { 
                            @Override 
                            public void onMessage(String message) { 

                            } 

                            @Override 
                            public void onFragment(String s, boolean b) { 
                            } 

                            @Override 
                            public void onOpen(WebSocket websocket) { 
                            } 

                            @Override 
                            public void onClose(WebSocket websocket) { 
                            } 

                            @Override 
                            public void onError(Throwable t) { 
                            } 
                        } 

                ).build() 
                ).get(); 

Are there any other steps to configure a proxy for websocket connections?

I have also tried configuring the ProxyServer object like this:

ProxyServer ps = new ProxyServer(ProxyServer.Protocol.HTTPS,"host-name",portNo,"user_name","password");
Sudhanshu
  • 421
  • 2
  • 6
  • 15
  • Which version do you use? Did you try with latest 2.0.0-RC7? – Stephane Landelle Jan 25 '16 at 21:39
  • @StephaneLandelle No, I tried with 1.9.32. (Updated the question to reflect that) I can try with the 2.0.0-RC7 and report back. In the meantime any guesses why this could be? – Sudhanshu Jan 25 '16 at 21:46
  • A guess? Yeah, a bug... – Stephane Landelle Jan 25 '16 at 21:48
  • @StephaneLandelle, I am new to Maven, but Using this in the POM file deons't recognize the latest version: com.ning async-http-client-project 2.0.0-RC7 I guess it's not up on Maven yet. I will try with adding as a Jar. – Sudhanshu Jan 25 '16 at 21:51
  • 1
    Wrong groupId and artifactId: http://search.maven.org/#artifactdetails%7Corg.asynchttpclient%7Casync-http-client%7C2.0.0-RC7%7Cjar – Stephane Landelle Jan 25 '16 at 21:53
  • @StephaneLandelle, thanks for your help with this. I have the dependency imported, but it does look like the class hierarchy has changed. My previous code isn't compatible with the new changes. I will read up and update. – Sudhanshu Jan 25 '16 at 22:16
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/101684/discussion-between-sudhanshu-and-stephane-landelle). – Sudhanshu Jan 26 '16 at 14:06

0 Answers0