Class HttpChannel

  • All Implemented Interfaces:
    Runnable, HttpOutput.Interceptor
    Direct Known Subclasses:
    HttpChannelOverHttp

    public class HttpChannel
    extends Object
    implements Runnable, HttpOutput.Interceptor
    HttpChannel represents a single endpoint for HTTP semantic processing. The HttpChannel is both a HttpParser.RequestHandler, where it passively receives events from an incoming HTTP request, and a Runnable, where it actively takes control of the request/response life cycle and calls the application (perhaps suspending and resuming with multiple calls to run). The HttpChannel signals the switch from passive mode to active mode by returning true to one of the HttpParser.RequestHandler callbacks. The completion of the active phase is signalled by a call to HttpTransport.completed().
    • Method Detail

      • newHttpOutput

        protected HttpOutput newHttpOutput()
      • getBytesWritten

        public long getBytesWritten()
      • getRequests

        public long getRequests()
        Returns:
        the number of requests handled by this connection
      • getConnector

        public Connector getConnector()
      • getRequestLog

        public RequestLog getRequestLog()
      • setRequestLog

        public void setRequestLog​(RequestLog requestLog)
      • addRequestLog

        public void addRequestLog​(RequestLog requestLog)
      • getCommittedMetaData

        public org.eclipse.jetty.http.MetaData.Response getCommittedMetaData()
      • getIdleTimeout

        public long getIdleTimeout()
        Get the idle timeout.

        This is implemented as a call to EndPoint.getIdleTimeout(), but may be overridden by channels that have timeouts different from their connections.

        Returns:
        the idle timeout (in milliseconds)
      • setIdleTimeout

        public void setIdleTimeout​(long timeoutMs)
        Set the idle timeout.

        This is implemented as a call to EndPoint.setIdleTimeout(long), but may be overridden by channels that have timeouts different from their connections.

        Parameters:
        timeoutMs - the idle timeout in milliseconds
      • getByteBufferPool

        public org.eclipse.jetty.io.ByteBufferPool getByteBufferPool()
      • getServer

        public Server getServer()
      • getRequest

        public Request getRequest()
      • getResponse

        public Response getResponse()
      • getEndPoint

        public org.eclipse.jetty.io.EndPoint getEndPoint()
      • continue100

        public void continue100​(int available)
                         throws IOException
        If the associated response has the Expect header set to 100 Continue, then accessing the input stream indicates that the handler/servlet is ready for the request body and thus a 100 Continue response is sent.
        Parameters:
        available - estimate of the number of bytes that are available
        Throws:
        IOException - if the InputStream cannot be created
      • recycle

        public void recycle()
      • onAsyncWaitForContent

        public void onAsyncWaitForContent()
      • onBlockWaitForContent

        public void onBlockWaitForContent()
      • onBlockWaitForContentFailure

        public void onBlockWaitForContentFailure​(Throwable failure)
      • run

        public void run()
        Specified by:
        run in interface Runnable
      • handle

        public boolean handle()
        Returns:
        True if the channel is ready to continue handling (ie it is not suspended)
      • sendError

        protected void sendError​(int code,
                                 String reason)
      • handleException

        protected void handleException​(Throwable failure)

        Sends an error 500, performing a special logic to detect whether the request is suspended, to avoid concurrent writes from the application.

        It may happen that the application suspends, and then throws an exception, while an application spawned thread writes the response content; in such case, we attempt to commit the error directly bypassing the ErrorHandler mechanisms and the response OutputStream.

        Parameters:
        failure - the Throwable that caused the problem
      • unwrap

        protected Throwable unwrap​(Throwable failure,
                                   Class<?>... targets)
        Unwrap failure causes to find target class
        Parameters:
        failure - The throwable to have its causes unwrapped
        targets - Exception classes that we should not unwrap
        Returns:
        A target throwable or null
      • isExpecting100Continue

        public boolean isExpecting100Continue()
      • isExpecting102Processing

        public boolean isExpecting102Processing()
      • onRequest

        public void onRequest​(org.eclipse.jetty.http.MetaData.Request request)
      • onContentComplete

        public boolean onContentComplete()
      • onTrailers

        public void onTrailers​(org.eclipse.jetty.http.HttpFields trailers)
      • onRequestComplete

        public boolean onRequestComplete()
      • onCompleted

        public void onCompleted()
      • onEarlyEOF

        public boolean onEarlyEOF()
      • onBadMessage

        public void onBadMessage​(org.eclipse.jetty.http.BadMessageException failure)
      • sendResponse

        protected boolean sendResponse​(org.eclipse.jetty.http.MetaData.Response info,
                                       ByteBuffer content,
                                       boolean complete,
                                       org.eclipse.jetty.util.Callback callback)
      • sendResponse

        public boolean sendResponse​(org.eclipse.jetty.http.MetaData.Response info,
                                    ByteBuffer content,
                                    boolean complete)
                             throws IOException
        Throws:
        IOException
      • commit

        protected void commit​(org.eclipse.jetty.http.MetaData.Response info)
      • isCommitted

        public boolean isCommitted()
      • write

        public void write​(ByteBuffer content,
                          boolean complete,
                          org.eclipse.jetty.util.Callback callback)

        Non-Blocking write, committing the response if needed.

        Called as last link in HttpOutput.Filter chain
        Specified by:
        write in interface HttpOutput.Interceptor
        Parameters:
        content - the content buffer to write
        complete - whether the content is complete for the response
        callback - Callback when complete or failed
      • execute

        protected void execute​(Runnable task)
      • getScheduler

        public org.eclipse.jetty.util.thread.Scheduler getScheduler()
      • useDirectBuffers

        public boolean useDirectBuffers()
        Returns:
        true if the HttpChannel can efficiently use direct buffer (typically this means it is not over SSL or a multiplexed protocol)
      • abort

        public void abort​(Throwable failure)
        If a write or similar operation to this channel fails, then this method should be called.

        The standard implementation calls HttpTransport.abort(Throwable).

        Parameters:
        failure - the failure that caused the abort.