Class HttpChannel

java.lang.Object
org.eclipse.jetty.ee8.nested.HttpChannel
All Implemented Interfaces:
Runnable, HttpOutput.Interceptor

public class HttpChannel extends Object implements Runnable, HttpOutput.Interceptor

The state machine that processes a request/response cycle interpreting the HTTP and Servlet semantic.

  • Constructor Details

  • Method Details

    • getContextHandler

      public ContextHandler getContextHandler()
    • isSendError

      public boolean isSendError()
    • newHttpInput

      protected HttpInput newHttpInput()
    • getConnectionMetaData

      public ConnectionMetaData getConnectionMetaData()
    • needContent

      public boolean needContent()
      Notify the channel that content is needed. If some content is immediately available, true is returned and produceContent() has to be called and will return a non-null object. If no content is immediately available, an attempt to produce content must be made; if new content has been produced, true is returned; otherwise HttpInput.onContentProducible() is called once some content arrives and produceContent() can be called without returning null. If a failure happens, then HttpInput.onContentProducible() will be called and an error content will return the error on the next call to produceContent().
      Returns:
      true if content is immediately available.
    • produceContent

      public HttpInput.Content produceContent()
      Produce a HttpInput.Content object with data currently stored within the channel. The produced content can be special (meaning calling HttpInput.Content.isSpecial() returns true) if the channel reached a special state, like EOF or an error. Once a special content has been returned, all subsequent calls to this method will always return a special content of the same kind and needContent() will always return true. The returned content is "raw", i.e.: not decoded.
      Returns:
      a HttpInput.Content object if one is immediately available without blocking, null otherwise.
    • failAllContent

      public boolean failAllContent(Throwable failure)
      Fail all content that is currently stored within the channel.
      Parameters:
      failure - the failure to fail the content with.
      Returns:
      true if EOF was reached while failing all content, false otherwise.
    • failed

      public boolean failed(Throwable failure)
      Fail the channel's input.
      Parameters:
      failure - the failure.
      Returns:
      true if the channel needs to be rescheduled.
    • eof

      protected boolean eof()
      Mark the channel's input as EOF.
      Returns:
      true if the channel needs to be rescheduled.
    • newHttpOutput

      protected HttpOutput newHttpOutput()
    • getState

      public HttpChannelState getState()
    • addListener

      @Deprecated public boolean addListener(HttpChannel.Listener listener)
      Deprecated.
      Add a transient Listener to the HttpChannel.

      Listeners added by this method will only be notified if the HttpChannel has been constructed with an instance of HttpChannel.TransientListeners as an AbstractConnector provided listener

      Transient listeners are removed after every request cycle

      Parameters:
      listener - the listener to add
      Returns:
      true if the listener was added.
    • removeListener

      @Deprecated public boolean removeListener(HttpChannel.Listener listener)
      Deprecated.
    • getTransientListeners

      @Deprecated public List<HttpChannel.Listener> getTransientListeners()
      Deprecated.
    • getBytesWritten

      public long getBytesWritten()
    • getRequests

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

      public Connector getConnector()
    • getCommittedMetaData

      public 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 ByteBufferPool getByteBufferPool()
    • getHttpConfiguration

      public HttpConfiguration getHttpConfiguration()
    • getServer

      public Server getServer()
    • getCoreRequest

      public ContextHandler.CoreContextRequest getCoreRequest()
    • getRequest

      public Request getRequest()
    • getCoreResponse

      public Response getCoreResponse()
    • getResponse

      public Response getResponse()
    • getConnection

      public Connection getConnection()
    • getEndPoint

      public EndPoint getEndPoint()
    • getLocalName

      public String getLocalName()

      Return the local name of the connected channel.

      This is the host name after the connector is bound and the connection is accepted.

      Value can be overridden by HttpConfiguration.setLocalAddress(SocketAddress).

      Note: some connectors are not based on IP networking, and default behavior here will result in a null return. Use HttpConfiguration.setLocalAddress(SocketAddress) to set the value to an acceptable host name.

      Returns:
      the local name, or null
    • getLocalPort

      public int getLocalPort()

      Return the Local Port of the connected channel.

      This is the port the connector is bound to and is accepting connections on.

      Value can be overridden by HttpConfiguration.setLocalAddress(SocketAddress).

      Note: some connectors are not based on IP networking, and default behavior here will result in a value of 0 returned. Use HttpConfiguration.setLocalAddress(SocketAddress) to set the value to an acceptable port.

      Returns:
      the local port, or 0 if unspecified
    • getLocalAddress

      public InetSocketAddress getLocalAddress()
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
    • getServerAuthority

      public HostPort getServerAuthority()
      Get return the HttpConfiguration server authority override.
      Returns:
      return the HttpConfiguration server authority override
    • send102Processing

      public void send102Processing(HttpFields headers) throws IOException
      Throws:
      IOException
    • send103EarlyHints

      public void send103EarlyHints(HttpFields headers) throws IOException
      Throws:
      IOException
    • recycle

      public void recycle()
    • 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)
    • ensureConsumeAllOrNotPersistent

      public void ensureConsumeAllOrNotPersistent()
    • sendErrorOrAbort

      public boolean sendErrorOrAbort(String message)
      Parameters:
      message - the error message.
      Returns:
      true if we have sent an error, false if we have aborted.
    • 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
    • sendResponseAndComplete

      public void sendResponseAndComplete()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • onRequest

      public void onRequest(ContextHandler.CoreContextRequest coreRequest)
    • onProcess

      public void onProcess(Response coreResponse, Callback coreCallback)
    • onCompleted

      public void onCompleted()
    • onBadMessage

      public void onBadMessage(BadMessageException failure)
    • sendResponse

      protected boolean sendResponse(MetaData.Response response, ByteBuffer content, boolean complete, Callback callback)
    • sendResponse

      public boolean sendResponse(MetaData.Response info, ByteBuffer content, boolean complete) throws IOException
      Throws:
      IOException
    • commit

      protected void commit(MetaData.Response info)
    • isCommitted

      public boolean isCommitted()
    • isRequestCompleted

      public boolean isRequestCompleted()
      Returns:
      True if the request lifecycle is completed
    • isResponseCompleted

      public boolean isResponseCompleted()
      Returns:
      True if the response is completely written.
    • isPersistent

      public boolean isPersistent()
    • write

      public void write(ByteBuffer content, boolean complete, 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
    • resetBuffer

      public void resetBuffer()
      Description copied from interface: HttpOutput.Interceptor
      Reset the buffers.

      If the Interceptor contains buffers then reset them.

      Specified by:
      resetBuffer in interface HttpOutput.Interceptor
    • getNextInterceptor

      public HttpOutput.Interceptor getNextInterceptor()
      Specified by:
      getNextInterceptor in interface HttpOutput.Interceptor
      Returns:
      The next Interceptor in the chain or null if this is the last Interceptor in the chain.
    • execute

      protected void execute(Runnable task)
    • getScheduler

      public Scheduler getScheduler()
    • isUseOutputDirectByteBuffers

      public boolean isUseOutputDirectByteBuffers()
    • abort

      public void abort(Throwable failure)
      If a write or similar operation to this channel fails, then this method should be called.
      Parameters:
      failure - the failure that caused the abort.
    • isTunnellingSupported

      public boolean isTunnellingSupported()
    • getTunnellingEndPoint

      public EndPoint getTunnellingEndPoint()