- java.lang.Object
-
- org.eclipse.jetty.server.HttpChannel
-
- All Implemented Interfaces:
java.lang.Runnable
,HttpOutput.Interceptor
- Direct Known Subclasses:
HttpChannelOverHttp
public abstract class HttpChannel extends java.lang.Object implements java.lang.Runnable, HttpOutput.Interceptor
HttpChannel represents a single endpoint for HTTP semantic processing. The HttpChannel is both an 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().
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
HttpChannel.Listener
Listener forHttpChannel
events.static class
HttpChannel.TransientListeners
Deprecated.
-
Field Summary
Fields Modifier and Type Field Description static HttpChannel.Listener
NOOP_LISTENER
-
Constructor Summary
Constructors Constructor Description HttpChannel(Connector connector, HttpConfiguration configuration, org.eclipse.jetty.io.EndPoint endPoint, HttpTransport transport)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
abort(java.lang.Throwable failure)
If a write or similar operation to this channel fails, then this method should be called.boolean
addListener(HttpChannel.Listener listener)
Deprecated.void
addRequestLog(RequestLog requestLog)
protected boolean
checkAndPrepareUpgrade()
Checks whether the processing of the request resulted in an upgrade, and if so performs upgrade preparation steps before the upgrade response is sent back to the client.protected void
commit(org.eclipse.jetty.http.MetaData.Response info)
void
continue100(int available)
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.void
ensureConsumeAllOrNotPersistent()
protected abstract boolean
eof()
Mark the channel's input as EOF.protected void
execute(java.lang.Runnable task)
abstract boolean
failAllContent(java.lang.Throwable failure)
Fail all content that is currently stored within the channel.abstract boolean
failed(java.lang.Throwable failure)
Fail the channel's input.org.eclipse.jetty.io.ByteBufferPool
getByteBufferPool()
long
getBytesWritten()
org.eclipse.jetty.http.MetaData.Response
getCommittedMetaData()
org.eclipse.jetty.io.Connection
getConnection()
Connector
getConnector()
org.eclipse.jetty.io.EndPoint
getEndPoint()
HttpConfiguration
getHttpConfiguration()
HttpTransport
getHttpTransport()
long
getIdleTimeout()
Get the idle timeout.java.net.InetSocketAddress
getLocalAddress()
HttpOutput.Interceptor
getNextInterceptor()
java.net.InetSocketAddress
getRemoteAddress()
Request
getRequest()
RequestLog
getRequestLog()
long
getRequests()
Response
getResponse()
org.eclipse.jetty.util.thread.Scheduler
getScheduler()
Server
getServer()
HttpChannelState
getState()
java.util.List<HttpChannel.Listener>
getTransientListeners()
Deprecated.org.eclipse.jetty.io.EndPoint
getTunnellingEndPoint()
boolean
handle()
protected void
handleException(java.lang.Throwable failure)
Sends an error 500, performing a special logic to detect whether the request is suspended, to avoid concurrent writes from the application.boolean
isCommitted()
boolean
isExpecting100Continue()
boolean
isExpecting102Processing()
boolean
isPersistent()
boolean
isRequestCompleted()
boolean
isResponseCompleted()
boolean
isSendError()
boolean
isTunnellingSupported()
boolean
isUseOutputDirectByteBuffers()
abstract boolean
needContent()
Notify the channel that content is needed.protected HttpOutput
newHttpOutput()
void
onBadMessage(org.eclipse.jetty.http.BadMessageException failure)
void
onCompleted()
boolean
onContent(HttpInput.Content content)
boolean
onContentComplete()
void
onRequest(org.eclipse.jetty.http.MetaData.Request request)
boolean
onRequestComplete()
void
onTrailers(org.eclipse.jetty.http.HttpFields trailers)
abstract HttpInput.Content
produceContent()
Produce aHttpInput.Content
object with data currently stored within the channel.void
recycle()
boolean
removeListener(HttpChannel.Listener listener)
Deprecated.void
resetBuffer()
Reset the buffers.void
run()
boolean
sendErrorOrAbort(java.lang.String message)
boolean
sendResponse(org.eclipse.jetty.http.MetaData.Response info, java.nio.ByteBuffer content, boolean complete)
protected boolean
sendResponse(org.eclipse.jetty.http.MetaData.Response response, java.nio.ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)
void
sendResponseAndComplete()
void
setIdleTimeout(long timeoutMs)
Set the idle timeout.void
setRequestLog(RequestLog requestLog)
java.lang.String
toString()
protected java.lang.Throwable
unwrap(java.lang.Throwable failure, java.lang.Class<?>... targets)
Unwrap failure causes to find target classvoid
write(java.nio.ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)
Non-Blocking write, committing the response if needed.
-
-
-
Field Detail
-
NOOP_LISTENER
public static HttpChannel.Listener NOOP_LISTENER
-
-
Constructor Detail
-
HttpChannel
public HttpChannel(Connector connector, HttpConfiguration configuration, org.eclipse.jetty.io.EndPoint endPoint, HttpTransport transport)
-
-
Method Detail
-
isSendError
public boolean isSendError()
-
needContent
public abstract boolean needContent()
Notify the channel that content is needed. If some content is immediately available, true is returned andproduceContent()
has to be called and will return a non-null object. If no content is immediately available,HttpInput.onContentProducible()
is called once some content arrives andproduceContent()
can be called without returning null. If a failure happens, thenHttpInput.onContentProducible()
will be called and an error content will return the error on the next call toproduceContent()
.- Returns:
- true if content is immediately available.
-
produceContent
public abstract HttpInput.Content produceContent()
Produce aHttpInput.Content
object with data currently stored within the channel. The produced content can be special (meaning callingHttpInput.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 andneedContent()
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 abstract boolean failAllContent(java.lang.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 abstract boolean failed(java.lang.Throwable failure)
Fail the channel's input.- Parameters:
failure
- the failure.- Returns:
- true if the channel needs to be rescheduled.
-
eof
protected abstract 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 anAbstractConnector
provided listenerTransient listeners are removed after every request cycle
- Parameters:
listener
-- Returns:
- true if the listener was added.
-
removeListener
@Deprecated public boolean removeListener(HttpChannel.Listener listener)
Deprecated.
-
getTransientListeners
@Deprecated public java.util.List<HttpChannel.Listener> getTransientListeners()
Deprecated.
-
getBytesWritten
public long getBytesWritten()
-
getRequests
public long getRequests()
- Returns:
- the number of requests handled by this connection
-
getConnector
public Connector getConnector()
-
getHttpTransport
public HttpTransport getHttpTransport()
-
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()
-
getHttpConfiguration
public HttpConfiguration getHttpConfiguration()
-
getServer
public Server getServer()
-
getRequest
public Request getRequest()
-
getResponse
public Response getResponse()
-
getConnection
public org.eclipse.jetty.io.Connection getConnection()
-
getEndPoint
public org.eclipse.jetty.io.EndPoint getEndPoint()
-
getLocalAddress
public java.net.InetSocketAddress getLocalAddress()
-
getRemoteAddress
public java.net.InetSocketAddress getRemoteAddress()
-
continue100
public void continue100(int available) throws java.io.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:
java.io.IOException
- if the InputStream cannot be created
-
recycle
public void recycle()
-
run
public void run()
- Specified by:
run
in interfacejava.lang.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(java.lang.String message)
- Parameters:
message
- the error message.- Returns:
- true if we have sent an error, false if we have aborted.
-
handleException
protected void handleException(java.lang.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 java.lang.Throwable unwrap(java.lang.Throwable failure, java.lang.Class<?>... targets)
Unwrap failure causes to find target class- Parameters:
failure
- The throwable to have its causes unwrappedtargets
- Exception classes that we should not unwrap- Returns:
- A target throwable or null
-
sendResponseAndComplete
public void sendResponseAndComplete()
-
isExpecting100Continue
public boolean isExpecting100Continue()
-
isExpecting102Processing
public boolean isExpecting102Processing()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
onRequest
public void onRequest(org.eclipse.jetty.http.MetaData.Request request)
-
onContent
public boolean onContent(HttpInput.Content content)
-
onContentComplete
public boolean onContentComplete()
-
onTrailers
public void onTrailers(org.eclipse.jetty.http.HttpFields trailers)
-
onRequestComplete
public boolean onRequestComplete()
-
checkAndPrepareUpgrade
protected boolean checkAndPrepareUpgrade()
Checks whether the processing of the request resulted in an upgrade, and if so performs upgrade preparation steps before the upgrade response is sent back to the client.
This avoids a race where the server is unprepared if the client sends data immediately after having received the upgrade response.
- Returns:
- true if the channel is not complete and more processing is required, typically because sendError has been called.
-
onCompleted
public void onCompleted()
-
onBadMessage
public void onBadMessage(org.eclipse.jetty.http.BadMessageException failure)
-
sendResponse
protected boolean sendResponse(org.eclipse.jetty.http.MetaData.Response response, java.nio.ByteBuffer content, boolean complete, org.eclipse.jetty.util.Callback callback)
-
sendResponse
public boolean sendResponse(org.eclipse.jetty.http.MetaData.Response info, java.nio.ByteBuffer content, boolean complete) throws java.io.IOException
- Throws:
java.io.IOException
-
commit
protected void commit(org.eclipse.jetty.http.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(java.nio.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 interfaceHttpOutput.Interceptor
- Parameters:
content
- the content buffer to writecomplete
- whether the content is complete for the responsecallback
- 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 interfaceHttpOutput.Interceptor
-
getNextInterceptor
public HttpOutput.Interceptor getNextInterceptor()
- Specified by:
getNextInterceptor
in interfaceHttpOutput.Interceptor
- Returns:
- The next Interceptor in the chain or null if this is the last Interceptor in the chain.
-
execute
protected void execute(java.lang.Runnable task)
-
getScheduler
public org.eclipse.jetty.util.thread.Scheduler getScheduler()
-
isUseOutputDirectByteBuffers
public boolean isUseOutputDirectByteBuffers()
-
abort
public void abort(java.lang.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.
-
isTunnellingSupported
public boolean isTunnellingSupported()
-
getTunnellingEndPoint
public org.eclipse.jetty.io.EndPoint getTunnellingEndPoint()
-
-