Top Description Inners Fields Constructors Methods
org.springframework.http.server.reactive

pack-priv Class ServletServerHttpRequest

extends AbstractServerHttpRequest
Class Inheritance
Known Direct Subclasses
org.springframework.http.server.reactive.TomcatHttpHandlerAdapter.TomcatServerHttpRequest
Imports
java.io.IOException, java.net.InetSocketAddress, .URI, .URISyntaxException, java.nio.charset.Charset, java.security.cert.X509Certificate, java.util.Enumeration, .Locale, .Map, jakarta.servlet.AsyncContext, .AsyncEvent, .AsyncListener, .ReadListener, .ServletInputStream, jakarta.servlet.http.Cookie, .HttpServletRequest, org.apache.commons.logging.Log, reactor.core.publisher.Flux, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DefaultDataBufferFactory, org.springframework.http.HttpCookie, .HttpHeaders, .HttpMethod, .MediaType, org.springframework.lang.NonNull, .Nullable, org.springframework.util.Assert, .CollectionUtils, .LinkedCaseInsensitiveMap, .LinkedMultiValueMap, .MultiValueMap, .StringUtils

Adapt ServerHttpRequest to the Servlet HttpServletRequest.
Authors
Rossen Stoyanchev, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final AsyncListener
private final ServletServerHttpRequest.RequestBodyPublisher
private final byte[]
private final DataBufferFactory
private final Object
pack-priv static final DataBuffer
private final ServletInputStream
private final HttpServletRequest

Constructor Summary

AccessConstructor and Description
public
ServletServerHttpRequest(HttpServletRequest request, AsyncContext asyncContext, String servletPath, DataBufferFactory bufferFactory, int bufferSize)

public
ServletServerHttpRequest(MultiValueMap<String, String> headers, HttpServletRequest request, AsyncContext asyncContext, String servletPath, DataBufferFactory bufferFactory, int bufferSize)

Method Summary

Modifier and TypeMethod and Description
private static MultiValueMap<String, String>
pack-priv AsyncListener
getAsyncListener()

Return an RequestAsyncListener that completes the request body Publisher when the Servlet container notifies that request input has ended.

public Flux<DataBuffer>
getBody()

Implements org.springframework.http.ReactiveHttpInputMessage.getBody.

Return the body of the message as a Publisher.

protected final ServletInputStream
getInputStream()

Return the ServletInputStream for the current response.

public InetSocketAddress
getLocalAddress()

Overrides default org.springframework.http.server.reactive.ServerHttpRequest.getLocalAddress.

Return the local address the request was accepted on, if available.

public <T> T
public InetSocketAddress
getRemoteAddress()

Overrides default org.springframework.http.server.reactive.ServerHttpRequest.getRemoteAddress.

Return the remote address where this request is connected to, if available.

private String
private X509Certificate[]
protected MultiValueMap<String, HttpCookie>
initCookies()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpRequest.initCookies.

Obtain the cookies from the underlying "native" request and adapt those to an HttpCookie map.

private static MultiValueMap<String, String>
protected SslInfo
initSslInfo()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpRequest.initSslInfo.

Obtain SSL session information from the underlying "native" request.

private static URI
protected final void
logBytesRead(int read)

pack-priv DataBuffer

Returns:

a DataBuffer with data read, or AbstractListenerReadPublisher#EMPTY_BUFFER if 0 bytes were read, or EOF_BUFFER if the input stream returned -1.
readFromInputStream
()

Read from the request body InputStream and return a DataBuffer.

Inherited from org.springframework.http.server.reactive.AbstractServerHttpRequest:
getCookiesgetHeadersgetIdgetLogPrefixgetMethodgetPathgetQueryParamsgetSslInfogetURIinitIdinitLogPrefixinitQueryParams

Field Detail

asyncListenerback to summary
private final AsyncListener asyncListener
bodyPublisherback to summary
private final ServletServerHttpRequest.RequestBodyPublisher bodyPublisher
bufferback to summary
private final byte[] buffer
bufferFactoryback to summary
private final DataBufferFactory bufferFactory
cookieLockback to summary
private final Object cookieLock
EOF_BUFFERback to summary
pack-priv static final DataBuffer EOF_BUFFER
inputStreamback to summary
private final ServletInputStream inputStream
requestback to summary
private final HttpServletRequest request

Constructor Detail

ServletServerHttpRequestback to summary
public ServletServerHttpRequest(HttpServletRequest request, AsyncContext asyncContext, String servletPath, DataBufferFactory bufferFactory, int bufferSize) throws IOException, URISyntaxException
ServletServerHttpRequestback to summary
public ServletServerHttpRequest(MultiValueMap<String, String> headers, HttpServletRequest request, AsyncContext asyncContext, String servletPath, DataBufferFactory bufferFactory, int bufferSize) throws IOException, URISyntaxException

Method Detail

createDefaultHttpHeadersback to summary
private static MultiValueMap<String, String> createDefaultHttpHeaders(HttpServletRequest request)
getAsyncListenerback to summary
pack-priv AsyncListener getAsyncListener()

Return an RequestAsyncListener that completes the request body Publisher when the Servlet container notifies that request input has ended. The listener is not actually registered but is rather exposed for ServletHttpHandlerAdapter to ensure events are delegated.

getBodyback to summary
public Flux<DataBuffer> getBody()

Implements org.springframework.http.ReactiveHttpInputMessage.getBody.

Doc from org.springframework.http.ReactiveHttpInputMessage.getBody.

Return the body of the message as a Publisher.

Returns:Flux<DataBuffer>

the body content publisher

Annotations
@Override
getInputStreamback to summary
protected final ServletInputStream getInputStream()

Return the ServletInputStream for the current response.

getLocalAddressback to summary
public InetSocketAddress getLocalAddress()

Overrides default org.springframework.http.server.reactive.ServerHttpRequest.getLocalAddress.

Doc from org.springframework.http.server.reactive.ServerHttpRequest.getLocalAddress.

Return the local address the request was accepted on, if available.

Annotations
@Override
@NonNull
getNativeRequestback to summary
public <T> T getNativeRequest()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpRequest.getNativeRequest.

Doc from org.springframework.http.server.reactive.AbstractServerHttpRequest.getNativeRequest.

Return the underlying server response.

Note

This is exposed mainly for internal framework use such as WebSocket upgrades in the spring-webflux module.

Annotations
@SuppressWarnings:unchecked
@Override
getRemoteAddressback to summary
public InetSocketAddress getRemoteAddress()

Overrides default org.springframework.http.server.reactive.ServerHttpRequest.getRemoteAddress.

Doc from org.springframework.http.server.reactive.ServerHttpRequest.getRemoteAddress.

Return the remote address where this request is connected to, if available.

Annotations
@Override
@NonNull
getSslSessionIdback to summary
private String getSslSessionId()
Annotations
@Nullable
getX509Certificatesback to summary
private X509Certificate[] getX509Certificates()
Annotations
@Nullable
initCookiesback to summary
protected MultiValueMap<String, HttpCookie> initCookies()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpRequest.initCookies.

Doc from org.springframework.http.server.reactive.AbstractServerHttpRequest.initCookies.

Obtain the cookies from the underlying "native" request and adapt those to an HttpCookie map. The return value is turned into an immutable map and cached.

Note that this method is invoked lazily on access to getCookies(). Subclasses should synchronize cookie initialization if the underlying "native" request does not provide thread-safe access to cookie data.

Annotations
@Override
initHeadersback to summary
private static MultiValueMap<String, String> initHeaders(MultiValueMap<String, String> headerValues, HttpServletRequest request)
initSslInfoback to summary
protected SslInfo initSslInfo()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpRequest.initSslInfo.

Doc from org.springframework.http.server.reactive.AbstractServerHttpRequest.initSslInfo.

Obtain SSL session information from the underlying "native" request.

Returns:SslInfo

the session information, or null if none available

Annotations
@Override
@Nullable
initUriback to summary
private static URI initUri(HttpServletRequest request) throws URISyntaxException
logBytesReadback to summary
protected final void logBytesRead(int read)
readFromInputStreamback to summary
pack-priv DataBuffer readFromInputStream() throws IOException

Read from the request body InputStream and return a DataBuffer. Invoked only when ServletInputStream#isReady() returns "true".

Returns:DataBuffer

a DataBuffer with data read, or AbstractListenerReadPublisher#EMPTY_BUFFER if 0 bytes were read, or EOF_BUFFER if the input stream returned -1.

org.springframework.http.server.reactive back to summary

private final Class ServletServerHttpRequest.RequestAsyncListener

extends Object
implements AsyncListener
Class Inheritance
  • java.lang.Object
  • org.springframework.http.server.reactive.ServletServerHttpRequest.RequestAsyncListener
All Implemented Interfaces
jakarta.servlet.AsyncListener, java.util.EventListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
onComplete(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onComplete.

This event is fired after the call to AsyncContext#complete() has been processed by the container.

public void
onError(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onError.

This event is fired if an error occurs during an asynchronous operation but before the container takes any action as a result of the error.

public void
onStartAsync(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onStartAsync.

This event is fired if new call is made to ServletRequest#startAsync() after the completion of the AsyncContext to which this listener was added.

public void
onTimeout(AsyncEvent
Provides access to the objects associated with the event
event
)

Implements jakarta.servlet.AsyncListener.onTimeout.

This event is fired if an asynchronous operation times out but before the container takes any action as a result of the timeout.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RequestAsyncListenerback to summary
private RequestAsyncListener()

Method Detail

onCompleteback to summary
public void onComplete(AsyncEvent event)

Implements jakarta.servlet.AsyncListener.onComplete.

Doc from jakarta.servlet.AsyncListener.onComplete.

This event is fired after the call to AsyncContext#complete() has been processed by the container.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
onErrorback to summary
public void onError(AsyncEvent event)

Implements jakarta.servlet.AsyncListener.onError.

Doc from jakarta.servlet.AsyncListener.onError.

This event is fired if an error occurs during an asynchronous operation but before the container takes any action as a result of the error.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
onStartAsyncback to summary
public void onStartAsync(AsyncEvent event)

Implements jakarta.servlet.AsyncListener.onStartAsync.

Doc from jakarta.servlet.AsyncListener.onStartAsync.

This event is fired if new call is made to ServletRequest#startAsync() after the completion of the AsyncContext to which this listener was added.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
onTimeoutback to summary
public void onTimeout(AsyncEvent event)

Implements jakarta.servlet.AsyncListener.onTimeout.

Doc from jakarta.servlet.AsyncListener.onTimeout.

This event is fired if an asynchronous operation times out but before the container takes any action as a result of the timeout.

Parameters
event:AsyncEvent

Provides access to the objects associated with the event

Annotations
@Override
org.springframework.http.server.reactive back to summary

private Class ServletServerHttpRequest.RequestBodyPublisher

extends AbstractListenerReadPublisher<DataBuffer>
Class Inheritance

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final ServletInputStream
Inherited from org.springframework.http.server.reactive.AbstractListenerReadPublisher:
EMPTY_BUFFERrsReadLogger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
checkOnDataAvailable()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.checkOnDataAvailable.

Check if data is available and either call onDataAvailable() immediately or schedule a notification.

protected void
discardData()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.discardData.

Invoked after an I/O read error from the underlying server or after a cancellation signal from the downstream consumer to allow subclasses to discard any current cached data they might have.

protected DataBuffer
read()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.read.

Read once from the input, if possible.

protected void
readingPaused()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.readingPaused.

Invoked when reading is paused due to a lack of demand.

public void
Inherited from org.springframework.http.server.reactive.AbstractListenerReadPublisher:
getLogPrefixonAllDataReadonDataAvailableonErrorsubscribe

Field Detail

inputStreamback to summary
private final ServletInputStream inputStream

Constructor Detail

RequestBodyPublisherback to summary
public RequestBodyPublisher(ServletInputStream inputStream)

Method Detail

checkOnDataAvailableback to summary
protected void checkOnDataAvailable()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.checkOnDataAvailable.

Doc from org.springframework.http.server.reactive.AbstractListenerReadPublisher.checkOnDataAvailable.

Check if data is available and either call onDataAvailable() immediately or schedule a notification.

Annotations
@Override
discardDataback to summary
protected void discardData()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.discardData.

Doc from org.springframework.http.server.reactive.AbstractListenerReadPublisher.discardData.

Invoked after an I/O read error from the underlying server or after a cancellation signal from the downstream consumer to allow subclasses to discard any current cached data they might have.

Annotations
@Override
readback to summary
protected DataBuffer read() throws IOException

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.read.

Doc from org.springframework.http.server.reactive.AbstractListenerReadPublisher.read.

Read once from the input, if possible.

Returns:DataBuffer

the item that was read; or null

Annotations
@Override
@Nullable
readingPausedback to summary
protected void readingPaused()

Implements abstract org.springframework.http.server.reactive.AbstractListenerReadPublisher.readingPaused.

Doc from org.springframework.http.server.reactive.AbstractListenerReadPublisher.readingPaused.

Invoked when reading is paused due to a lack of demand.

Note

This method is guaranteed not to compete with checkOnDataAvailable() so it can be used to safely suspend reading, if the underlying API supports it, i.e. without competing with an implicit call to resume via checkOnDataAvailable().

Annotations
@Override
registerReadListenerback to summary
public void registerReadListener() throws IOException
org.springframework.http.server.reactive back to summary

private Class ServletServerHttpRequest.RequestBodyPublisher.RequestBodyPublisherReadListener

extends Object
implements ReadListener
Class Inheritance
  • java.lang.Object
  • org.springframework.http.server.reactive.ServletServerHttpRequest.RequestBodyPublisher.RequestBodyPublisherReadListener
All Implemented Interfaces
jakarta.servlet.ReadListener, java.util.EventListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
onAllDataRead()

Implements jakarta.servlet.ReadListener.onAllDataRead.

Invoked when the request body has been fully read.

public void
onDataAvailable()

Implements jakarta.servlet.ReadListener.onDataAvailable.

Invoked when data is available to read.

public void
onError(Throwable
The exception that occurred
throwable
)

Implements jakarta.servlet.ReadListener.onError.

Invoked if an error occurs while reading the request body.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RequestBodyPublisherReadListenerback to summary
private RequestBodyPublisherReadListener()

Method Detail

onAllDataReadback to summary
public void onAllDataRead() throws IOException

Implements jakarta.servlet.ReadListener.onAllDataRead.

Doc from jakarta.servlet.ReadListener.onAllDataRead.

Invoked when the request body has been fully read.

Annotations
@Override
Exceptions
IOException:
id an I/O error occurs while processing the event
onDataAvailableback to summary
public void onDataAvailable() throws IOException

Implements jakarta.servlet.ReadListener.onDataAvailable.

Doc from jakarta.servlet.ReadListener.onDataAvailable.

Invoked when data is available to read. The container will invoke this method the first time for a request as soon as there is data to read. Subsequent invocations will only occur if a call to ServletInputStream#isReady() has returned false and data has subsequently become available to read.

Annotations
@Override
Exceptions
IOException:
id an I/O error occurs while processing the event
onErrorback to summary
public void onError(Throwable throwable)

Implements jakarta.servlet.ReadListener.onError.

Doc from jakarta.servlet.ReadListener.onError.

Invoked if an error occurs while reading the request body.

Parameters
throwable:Throwable

The exception that occurred

Annotations
@Override