Class JdkHttpHandlerContainer.ResponseWriter

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicBoolean closed  
      private com.sun.net.httpserver.HttpExchange exchange  
    • Constructor Summary

      Constructors 
      Constructor Description
      ResponseWriter​(com.sun.net.httpserver.HttpExchange exchange)
      Creates a new ResponseWriter for given HTTP Exchange.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void closeAndLogWarning()
      Commits the response and logs a warning message.
      void commit()
      Commit the response & close the container response writer.
      boolean enableResponseBuffering()
      Return true if the entity buffering should be enabled in Jersey.
      void failure​(java.lang.Throwable error)
      Propagate an unhandled error to the I/O container.
      private long getResponseLength​(long contentLength)  
      private void rethrow​(java.lang.Throwable error)
      Rethrow the original exception as required by JAX-RS, 3.3.4
      void setSuspendTimeout​(long timeOut, java.util.concurrent.TimeUnit timeUnit)
      Set the suspend timeout.
      boolean suspend​(long timeOut, java.util.concurrent.TimeUnit timeUnit, ContainerResponseWriter.TimeoutHandler timeoutHandler)
      Suspend the request/response processing.
      java.io.OutputStream writeResponseStatusAndHeaders​(long contentLength, ContainerResponse context)
      Write the status and headers of the response and return an output stream for the web application to write the entity of the response.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • exchange

        private final com.sun.net.httpserver.HttpExchange exchange
      • closed

        private final java.util.concurrent.atomic.AtomicBoolean closed
    • Constructor Detail

      • ResponseWriter

        ResponseWriter​(com.sun.net.httpserver.HttpExchange exchange)
        Creates a new ResponseWriter for given HTTP Exchange.
        Parameters:
        exchange - Exchange of the JDK Http Server
    • Method Detail

      • writeResponseStatusAndHeaders

        public java.io.OutputStream writeResponseStatusAndHeaders​(long contentLength,
                                                                  ContainerResponse context)
                                                           throws ContainerException
        Description copied from interface: ContainerResponseWriter
        Write the status and headers of the response and return an output stream for the web application to write the entity of the response.

        If the response content length is declared to be greater or equal to 0, it means that the content length in bytes of the entity to be written is known, otherwise -1. I/O containers may use this value to determine whether the "Content-Length" header can be set or utilize chunked transfer encoding.

        Specified by:
        writeResponseStatusAndHeaders in interface ContainerResponseWriter
        Parameters:
        contentLength - greater or equal to 0 if the content length in bytes of the entity to be written is known, otherwise -1. Containers may use this value to determine whether the "Content-Length" header can be set or utilize chunked transfer encoding.
        context - the JAX-RS response to be written. The status and headers are obtained from the response.
        Returns:
        the output stream to write the entity (if any).
        Throws:
        ContainerException - if an error occurred when writing out the status and headers or obtaining the output stream.
      • getResponseLength

        private long getResponseLength​(long contentLength)
      • setSuspendTimeout

        public void setSuspendTimeout​(long timeOut,
                                      java.util.concurrent.TimeUnit timeUnit)
                               throws java.lang.IllegalStateException
        Description copied from interface: ContainerResponseWriter
        Set the suspend timeout. Once the container response writer is suspended, the suspend timeout value can be further updated by the method.
        Specified by:
        setSuspendTimeout in interface ContainerResponseWriter
        Parameters:
        timeOut - time-out value. Value less or equal to 0, indicates that the processing is suspended indefinitely.
        timeUnit - time-out time unit.
        Throws:
        java.lang.IllegalStateException - in case the response writer has not been suspended yet.
      • failure

        public void failure​(java.lang.Throwable error)
        Description copied from interface: ContainerResponseWriter
        Propagate an unhandled error to the I/O container. Indicates to the I/O container that the request processing has finished with an error that could not be processed by the Jersey runtime. The I/O container is expected to process the exception in a container-specific way. This method also signals the I/O container to finish the request/response processing, clean up any state, flush any streams, release resources etc.
        Specified by:
        failure in interface ContainerResponseWriter
        Parameters:
        error - unhandled request processing error.
        See Also:
        ContainerResponseWriter.suspend(long, TimeUnit, TimeoutHandler), ContainerResponseWriter.commit()
      • enableResponseBuffering

        public boolean enableResponseBuffering()
        Description copied from interface: ContainerResponseWriter
        Return true if the entity buffering should be enabled in Jersey. If enabled, the outbound entity is buffered by Jersey runtime up to a configured amount of bytes prior to being written to the output stream to determine its size that may be used to set the value of HTTP "Content-Length" header.

        Containers that provide it's own solution for determining the message payload size may decide to return false to prevent Jersey from buffering message entities unnecessarily.

        Specified by:
        enableResponseBuffering in interface ContainerResponseWriter
        Returns:
        true to enable entity buffering to be done by Jersey runtime, false otherwise.
      • rethrow

        private void rethrow​(java.lang.Throwable error)
        Rethrow the original exception as required by JAX-RS, 3.3.4
        Parameters:
        error - throwable to be re-thrown
      • closeAndLogWarning

        private void closeAndLogWarning()
        Commits the response and logs a warning message. This method should be called by the container at the end of the handle method to make sure that the ResponseWriter was committed.