OKHttp原因:java.io.EOFException:\ n未找到:limit = 0 content =…

时间:2018-12-23 11:43:27

标签: okhttp3 undertow

我偶尔会遇到此问题,今天我的网站没有这个问题,当我遇到此问题时,我尝试通过检查我的代码并跟踪问题日志来解决它,甚至尝试 stack-overflow ,答案可能会列出:

    在创建OkHttpClient时
  1. 设置retryOnConnectionFailure(true) 实例。
  2. 设置标题(“连接”,“关闭”)
  3. 设置标头(“接受编码”,“身份”)

但是这些方法都不能解决我的问题,我也尝试使用addNetworkInterceptor代替addInterceptor,但是它无法正常工作。

最后,我尝试返回我的previos版本。好吧,我之前的代码如下:

response.setStatusCode(HttpStatus.UNAUTHORIZED);
return Mono.empty();

现在:

response.setStatusCode(HttpStatus.UNAUTHORIZED);
return response.writeAndFlushWith(Flux.just(Flux.fromStream(
                    Stream.generate(() -> ASRUtil.buildNLUResponse(ResponseEnum.TOKEN_NOT_EXIST))
                            .limit(1)
                            .map(ASRUtil::convertNLU2DataBuffer)
)));

我使用上面的代码只是想提醒客户其令牌无效或不存在。 但是,这似乎是导致问题的原因。

欢迎任何建议。

日志附件:

java.io.IOException: unexpected end of stream on Connection{127.0.0.1:9443, proxy=DIRECT hostAddress=/127.0.0.1:9443 cipherSuite=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA protocol=http/1.1}
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:208) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:88) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
    at com.asr.client.service.WebService.lambda$handlePostASR$3(WebService.java:263) ~[classes/:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121) ~[okhttp-3.11.0.jar:na]
    at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200) ~[okhttp-3.11.0.jar:na]
    at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) [okhttp-3.11.0.jar:na]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_191]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_191]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_191]
Caused by: java.io.EOFException: \n not found: limit=0 content=…
    at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:237) ~[okio-1.14.0.jar:na]
    at okhttp3.internal.http1.Http1Codec.readHeaderLine(Http1Codec.java:215) ~[okhttp-3.11.0.jar:na]
    at okhttp3.internal.http1.Http1Codec.readResponseHeaders(Http1Codec.java:189) ~[okhttp-3.11.0.jar:na]
    ... 22 common frames omitted

错误点:

OkHttpClient httpClient = this.httpClient;
if (null != callBack) {
    OkHttpClient.Builder clientBuilder = httpClient.newBuilder();
    clientBuilder.addInterceptor(chain -> {
        ***Response response = chain.proceed(chain.request());***

0 个答案:

没有答案