Package org.springframework.web.server.adapter

# Class HttpWebHandlerAdapter

java.lang.Object
org.springframework.web.server.handler.WebHandlerDecorator
org.springframework.web.server.adapter.HttpWebHandlerAdapter

All Implemented Interfaces:
  `HttpHandler`, `WebHandler`

public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHandler
Default adapter of `WebHandler` to the `HttpHandler` contract.

By default creates and configures a `DefaultServerWebExchange` and then invokes the target `WebHandler`.

Since:
  5.0
Author:
  Rossen Stoyanchev, Sebastien Deleuze, Brian Clozel

## Constructor Summary

Constructors
Constructor
Description
`HttpWebHandlerAdapter(WebHandler delegate)`

## Method Summary

Modifier and Type
Method
Description
`void`
`afterPropertiesSet()`
This method must be invoked after all properties have been set to complete initialization.
`protected ServerWebExchange`
`createExchange(ServerHttpRequest request, ServerHttpResponse response)`
`protected String`
`formatRequest(ServerHttpRequest request)`
Format the request for logging purposes including HTTP method and URL.
`org.springframework.context.ApplicationContext`
`getApplicationContext()`
Return the configured `ApplicationContext`, if any.
`ServerCodecConfigurer`
`getCodecConfigurer()`
Return the configured `ServerCodecConfigurer`.
`ForwardedHeaderTransformer`
`getForwardedHeaderTransformer()`
Return the configured `ForwardedHeaderTransformer`.
`LocaleContextResolver`
`getLocaleContextResolver()`
Return the configured `LocaleContextResolver`.
`ServerRequestObservationConvention`
`getObservationConvention()`
Return the Observation convention configured for server exchanges observations.
`io.micrometer.observation.ObservationRegistry`
`getObservationRegistry()`
Return the configured `ObservationRegistry`.
`WebSessionManager`
`getSessionManager()`
Return the configured `WebSessionManager`.
`reactor.core.publisher.Mono<Void>`
`handle(ServerHttpRequest request, ServerHttpResponse response)`
Handle the given request and write to the response.
`void`
`setApplicationContext(org.springframework.context.ApplicationContext applicationContext)`
Configure the `ApplicationContext` associated with the web application, if it was initialized with one via `WebHttpHandlerBuilder.applicationContext(ApplicationContext)`.
`void`
`setCodecConfigurer(ServerCodecConfigurer codecConfigurer)`
Configure a custom `ServerCodecConfigurer`.
`void`
`setForwardedHeaderTransformer(ForwardedHeaderTransformer transformer)`
Enable processing of forwarded headers, either extracting and removing, or remove only.
`void`
`setLocaleContextResolver(LocaleContextResolver resolver)`
Configure a custom `LocaleContextResolver`.
`void`
`setObservationConvention(ServerRequestObservationConvention observationConvention)`
Configure a `ServerRequestObservationConvention` for server exchanges observations.
`void`
`setObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)`
Configure an `ObservationRegistry` for recording server exchange observations.
`void`
`setSessionManager(WebSessionManager sessionManager)`
Configure a custom `WebSessionManager` to use for managing web sessions.

### Methods inherited from class org.springframework.web.server.handler.WebHandlerDecorator

`getDelegate, handle, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### HttpWebHandlerAdapter

public HttpWebHandlerAdapter(WebHandler delegate)

## Method Details

### setSessionManager

public void setSessionManager(WebSessionManager sessionManager)
Configure a custom `WebSessionManager` to use for managing web sessions. The provided instance is set on each created `DefaultServerWebExchange`.

By default this is set to `DefaultWebSessionManager`.

Parameters:
  `sessionManager` - the session manager to use

### getSessionManager

public WebSessionManager getSessionManager()
Return the configured `WebSessionManager`.

### setCodecConfigurer

public void setCodecConfigurer(ServerCodecConfigurer codecConfigurer)
Configure a custom `ServerCodecConfigurer`. The provided instance is set on each created `DefaultServerWebExchange`.

By default this is set to `ServerCodecConfigurer.create()`.

Parameters:
  `codecConfigurer` - the codec configurer to use

### getCodecConfigurer

public ServerCodecConfigurer getCodecConfigurer()
Return the configured `ServerCodecConfigurer`.

### setLocaleContextResolver

public void setLocaleContextResolver(LocaleContextResolver resolver)
Configure a custom `LocaleContextResolver`. The provided instance is set on each created `DefaultServerWebExchange`.

By default this is set to `AcceptHeaderLocaleContextResolver`.

Parameters:
  `resolver` - the locale context resolver to use

### getLocaleContextResolver

public LocaleContextResolver getLocaleContextResolver()
Return the configured `LocaleContextResolver`.

### setForwardedHeaderTransformer

public void setForwardedHeaderTransformer(@Nullable ForwardedHeaderTransformer transformer)
Enable processing of forwarded headers, either extracting and removing, or remove only.

By default this is not set.

Parameters:
  `transformer` - the transformer to use
Since:
  5.1

### getForwardedHeaderTransformer

@Nullable public ForwardedHeaderTransformer getForwardedHeaderTransformer()
Return the configured `ForwardedHeaderTransformer`.

Since:
  5.1

### setObservationRegistry

public void setObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)
Configure an `ObservationRegistry` for recording server exchange observations. By default, a `no-op` instance will be used.

Parameters:
  `observationRegistry` - the observation registry to use
Since:
  6.1

### getObservationRegistry

public io.micrometer.observation.ObservationRegistry getObservationRegistry()
Return the configured `ObservationRegistry`.

Since:
  6.1

### setObservationConvention

public void setObservationConvention(ServerRequestObservationConvention observationConvention)
Configure a `ServerRequestObservationConvention` for server exchanges observations. By default, a `DefaultServerRequestObservationConvention` instance will be used.

Parameters:
  `observationConvention` - the observation convention to use
Since:
  6.1

### getObservationConvention

public ServerRequestObservationConvention getObservationConvention()
Return the Observation convention configured for server exchanges observations.

Since:
  6.1

### setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
Configure the `ApplicationContext` associated with the web application, if it was initialized with one via `WebHttpHandlerBuilder.applicationContext(ApplicationContext)`.

Parameters:
  `applicationContext` - the context
Since:
  5.0.3

### getApplicationContext

@Nullable public org.springframework.context.ApplicationContext getApplicationContext()
Return the configured `ApplicationContext`, if any.

Since:
  5.0.3

### afterPropertiesSet

public void afterPropertiesSet()
This method must be invoked after all properties have been set to complete initialization.

### handle

public reactor.core.publisher.Mono<Void> handle(ServerHttpRequest request, ServerHttpResponse response)
Description copied from interface: `HttpHandler`
Handle the given request and write to the response.

Specified by:
  `handle` in interface `HttpHandler`
Parameters:
  `request` - current request
  `response` - current response
Returns:
  indicates completion of request handling

### createExchange

protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response)

### formatRequest

protected String formatRequest(ServerHttpRequest request)
Format the request for logging purposes including HTTP method and URL.

By default this prints the HTTP method, the URL path, and the query.

Parameters:
  `request` - the request to format
Returns:
  the String to display, never empty or `null`