"请求标头太大"打开WebSocket请求时

时间:2018-02-21 14:21:25

标签: websocket jetty

我将WebSocket客户端连接到具有很长查询参数的URI,如下所示:

WebSocketClient client = new WebSocketClient();
URI uri = getVeryLongUri();
WebSocketListener websocketListener = getEventListener9);
client.connect(websocketListener, uri);

使用Jetty 9.4.8.v20171121我得到:

org.eclipse.jetty.websocket.api.UpgradeException: 0 null
    at org.eclipse.jetty.websocket.client.WebSocketUpgradeRequest.onComplete(WebSocketUpgradeRequest.java:513)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:193)
    at org.eclipse.jetty.client.ResponseNotifier.notifyComplete(ResponseNotifier.java:185)
    at org.eclipse.jetty.client.HttpReceiver.terminateResponse(HttpReceiver.java:459)
    at org.eclipse.jetty.client.HttpReceiver.abort(HttpReceiver.java:540)
    at org.eclipse.jetty.client.HttpChannel.abortResponse(HttpChannel.java:129)
    at org.eclipse.jetty.client.HttpSender.terminateRequest(HttpSender.java:376)
    at org.eclipse.jetty.client.HttpSender.abort(HttpSender.java:561)
    at org.eclipse.jetty.client.HttpSender.anyToFailure(HttpSender.java:345)
    at org.eclipse.jetty.client.HttpSender$CommitCallback.failed(HttpSender.java:712)
    at org.eclipse.jetty.client.http.HttpSenderOverHTTP$HeadersCallback.failed(HttpSenderOverHTTP.java:310)
    at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:245)
    at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:224)
    at org.eclipse.jetty.client.http.HttpSenderOverHTTP.sendHeaders(HttpSenderOverHTTP.java:62)
    at org.eclipse.jetty.client.HttpSender.send(HttpSender.java:207)
    at org.eclipse.jetty.client.http.HttpChannelOverHTTP.send(HttpChannelOverHTTP.java:88)
    at org.eclipse.jetty.client.HttpConnection.send(HttpConnection.java:199)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP$Delegate.send(HttpConnectionOverHTTP.java:254)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.send(HttpConnectionOverHTTP.java:122)
    at org.eclipse.jetty.client.http.HttpDestinationOverHTTP.send(HttpDestinationOverHTTP.java:38)
    at org.eclipse.jetty.client.HttpDestination.process(HttpDestination.java:332)
    at org.eclipse.jetty.client.HttpDestination.process(HttpDestination.java:290)
    at org.eclipse.jetty.client.HttpDestination.send(HttpDestination.java:280)
    at org.eclipse.jetty.client.HttpDestination.succeeded(HttpDestination.java:221)
    at org.eclipse.jetty.client.AbstractConnectionPool.proceed(AbstractConnectionPool.java:138)
    at org.eclipse.jetty.client.AbstractConnectionPool$1.succeeded(AbstractConnectionPool.java:115)
    at org.eclipse.jetty.client.AbstractConnectionPool$1.succeeded(AbstractConnectionPool.java:108)
    at org.eclipse.jetty.util.Promise$Wrapper.succeeded(Promise.java:130)
    at org.eclipse.jetty.client.http.HttpConnectionOverHTTP.onOpen(HttpConnectionOverHTTP.java:130)
    at org.eclipse.jetty.io.ssl.SslConnection.onOpen(SslConnection.java:249)
    at org.eclipse.jetty.io.SelectorManager.connectionOpened(SelectorManager.java:322)
    at org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:213)
    at org.eclipse.jetty.io.ManagedSelector.access$1600(ManagedSelector.java:60)
    at org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:650)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.eclipse.jetty.http.BadMessageException: 500: Request header too large
    at org.eclipse.jetty.http.HttpGenerator.generateRequest(HttpGenerator.java:287)
    at org.eclipse.jetty.client.http.HttpSenderOverHTTP$HeadersCallback.process(HttpSenderOverHTTP.java:231)
    at org.eclipse.jetty.util.IteratingCallback.processing(IteratingCallback.java:241)
    ... 25 common frames omitted
Caused by: java.nio.BufferOverflowException: null
    at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:189)
    at java.nio.ByteBuffer.put(ByteBuffer.java:859)
    at org.eclipse.jetty.http.HttpGenerator.generateRequestLine(HttpGenerator.java:574)
    at org.eclipse.jetty.http.HttpGenerator.generateRequest(HttpGenerator.java:253)
    ... 27 common frames omitted

https://stackoverflow.com/a/22472794/14731提到对于普通的HTTP客户端,必须增加请求缓冲区大小,但似乎并不是WebSocket客户端的等效配置选项。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我明白了。您需要将自定义HttpClient传递给WebSocketClient构造函数。

WebSocketClient client = new WebSocketClient();
client.getHttpClient().setRequestBufferSize(...);