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

pack-priv Class UndertowServerHttpResponse

extends AbstractListenerServerHttpResponse
implements ZeroCopyHttpOutputMessage
Class Inheritance
All Implemented Interfaces
org.springframework.http.ZeroCopyHttpOutputMessage, org.springframework.http.ReactiveHttpOutputMessage, org.springframework.http.HttpMessage
Imports
java.io.IOException, java.nio.ByteBuffer, java.nio.channels.FileChannel, java.nio.file.Path, .StandardOpenOption, io.undertow.server.HttpServerExchange, io.undertow.server.handlers.Cookie, .CookieImpl, org.reactivestreams.Processor, .Publisher, org.xnio.channels.StreamSinkChannel, reactor.core.publisher.Mono, .MonoSink, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.http.HttpHeaders, .HttpStatusCode, .ResponseCookie, .ZeroCopyHttpOutputMessage, org.springframework.lang.Nullable, org.springframework.util.Assert

Adapt ServerHttpResponse to the Undertow HttpServerExchange.
Authors
Marek Hawrylczak, Rossen Stoyanchev, Arjen Poutsma, Juergen Hoeller
Since
5.0

Nested and Inner Type Summary

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

Field Summary

Modifier and TypeField and Description
private final HttpServerExchange
private final UndertowServerHttpRequest
private StreamSinkChannel

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
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 UndertowServerHttpResponse.ResponseBodyProcessor
private static HttpHeaders
public <T> T
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.

public Mono<Void>
writeWith(Path
the file to transfer
file
,
long
the position within the file from which the transfer is to begin
position
,
long
the number of bytes to be transferred
count
)

Implements org.springframework.http.ZeroCopyHttpOutputMessage.writeWith.

Use the given Path to write the body of the message to the underlying HTTP layer.

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

Field Detail

exchangeback to summary
private final HttpServerExchange exchange
requestback to summary
private final UndertowServerHttpRequest request
responseChannelback to summary
private StreamSinkChannel responseChannel
Annotations
@Nullable

Constructor Detail

UndertowServerHttpResponseback to summary
pack-priv UndertowServerHttpResponse(HttpServerExchange exchange, DataBufferFactory bufferFactory, UndertowServerHttpRequest request)

Method Detail

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
createBodyProcessorback to summary
private UndertowServerHttpResponse.ResponseBodyProcessor createBodyProcessor()
createHeadersback to summary
private static HttpHeaders createHeaders(HttpServerExchange exchange)
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
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
writeWithback to summary
public Mono<Void> writeWith(Path file, long position, long count)

Implements org.springframework.http.ZeroCopyHttpOutputMessage.writeWith.

Doc from org.springframework.http.ZeroCopyHttpOutputMessage.writeWith.

Use the given Path to write the body of the message to the underlying HTTP layer.

Parameters
file:Path

the file to transfer

position:long

the position within the file from which the transfer is to begin

count:long

the number of bytes to be transferred

Returns:Mono<Void>

a publisher that indicates completion or error.

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

private Class UndertowServerHttpResponse.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 UndertowServerHttpResponse.ResponseBodyProcessor

extends AbstractListenerWriteProcessor<DataBuffer>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private volatile ByteBuffer
private final StreamSinkChannel
private volatile boolean
writePossible

Keep track of write listener calls, for writePossible.

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

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
dataReceived(DataBuffer dataBuffer)

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

Template method invoked after a data item to write is received via Subscriber#onNext(Object).

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.

private int
protected void
protected void
Inherited from org.springframework.http.server.reactive.AbstractListenerWriteProcessor:
cancelcancelAndSetCompletedgetLogPrefixonCompleteonErroronNextonSubscribeonWritePossiblesubscribewritingPaused

Field Detail

byteBufferback to summary
private volatile ByteBuffer byteBuffer
Annotations
@Nullable
channelback to summary
private final StreamSinkChannel channel
writePossibleback to summary
private volatile boolean writePossible

Keep track of write listener calls, for writePossible.

Constructor Detail

ResponseBodyProcessorback to summary
public ResponseBodyProcessor(StreamSinkChannel channel)

Method Detail

dataReceivedback to summary
protected void dataReceived(DataBuffer dataBuffer)

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

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

Template method invoked after a data item to write is received via Subscriber#onNext(Object). The default implementation saves the data item for writing once that is possible.

Annotations
@Override
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
writeByteBufferback to summary
private int writeByteBuffer(ByteBuffer byteBuffer) throws IOException
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
writingFailedback to summary
protected void writingFailed(Throwable ex)

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

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

Invoked when an I/O error occurs during a write. Subclasses may choose to ignore this if they know the underlying API will provide an error notification in a container thread.

Defaults to no-op.

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

private Class UndertowServerHttpResponse.TransferBodyListener

extends Object
Class Inheritance
  • java.lang.Object
  • org.springframework.http.server.reactive.UndertowServerHttpResponse.TransferBodyListener

Field Summary

Modifier and TypeField and Description
private long
private long
private final MonoSink<Void>
private final FileChannel

Constructor Summary

AccessConstructor and Description
public
TransferBodyListener(FileChannel source, long position, long count, MonoSink<Void> sink)

Method Summary

Modifier and TypeMethod and Description
public void
public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

countback to summary
private long count
positionback to summary
private long position
sinkback to summary
private final MonoSink<Void> sink
sourceback to summary
private final FileChannel source

Constructor Detail

TransferBodyListenerback to summary
public TransferBodyListener(FileChannel source, long position, long count, MonoSink<Void> sink)

Method Detail

closeSourceback to summary
public void closeSource()
transferback to summary
public void transfer(StreamSinkChannel destination)