Uploaded image for project: 'RESTEasy'
  1. RESTEasy
  2. RESTEASY-1650

Wrapping outputstreams set in interceptors are not closed

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 3.1.3.Final
    • 3.1.2.Final
    • jaxrs
    • None

    Description

      It appears that RESTEASY runtime does not call .close() on output stream.
      Many MessageBodyWritters do however call flush() o close() thus the problem is not always visible.
      But for simple StringTextStar MessageBodyWritter the problem can be easyli reproduced.

      ServletContainerDispatcher.service ends up calling
      (after invoking user methods)
      org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse()

      followed by interceptors ( proceed/aroundWriteTo)
      followed by message output writers (writeTo)

      during this chain the output stream is never closed.

      JavaDocs say in many places (CointainerResponseContext, WriterInterceptor etc)
      "The JAX-RS runtime is responsible for closing the output stream".

      So the stream should be closed somewhere after last call to writeTo.. but it's not.

      However some message writters DO close stream (in it's writeTo). Eg ResteasyJackson2Provider internally in writeTo calls it's JsonGenerator.close() method which closes wrapped entity stream.

      So when you return json entities using jackson - you have no problem with the output.

      However if you return eg simple String class (org.jboss.resteasy.plugins.providers.StringTextStar) then close() is never called.

      steps to reproduce:

      1. setup simple jax-rs service that returns String.class entity
      2. add writterInterceptor that will wrap output stream with some OutputStream that does buffering (CipherOutputStream is good example)
      3. observe that you wont'get full output body (or no output at all)

      instead of adding conrete wrapping output stream you may add eg FilterOutputStream + override close() method to add logging
      public void close() throws IOException {
      logger.info("close() called");
      super.close();
      }

      Attachments

        Issue Links

          Activity

            People

              rhn-support-asoldano Alessio Soldano
              pputerla PaweĊ‚ Puterla (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: