GZIP压缩的EofException

发布于 2025-02-01 17:36:46 字数 2565 浏览 2 评论 0原文

我启用了REST API的GZIP压缩,并且在测试期间,我得到了EofException例外。

终点注释在这里: -

@POST
@Path("/")
@Consumes("application/json")
@Produces("application/json")
@GZIP

即使我删除了@zip注释,但我仍然遇到相同的错误。

测试案例代码在这里: -

 val compressedPayLoad = EntityBuilder.create()
        .setText(jsonLoader.loadAsString("abc.json"))
        .gzipCompress()
        .build()
    val req = HttpPost("$rootPath/").entity(compressedPayLoad).addAuthorization()
   
    req.addHeader(HttpHeaders.CONTENT_ENCODING, "gzip")
    req.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())

    val resp = execute(req)
    assertEquals(200, resp.statusLine.statusCode)

我在调试期间在Mete-inf.Services文件夹中添加了提供商类

org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor
org.jboss.resteasy.plugins.interceptors.GZIPEncodingInterceptor
org.jboss.resteasy.plugins.interceptors.AcceptEncodingGZIPFilter

,我发现了互轴承方法称为Twiet,我的假设是在服务器端两次消耗流,使其“空为空对于第二个消费者。

注意: - .addauthorization()是我们的内部辅助函数。

服务中的日志在这里: -

Interceptor Context: org.jboss.resteasy.core.interception.jaxrs.ServerReaderInterceptorContext,  Method : proceed
DEBUG o.j.r.r.i18n ReaderInterceptor: org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor
DEBUG o.j.r.r.i18n Interceptor : org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor,  Method : aroundReadFrom
DEBUG o.j.r.r.i18n Interceptor Context: org.jboss.resteasy.core.interception.jaxrs.ServerReaderInterceptorContext,  Method : proceed
DEBUG o.j.r.r.i18n MessageBodyReader: org.jboss.resteasy.core.providerfactory.SortedKey
DEBUG o.j.r.r.i18n MessageBodyReader: org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider
DEBUG o.j.r.r.i18n Provider : org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider,  Method : readFrom
DEBUG o.j.r.r.i18n Interceptor : org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor$FinishableGZIPInputStream,  Method : read
DEBUG o.j.r.r.i18n Interceptor Context: org.jboss.resteasy.core.interception.jaxrs.ServerReaderInterceptorContext,  Method : proceed
DEBUG o.j.r.r.i18n ReaderInterceptor: org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor
DEBUG o.j.r.r.i18n Interceptor : org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor,  Method : aroundReadFrom
ERROR c.t.s.e.CatchAllExceptionMapper Unhandled exception
java.io.EOFException: null

在这里,我们可以看到 awardRead 方法两次。我有没有想念的东西,或者以前有人遇到了这个问题。请帮助我。

I enabled the GZIP compression for the REST API and during testing, I am getting an EOFException exception.

The Endpoint annotations are here:-

@POST
@Path("/")
@Consumes("application/json")
@Produces("application/json")
@GZIP

Even though I removed the @ZIP annotation still I am getting the same error.

The test case code is here:-

 val compressedPayLoad = EntityBuilder.create()
        .setText(jsonLoader.loadAsString("abc.json"))
        .gzipCompress()
        .build()
    val req = HttpPost("$rootPath/").entity(compressedPayLoad).addAuthorization()
   
    req.addHeader(HttpHeaders.CONTENT_ENCODING, "gzip")
    req.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())

    val resp = execute(req)
    assertEquals(200, resp.statusLine.statusCode)

I added the Provider classes in the METE-INF.services folder

org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor
org.jboss.resteasy.plugins.interceptors.GZIPEncodingInterceptor
org.jboss.resteasy.plugins.interceptors.AcceptEncodingGZIPFilter

During debugging I found the Interparator method called twice and My assumption is that stream is being consumed twice on the server-side, making it “empty” for the second consumer.

Note:- .addAuthorization() is our internal helper function.

The logs from the service are here:-

Interceptor Context: org.jboss.resteasy.core.interception.jaxrs.ServerReaderInterceptorContext,  Method : proceed
DEBUG o.j.r.r.i18n ReaderInterceptor: org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor
DEBUG o.j.r.r.i18n Interceptor : org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor,  Method : aroundReadFrom
DEBUG o.j.r.r.i18n Interceptor Context: org.jboss.resteasy.core.interception.jaxrs.ServerReaderInterceptorContext,  Method : proceed
DEBUG o.j.r.r.i18n MessageBodyReader: org.jboss.resteasy.core.providerfactory.SortedKey
DEBUG o.j.r.r.i18n MessageBodyReader: org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider
DEBUG o.j.r.r.i18n Provider : org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider,  Method : readFrom
DEBUG o.j.r.r.i18n Interceptor : org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor$FinishableGZIPInputStream,  Method : read
DEBUG o.j.r.r.i18n Interceptor Context: org.jboss.resteasy.core.interception.jaxrs.ServerReaderInterceptorContext,  Method : proceed
DEBUG o.j.r.r.i18n ReaderInterceptor: org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor
DEBUG o.j.r.r.i18n Interceptor : org.jboss.resteasy.plugins.interceptors.GZIPDecodingInterceptor,  Method : aroundReadFrom
ERROR c.t.s.e.CatchAllExceptionMapper Unhandled exception
java.io.EOFException: null

Here we can see the aroundReadFrom method called twice. Is there anything that I am missing or anyone faced this issue before. Please help me with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文