public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHandler
WebHandler
to the HttpHandler
contract.
By default creates and configures a DefaultServerWebExchange
and
then invokes the target WebHandler
.
Modifier and Type | Field and Description |
---|---|
private ApplicationContext |
applicationContext |
private ServerCodecConfigurer |
codecConfigurer |
private static java.util.Set<java.lang.String> |
DISCONNECTED_CLIENT_EXCEPTIONS
Tomcat: ClientAbortException or EOFException
Jetty: EofException
WildFly, GlassFish: java.io.IOException "Broken pipe" (already covered)
|
private static java.lang.String |
DISCONNECTED_CLIENT_LOG_CATEGORY
Dedicated log category for disconnected client exceptions.
|
private static Log |
disconnectedClientLogger |
private LocaleContextResolver |
localeContextResolver |
private static Log |
logger |
private WebSessionManager |
sessionManager |
Constructor and Description |
---|
HttpWebHandlerAdapter(WebHandler delegate) |
Modifier and Type | Method and Description |
---|---|
protected ServerWebExchange |
createExchange(ServerHttpRequest request,
ServerHttpResponse response) |
ApplicationContext |
getApplicationContext()
Return the configured
ApplicationContext , if any. |
ServerCodecConfigurer |
getCodecConfigurer()
Return the configured
ServerCodecConfigurer . |
LocaleContextResolver |
getLocaleContextResolver()
Return the configured
LocaleContextResolver . |
WebSessionManager |
getSessionManager()
Return the configured
WebSessionManager . |
<any> |
handle(ServerHttpRequest request,
ServerHttpResponse response)
Handle the given request and write to the response.
|
private <any> |
handleFailure(ServerHttpRequest request,
ServerHttpResponse response,
java.lang.Throwable ex) |
private boolean |
isDisconnectedClientError(java.lang.Throwable ex) |
void |
setApplicationContext(ApplicationContext applicationContext)
Configure the
ApplicationContext associated with the web application,
if it was initialized with one via
WebHttpHandlerBuilder#applicationContext . |
void |
setCodecConfigurer(ServerCodecConfigurer codecConfigurer)
Configure a custom
ServerCodecConfigurer . |
void |
setLocaleContextResolver(LocaleContextResolver localeContextResolver)
Configure a custom
LocaleContextResolver . |
void |
setSessionManager(WebSessionManager sessionManager)
Configure a custom
WebSessionManager to use for managing web
sessions. |
getDelegate, handle, toString
private static final java.lang.String DISCONNECTED_CLIENT_LOG_CATEGORY
Servlet containers do not expose a notification when a client disconnects, e.g. SERVLET_SPEC-44.
To avoid filling logs with unnecessary stack traces, we make an effort to identify such network failures on a per-server basis, and then log under a separate log category a simple one-line message at DEBUG level or a full stack trace only at TRACE level.
private static final java.util.Set<java.lang.String> DISCONNECTED_CLIENT_EXCEPTIONS
TODO: This definition is currently duplicated between HttpWebHandlerAdapter and AbstractSockJsSession. It is a candidate for a common utility class.
isDisconnectedClientError(Throwable)
private static final Log logger
private static final Log disconnectedClientLogger
private WebSessionManager sessionManager
@Nullable private ServerCodecConfigurer codecConfigurer
@Nullable private LocaleContextResolver localeContextResolver
@Nullable private ApplicationContext applicationContext
public HttpWebHandlerAdapter(WebHandler delegate)
public void setSessionManager(WebSessionManager sessionManager)
WebSessionManager
to use for managing web
sessions. The provided instance is set on each created
DefaultServerWebExchange
.
By default this is set to DefaultWebSessionManager
.
sessionManager
- the session manager to usepublic WebSessionManager getSessionManager()
WebSessionManager
.public void setCodecConfigurer(ServerCodecConfigurer codecConfigurer)
ServerCodecConfigurer
. The provided instance is set on
each created DefaultServerWebExchange
.
By default this is set to ServerCodecConfigurer.create()
.
codecConfigurer
- the codec configurer to usepublic ServerCodecConfigurer getCodecConfigurer()
ServerCodecConfigurer
.public void setLocaleContextResolver(LocaleContextResolver localeContextResolver)
LocaleContextResolver
. The provided instance is set on
each created DefaultServerWebExchange
.
By default this is set to
AcceptHeaderLocaleContextResolver
.
localeContextResolver
- the locale context resolver to usepublic LocaleContextResolver getLocaleContextResolver()
LocaleContextResolver
.public void setApplicationContext(ApplicationContext applicationContext)
ApplicationContext
associated with the web application,
if it was initialized with one via
WebHttpHandlerBuilder#applicationContext
.applicationContext
- the context@Nullable public ApplicationContext getApplicationContext()
ApplicationContext
, if any.public <any> handle(ServerHttpRequest request, ServerHttpResponse response)
HttpHandler
handle
in interface HttpHandler
request
- current requestresponse
- current responseprotected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response)
private <any> handleFailure(ServerHttpRequest request, ServerHttpResponse response, java.lang.Throwable ex)
private boolean isDisconnectedClientError(java.lang.Throwable ex)