繁体   English   中英

通过squid代理与pusher lib连接

[英]Connect through squid proxy with pusher lib

我必须连接到pusher上托管的websocket,它们提供了一个lib

我设法通过cntlm代理使其在我的开发环境上工作,我的connectionEventListener中有这样的日志

New state for pusher connection: CONNECTING -> CONNECTED

private final ConnectionEventListener connectionEventListener = new ConnectionEventListener() {
    @Override
    public void onConnectionStateChange(ConnectionStateChange connectionStateChange) {
        log.info("New state for pusher connection: {} -> {}",
                connectionStateChange.getPreviousState(),
                connectionStateChange.getCurrentState());
    }

    @Override
    public void onError(String s, String s1, Exception e) {
        log.error("Some error {} - {} - {}", s, s1, e);
    }
};

问题出在我们的预生产环境中,它位于鱿鱼代理(v.3.5.12)的后面,我在日志中得到了它:

New state for pusher connection: DISCONNECTED -> CONNECTING
Exception in thread "Thread-8" java.lang.InternalError: Should not reach here
    at java.net.HttpConnectSocketImpl.doTunneling(HttpConnectSocketImpl.java:181)
    at java.net.HttpConnectSocketImpl.doTunnel(HttpConnectSocketImpl.java:168)
    at java.net.HttpConnectSocketImpl.access$200(HttpConnectSocketImpl.java:44)
    at java.net.HttpConnectSocketImpl$2.run(HttpConnectSocketImpl.java:151)
    at java.net.HttpConnectSocketImpl$2.run(HttpConnectSocketImpl.java:149)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.HttpConnectSocketImpl.privilegedDoTunnel(HttpConnectSocketImpl.java:148)
    at java.net.HttpConnectSocketImpl.connect(HttpConnectSocketImpl.java:111)
    at java.net.Socket.connect(Socket.java:589)
    at com.pusher.java_websocket.client.WebSocketClient.run(WebSocketClient.java:165)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at java.net.HttpConnectSocketImpl.doTunneling(HttpConnectSocketImpl.java:179)
    ... 10 more
Caused by: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 403 Forbidden"
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2084)
    ... 15 more

我的问题是,有人设法从鱿鱼代理后面的java中的pusher中消耗了websocket。

更新:问题已解决,我们的鱿鱼代理缺少一些允许连接的规则。

我最近没有遇到同样的问题,所以我看不出您如何解决该问题。

该URL已在内部鱿鱼代理中列入白名单,但是,当前Pusher Java客户端库实现的问题是(Pusher的java-websocket客户端1.4.1版本),构造函数使用主机地址(ws)创建了InetAddress。 pusherapp.com),导致将网址解析为IP地址。

然后,库尝试使用解析的IP地址打开套接字(使用代理),而不是使用URL地址打开套接字连接。 这对于代理来说是有问题的,因为Pusher使用AWS,并且URL被动态解析为随机的AWS IP地址。

我可以通过在com.pusher.java_websocket.client软件包中修补WebSocketClient.java来更改此行为,如下所示

public void run()方法中,原始行是:

this.socket.connect(new InetSocketAddress(this.uri.getHost(), this.getPort()), this.connectTimeout);

我用this.socket.connect(InetSocketAddress.createUnresolved(this.uri.getHost(), this.uri.getPort()), this.connectTimeout);替换了this.socket.connect(InetSocketAddress.createUnresolved(this.uri.getHost(), this.uri.getPort()), this.connectTimeout);

InetScoketAddress第二个构造函数不使用DNS来解析URL,并且库使用URL地址向Pusher服务器发出请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM