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

pack-priv Class ServletServerHttpResponse

extends AbstractListenerServerHttpResponse
Class Inheritance
Known Direct Subclasses
org.springframework.http.server.reactive.TomcatHttpHandlerAdapter.TomcatServerHttpResponse, org.springframework.http.server.reactive.JettyHttpHandlerAdapter.Jetty12ServerHttpResponse
Imports
java.io.IOException, .InputStream, java.nio.charset.Charset, jakarta.servlet.AsyncContext, .AsyncEvent, .AsyncListener, .ServletOutputStream, .WriteListener, jakarta.servlet.http.Cookie, .HttpServletResponse, org.reactivestreams.Processor, .Publisher, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.http.HttpHeaders, .HttpStatusCode, .MediaType, .ResponseCookie, org.springframework.lang.Nullable, org.springframework.util.Assert

Adapt ServerHttpResponse to the Servlet HttpServletResponse.
Authors
Rossen Stoyanchev, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class
private class

Field Summary

Modifier and TypeField and Description
private final ServletServerHttpResponse.ResponseAsyncListener
private volatile ServletServerHttpResponse.ResponseBodyFlushProcessor
private volatile ServletServerHttpResponse.ResponseBodyProcessor
private final int
private volatile boolean
private final ServletOutputStream
private final ServletServerHttpRequest
private final HttpServletResponse

Constructor Summary

AccessConstructor and Description
public
ServletServerHttpResponse(HttpServletResponse response, AsyncContext asyncContext, DataBufferFactory bufferFactory, int bufferSize, ServletServerHttpRequest request)

public
ServletServerHttpResponse(HttpHeaders headers, HttpServletResponse response, AsyncContext asyncContext, DataBufferFactory bufferFactory, int bufferSize, ServletServerHttpRequest request)

Method Summary

Modifier and TypeMethod and Description
protected void
adaptHeaders(boolean removeAdaptedHeaders)

protected void
applyCookies()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.applyCookies.

Add cookies from getHeaders() to the underlying response.
protected void
applyHeaders()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.applyHeaders.

Invoked when the response is getting committed allowing subclasses to make apply header values to the underlying response.
protected void
applyStatusCode()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.applyStatusCode.

Write the status code to the underlying response.
protected Processor<? super Publisher<? extends DataBuffer>, Void>
createBodyFlushProcessor()

Implements abstract org.springframework.http.server.reactive.AbstractListenerServerHttpResponse.createBodyFlushProcessor.

Abstract template method to create a Processor<Publisher<DataBuffer>, Void> that will write the response body with flushes to the underlying output.
private void
pack-priv AsyncListener
getAsyncListener()

Return an ResponseAsyncListener that notifies the response body Publisher and Subscriber of Servlet container events.

public <T> T
protected final ServletOutputStream
getOutputStream()

Return the ServletOutputStream for the current response.

public Integer
getRawStatusCode()

Overrides org.springframework.http.server.reactive.AbstractServerHttpResponse.getRawStatusCode.

Overrides default org.springframework.http.server.reactive.ServerHttpResponse.getRawStatusCode.

Deprecated
Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server.
public HttpStatusCode
getStatusCode()

Overrides org.springframework.http.server.reactive.AbstractServerHttpResponse.getStatusCode.

Implements org.springframework.http.server.reactive.ServerHttpResponse.getStatusCode.

Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server.
private boolean
protected int

Returns:

the number of bytes written
writeToOutputStream
(DataBuffer dataBuffer)

Write the DataBuffer to the response body OutputStream.

Inherited from org.springframework.http.server.reactive.AbstractListenerServerHttpResponse:
writeAndFlushWithInternalwriteWithInternal

Field Detail

asyncListenerback to summary
private final ServletServerHttpResponse.ResponseAsyncListener asyncListener
bodyFlushProcessorback to summary
private volatile ServletServerHttpResponse.ResponseBodyFlushProcessor bodyFlushProcessor
Annotations
@Nullable
bodyProcessorback to summary
private volatile ServletServerHttpResponse.ResponseBodyProcessor bodyProcessor
Annotations
@Nullable
bufferSizeback to summary
private final int bufferSize
flushOnNextback to summary
private volatile boolean flushOnNext
outputStreamback to summary
private final ServletOutputStream outputStream
requestback to summary
private final ServletServerHttpRequest request
responseback to summary
private final HttpServletResponse response

Constructor Detail

ServletServerHttpResponseback to summary
public ServletServerHttpResponse(HttpServletResponse response, AsyncContext asyncContext, DataBufferFactory bufferFactory, int bufferSize, ServletServerHttpRequest request) throws IOException
ServletServerHttpResponseback to summary
public ServletServerHttpResponse(HttpHeaders headers, HttpServletResponse response, AsyncContext asyncContext, DataBufferFactory bufferFactory, int bufferSize, ServletServerHttpRequest request) throws IOException

Method Detail

adaptHeadersback to summary
protected void adaptHeaders(boolean removeAdaptedHeaders)
applyCookiesback to summary
protected void applyCookies()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.applyCookies.

Doc from org.springframework.http.server.reactive.AbstractServerHttpResponse.applyCookies.

Add cookies from getHeaders() to the underlying response. This method is called once only.

Annotations
@Override
applyHeadersback to summary
protected void applyHeaders()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.applyHeaders.

Doc from org.springframework.http.server.reactive.AbstractServerHttpResponse.applyHeaders.

Invoked when the response is getting committed allowing subclasses to make apply header values to the underlying response.

Note that some subclasses use an HttpHeaders instance that wraps an adapter to the native response headers such that changes are propagated to the underlying response on the go. That means this callback might not be used other than for specialized updates such as setting the contentType or characterEncoding fields in a Servlet response.

Annotations
@Override
applyStatusCodeback to summary
protected void applyStatusCode()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.applyStatusCode.

Doc from org.springframework.http.server.reactive.AbstractServerHttpResponse.applyStatusCode.

Write the status code to the underlying response. This method is called once only.

Annotations
@Override
createBodyFlushProcessorback to summary
protected Processor<? super Publisher<? extends DataBuffer>, Void> createBodyFlushProcessor()

Implements abstract org.springframework.http.server.reactive.AbstractListenerServerHttpResponse.createBodyFlushProcessor.

Doc from org.springframework.http.server.reactive.AbstractListenerServerHttpResponse.createBodyFlushProcessor.

Abstract template method to create a Processor<Publisher<DataBuffer>, Void> that will write the response body with flushes to the underlying output. Called from writeAndFlushWithInternal(Publisher).

Annotations
@Override
flushback to summary
private void flush() throws IOException
getAsyncListenerback to summary
pack-priv AsyncListener getAsyncListener()

Return an ResponseAsyncListener that notifies the response body Publisher and Subscriber of Servlet container events. The listener is not actually registered but is rather exposed for ServletHttpHandlerAdapter to ensure events are delegated.

getNativeResponseback to summary
public <T> T getNativeResponse()

Implements abstract org.springframework.http.server.reactive.AbstractServerHttpResponse.getNativeResponse.

Doc from org.springframework.http.server.reactive.AbstractServerHttpResponse.getNativeResponse.

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
getOutputStreamback to summary
protected final ServletOutputStream getOutputStream()

Return the ServletOutputStream for the current response.

getRawStatusCodeback to summary
public Integer getRawStatusCode()

Overrides org.springframework.http.server.reactive.AbstractServerHttpResponse.getRawStatusCode.

Overrides default org.springframework.http.server.reactive.ServerHttpResponse.getRawStatusCode.

Doc from org.springframework.http.server.reactive.ServerHttpResponse.getRawStatusCode.

Deprecated

Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server. The return value may be null if there is no default value from the underlying server.

Annotations
@Override
@Deprecated
getStatusCodeback to summary
public HttpStatusCode getStatusCode()

Overrides org.springframework.http.server.reactive.AbstractServerHttpResponse.getStatusCode.

Implements org.springframework.http.server.reactive.ServerHttpResponse.getStatusCode.

Doc from org.springframework.http.server.reactive.ServerHttpResponse.getStatusCode.

Return the status code that has been set, or otherwise fall back on the status of the response from the underlying server. The return value may be null if there is no default value from the underlying server.

Annotations
@Override
isWritePossibleback to summary
private boolean isWritePossible()
writeToOutputStreamback to summary
protected int writeToOutputStream(DataBuffer dataBuffer) throws IOException

Write the DataBuffer to the response body OutputStream. Invoked only when ServletOutputStream#isReady() returns "true" and the readable bytes in the DataBuffer is greater than 0.

Returns:int

the number of bytes written

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

private final Class ServletServerHttpResponse.ResponseAsyncListener

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

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
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

ResponseAsyncListenerback to summary
private ResponseAsyncListener()

Method Detail

handleErrorback to summary
public void handleError(Throwable ex)
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 ServletServerHttpResponse.ResponseBodyFlushProcessor

extends AbstractListenerWriteFlushProcessor<DataBuffer>
Class Inheritance

Field Summary

Inherited from org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor:
rsWriteFlushLogger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected Processor<? super DataBuffer, Void>
createWriteProcessor()

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.createWriteProcessor.

Create a new processor for the current flush boundary.
protected void
flush()

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.flush.

Flush the output if ready, or otherwise isFlushPending() should return true after.
protected boolean
protected boolean
Inherited from org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor:
cancelflushingFailedgetLogPrefixonCompleteonErroronFlushPossibleonNextonSubscribesubscribe

Constructor Detail

ResponseBodyFlushProcessorback to summary
public ResponseBodyFlushProcessor()

Method Detail

createWriteProcessorback to summary
protected Processor<? super DataBuffer, Void> createWriteProcessor()

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.createWriteProcessor.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.createWriteProcessor.

Create a new processor for the current flush boundary.

Annotations
@Override
flushback to summary
protected void flush() throws IOException

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.flush.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.flush.

Flush the output if ready, or otherwise isFlushPending() should return true after.

This is primarily for the Servlet non-blocking I/O API where flush cannot be called without a readyToWrite check.

Annotations
@Override
isFlushPendingback to summary
protected boolean isFlushPending()

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.isFlushPending.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.isFlushPending.

Whether flushing is pending.

This is primarily for the Servlet non-blocking I/O API where flush cannot be called without a readyToWrite check.

Annotations
@Override
isWritePossibleback to summary
protected boolean isWritePossible()

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.isWritePossible.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteFlushProcessor.isWritePossible.

Whether writing/flushing is possible.

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

private Class ServletServerHttpResponse.ResponseBodyProcessor

extends AbstractListenerWriteProcessor<DataBuffer>
Class Inheritance

Field Summary

Inherited from org.springframework.http.server.reactive.AbstractListenerWriteProcessor:
rsWriteLogger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
discardData(DataBuffer
the data to be released
dataBuffer
)

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

Invoked after any error (either from the upstream write Publisher, or from I/O operations to the underlying server) and cancellation to discard in-flight data that was in the process of being written when the error took place.
protected boolean
isDataEmpty(DataBuffer dataBuffer)

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteProcessor.isDataEmpty.

Whether the given data item has any content to write.
protected boolean
protected boolean
write(DataBuffer
the item to write
dataBuffer
)

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteProcessor.write.

Write the given item.
protected void
Inherited from org.springframework.http.server.reactive.AbstractListenerWriteProcessor:
cancelcancelAndSetCompleteddataReceivedgetLogPrefixonCompleteonErroronNextonSubscribeonWritePossiblesubscribewritingFailedwritingPaused

Constructor Detail

ResponseBodyProcessorback to summary
public ResponseBodyProcessor()

Method Detail

discardDataback to summary
protected void discardData(DataBuffer dataBuffer)

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

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

Invoked after any error (either from the upstream write Publisher, or from I/O operations to the underlying server) and cancellation to discard in-flight data that was in the process of being written when the error took place.

Parameters
dataBuffer:DataBuffer

the data to be released

Annotations
@Override
isDataEmptyback to summary
protected boolean isDataEmpty(DataBuffer dataBuffer)

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteProcessor.isDataEmpty.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteProcessor.isDataEmpty.

Whether the given data item has any content to write. If false the item is not written.

Annotations
@Override
isWritePossibleback to summary
protected boolean isWritePossible()

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteProcessor.isWritePossible.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteProcessor.isWritePossible.

Whether writing is possible.

Annotations
@Override
writeback to summary
protected boolean write(DataBuffer dataBuffer) throws IOException

Implements abstract org.springframework.http.server.reactive.AbstractListenerWriteProcessor.write.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteProcessor.write.

Write the given item.

Note

Sub-classes are responsible for releasing any data buffer associated with the item, once fully written, if pooled buffers apply to the underlying container.

Parameters
dataBuffer:DataBuffer

the item to write

Returns:boolean

true if the current data item was written completely and a new item requested, or false if it was written partially and we'll need more write callbacks before it is fully written

Annotations
@Override
writingCompleteback to summary
protected void writingComplete()

Overrides org.springframework.http.server.reactive.AbstractListenerWriteProcessor.writingComplete.

Doc from org.springframework.http.server.reactive.AbstractListenerWriteProcessor.writingComplete.

Invoked after onComplete or onError notification.

The default implementation is a no-op.

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

private Class ServletServerHttpResponse.ResponseBodyWriteListener

extends Object
implements WriteListener
Class Inheritance
  • java.lang.Object
  • org.springframework.http.server.reactive.ServletServerHttpResponse.ResponseBodyWriteListener
All Implemented Interfaces
jakarta.servlet.WriteListener, java.util.EventListener

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
onError(Throwable
The throwable that represents the error that occurred
ex
)

Implements jakarta.servlet.WriteListener.onError.

Invoked if an error occurs while writing the response.
public void
onWritePossible()

Implements jakarta.servlet.WriteListener.onWritePossible.

Invoked when it it possible to write data without blocking.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ResponseBodyWriteListenerback to summary
private ResponseBodyWriteListener()

Method Detail

onErrorback to summary
public void onError(Throwable ex)

Implements jakarta.servlet.WriteListener.onError.

Doc from jakarta.servlet.WriteListener.onError.

Invoked if an error occurs while writing the response.

Parameters
ex:Throwable

The throwable that represents the error that occurred

Annotations
@Override
onWritePossibleback to summary
public void onWritePossible()

Implements jakarta.servlet.WriteListener.onWritePossible.

Doc from jakarta.servlet.WriteListener.onWritePossible.

Invoked when it it possible to write data without blocking. The container will invoke this method the first time for a request as soon as data can be written. Subsequent invocations will only occur if a call to ServletOutputStream#isReady() has returned false and it has since become possible to write data.

Annotations
@Override