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
ConstructorsConstructorDescriptionServletChannel(ServletContextHandler servletContextHandler, ConnectionMetaData connectionMetaData) ServletChannel(ServletContextHandler servletContextHandler, Request request)  - 
Method Summary
Modifier and TypeMethodDescriptionvoidIf a write or similar operation to this channel fails, then this method should be called.voidassociate(ServletContextRequest servletContextRequest) Associate this channel with a specific request.voidAssociate this channel with possibly wrapped values forgetRequest(),getResponse()andgetCallback().voidAn AsyncContext dispatch method was called.protected voidprotected voidprotected StringformatAddrOrHost(String addr) Format the address or host returned from Request methodslongGet the idle timeout.Return the local name of the connected channel.intReturn the Local Port of the connected channel.Get return the HttpConfiguration server authority override.voidhandle()Handle the servlet request.protected voidhandleException(Throwable failure) Sends an error 500, performing a special logic to detect whether the request is suspended, to avoid concurrent writes from the application.booleanbooleanbooleanbooleanbooleanvoidvoidvoidsetIdleTimeout(long timeoutMs) Set the idle timeout.toString()protected ThrowableUnwrap 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 theServletContextHandlerwhen a coreRequestis 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:
 
 - 
associate
Associate this channel with possibly wrapped values forgetRequest(),getResponse()andgetCallback(). This is called by theServletHandlerimmediately before callinghandle()on the initial dispatch. This allows for handlers between theServletContextHandlerand theServletHandlerto 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 
ServletContextRequestas wrapped by theServletContextHandler. - See Also:
 
 - 
getRequest
- Returns:
 - The core 
Requestassociated with the request. This may differ fromgetServletContextRequest()if the request was wrapped by another handler after theServletContextHandlerand passed toassociate(Request, Response, Callback). - See Also:
 
 - 
getServletContextResponse
- Returns:
 - The ServetContextResponse as wrapped by the 
ServletContextHandler. - See Also:
 
 - 
getResponse
- Returns:
 - The core 
Responseassociated with the API response. This may differ fromgetServletContextResponse()if the response was wrapped by another handler after theServletContextHandlerand 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
ErrorHandlermechanisms and the response OutputStream.- Parameters:
 failure- the Throwable that caused the problem
 - 
unwrap
 - 
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
 
 -