Class ServletChannel
ServletChannelState
to coordinate the states of dispatch state, input and
output according to the servlet specification. The combined state so obtained
is reflected in the behaviour of the contained HttpInput
implementation of
ServletInputStream
.
This class is reusable over multiple requests for the same ServletContextHandler
and is recycled
after each use before being
associated
with a new ServletContextRequest
and then associated
with possibly wrapped
request, response and callback.
- See Also:
-
Constructor Summary
ConstructorDescriptionServletChannel
(ServletContextHandler servletContextHandler, ConnectionMetaData connectionMetaData) ServletChannel
(ServletContextHandler servletContextHandler, Request request) -
Method Summary
Modifier and TypeMethodDescriptionvoid
If a write or similar operation to this channel fails, then this method should be called.void
associate
(ServletContextRequest servletContextRequest) Associate this channel with a specific request.void
Associate this channel with possibly wrapped values forgetRequest()
,getResponse()
andgetCallback()
.void
protected void
protected void
protected String
formatAddrOrHost
(String addr) Format the address or host returned from Request methodslong
Get the idle timeout.Return the local name of the connected channel.int
Return the Local Port of the connected channel.Get return the HttpConfiguration server authority override.void
handle()
Handle the servlet request.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.boolean
boolean
boolean
boolean
boolean
void
void
void
setIdleTimeout
(long timeoutMs) Set the idle timeout.toString()
protected Throwable
Unwrap failure causes to find target class
-
Constructor Details
-
ServletChannel
-
ServletChannel
public ServletChannel(ServletContextHandler servletContextHandler, ConnectionMetaData connectionMetaData)
-
-
Method Details
-
getConnectionMetaData
-
getCallback
-
associate
Associate this channel with a specific request. This method is called by theServletContextHandler
when a coreRequest
is accepted and associated with a servlet mapping. The association remains functional untilrecycle(Throwable)
is called, and it remains readable until a call torecycle(Throwable)
or a subsequent call toassociate
.- Parameters:
servletContextRequest
- The servlet context request to associate- See Also:
-
recycle(Throwable)
-
associate
Associate this channel with possibly wrapped values forgetRequest()
,getResponse()
andgetCallback()
. This is called by theServletHandler
immediately before callinghandle()
on the initial dispatch. This allows for handlers between theServletContextHandler
and theServletHandler
to wrap the instances.- Parameters:
request
- The request, which may have been wrapped after #ServletContextHandler.wrapRequest(Request, Response)
response
- The response, which may have been wrapped after #ServletContextHandler.wrapResponse(ContextRequest, Response)
callback
- The context, which may have been wrapped afterContextHandler.handle(Request, Response, Callback)
-
getContext
-
getServletContextHandler
-
getServletContextApi
-
getHttpOutput
-
getHttpInput
-
isAborted
public boolean isAborted() -
isSendError
public boolean isSendError() -
formatAddrOrHost
Format the address or host returned from Request methods- Parameters:
addr
- The address or host- Returns:
- Default implementation returns
HostPort.normalizeHost(String)
-
getServletRequestState
-
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
-
getHttpConfiguration
-
getServer
-
getServletContextRequest
- Returns:
- The
ServletContextRequest
as wrapped by theServletContextHandler
. - See Also:
-
getRequest
- Returns:
- The core
Request
associated with the request. This may differ fromgetServletContextRequest()
if the request was wrapped by another handler after theServletContextHandler
and passed toassociate(Request, Response, Callback)
. - See Also:
-
getServletContextResponse
- Returns:
- The ServetContextResponse as wrapped by the
ServletContextHandler
. - See Also:
-
getResponse
- Returns:
- The core
Response
associated with the API response. This may differ fromgetServletContextResponse()
if the response was wrapped by another handler after theServletContextHandler
and passed toassociate(Request, Response, Callback)
. - See Also:
-
getConnection
-
getEndPoint
-
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
-
getRemoteAddress
-
getServerAuthority
Get return the HttpConfiguration server authority override.- Returns:
- return the HttpConfiguration server authority override
-
handle
public void handle()Handle the servlet request. This is called on the initial dispatch and then again on any asynchronous events. -
handleException
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
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
-
sendErrorResponseAndComplete
public void sendErrorResponseAndComplete() -
toString
-
onCompleted
public void onCompleted()- See Also:
-
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.
-
execute
-
execute
-
abort
If a write or similar operation to this channel fails, then this method should be called.- Parameters:
failure
- the failure that caused the abort.- See Also:
-
dispatchAsync
- Throws:
Exception
-