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

public abstract Class AbstractServerHttpResponse

extends Object
implements ServerHttpResponse
Class Inheritance
All Implemented Interfaces
org.springframework.http.server.reactive.ServerHttpResponse, org.springframework.http.ReactiveHttpOutputMessage, org.springframework.http.HttpMessage
Known Direct Subclasses
org.springframework.http.server.reactive.ReactorNetty2ServerHttpResponse, org.springframework.http.server.reactive.ReactorServerHttpResponse, org.springframework.http.server.reactive.AbstractListenerServerHttpResponse
Imports
java.util.List, java.util.concurrent.CopyOnWriteArrayList, java.util.concurrent.atomic.AtomicBoolean, .AtomicReference, java.util.function.Supplier, org.reactivestreams.Publisher, reactor.core.publisher.Flux, .Mono, org.springframework.core.io.buffer.DataBuffer, .DataBufferFactory, .DataBufferUtils, org.springframework.http.HttpHeaders, .HttpStatusCode, .ResponseCookie, org.springframework.lang.Nullable, org.springframework.util.Assert, .CollectionUtils, .LinkedMultiValueMap, .MultiValueMap

Base class for ServerHttpResponse implementations.
Authors
Rossen Stoyanchev, Juergen Hoeller, Sebastien Deleuze, Brian Clozel
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
AbstractServerHttpResponse.State

COMMITTING -> COMMITTED is the period after doCommit is called but before the response status and headers have been applied to the underlying response during which time pre-commit actions can still make changes to the response status and headers.

Field Summary

Modifier and TypeField and Description
private final List<Supplier<? extends Mono<Void>>>
private final MultiValueMap<String, ResponseCookie>
private final DataBufferFactory
private final HttpHeaders
private HttpHeaders
private final AtomicReference<AbstractServerHttpResponse.State>
private HttpStatusCode

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public void
addCookie(ResponseCookie
the cookie to add
cookie
)

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

Add the given ResponseCookie.

protected abstract void
applyCookies()

Add cookies from getHeaders() to the underlying response.

protected abstract void
applyHeaders()

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

protected abstract void
applyStatusCode()

Write the status code to the underlying response.

public void
beforeCommit(Supplier<? extends Mono<Void>>
the action to apply
action
)

Implements org.springframework.http.ReactiveHttpOutputMessage.beforeCommit.

Register an action to apply just before the HttpOutputMessage is committed.

public final DataBufferFactory
protected Mono<Void>

Returns:

a completion publisher
doCommit
()

A variant of doCommit(Supplier) for a response without a body.

protected Mono<Void>

Returns:

a completion publisher
doCommit
(Supplier<? extends Mono<Void>>
the action to write the response body (may be null)
writeAction
)

Apply beforeCommit actions, apply the response status and headers/cookies, and write the response body.

public MultiValueMap<String, ResponseCookie>
getCookies()

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

Return a mutable map with the cookies to send to the server.

public HttpHeaders
getHeaders()

Implements org.springframework.http.HttpMessage.getHeaders.

Return the headers of this message.

public abstract <T> T
getNativeResponse()

Return the underlying server response.

public Integer
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()

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 boolean
isCommitted()

Implements org.springframework.http.ReactiveHttpOutputMessage.isCommitted.

Whether the HttpOutputMessage is committed.

public Mono<Void>
setComplete()

Implements org.springframework.http.ReactiveHttpOutputMessage.setComplete.

Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made via getHeaders() to the underlying HTTP message (if not applied already).

public boolean
setRawStatusCode(Integer
the status code value
statusCode
)

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

Set the HTTP status code to the given value as an integer.

public boolean
setStatusCode(HttpStatusCode
the HTTP status as an HttpStatusCode value
status
)

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

Set the HTTP status code of the response.

protected void
touchDataBuffer(DataBuffer
the buffer to attach a hint to
buffer
)

Allow subclasses to associate a hint with the data buffer if it is a pooled buffer and supports leak tracking.

public final Mono<Void>
writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>>
the body content publisher
body
)

Implements org.springframework.http.ReactiveHttpOutputMessage.writeAndFlushWith.

Use the given Publisher of Publishers to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after each Publisher<DataBuffer>.

protected abstract Mono<Void>
writeAndFlushWithInternal(Publisher<? extends Publisher<? extends DataBuffer>>
the publisher to write and flush with
body
)

Write to the underlying the response, and flush after each Publisher<DataBuffer>.

public final Mono<Void>
writeWith(Publisher<? extends DataBuffer>
the body content publisher
body
)

Implements org.springframework.http.ReactiveHttpOutputMessage.writeWith.

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

protected abstract Mono<Void>
writeWithInternal(Publisher<? extends DataBuffer>
the publisher to write with
body
)

Write to the underlying the response.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

commitActionsback to summary
private final List<Supplier<? extends Mono<Void>>> commitActions
cookiesback to summary
private final MultiValueMap<String, ResponseCookie> cookies
dataBufferFactoryback to summary
private final DataBufferFactory dataBufferFactory
headersback to summary
private final HttpHeaders headers
readOnlyHeadersback to summary
private HttpHeaders readOnlyHeaders
Annotations
@Nullable
stateback to summary
private final AtomicReference<AbstractServerHttpResponse.State> state
statusCodeback to summary
private HttpStatusCode statusCode
Annotations
@Nullable

Constructor Detail

AbstractServerHttpResponseback to summary
public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory)
AbstractServerHttpResponseback to summary
public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory, HttpHeaders headers)

Method Detail

addCookieback to summary
public void addCookie(ResponseCookie cookie)

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

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

Add the given ResponseCookie.

Parameters
cookie:ResponseCookie

the cookie to add

Annotations
@Override
applyCookiesback to summary
protected abstract void applyCookies()

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

applyHeadersback to summary
protected abstract void 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.

applyStatusCodeback to summary
protected abstract void applyStatusCode()

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

beforeCommitback to summary
public void beforeCommit(Supplier<? extends Mono<Void>> action)

Implements org.springframework.http.ReactiveHttpOutputMessage.beforeCommit.

Doc from org.springframework.http.ReactiveHttpOutputMessage.beforeCommit.

Register an action to apply just before the HttpOutputMessage is committed.

Note

the supplied action must be properly deferred, e.g. via Mono#defer or Mono#fromRunnable, to ensure it's executed in the right order, relative to other actions.

Parameters
action:Supplier<? extends Mono<Void>>

the action to apply

Annotations
@Override
bufferFactoryback to summary
public final DataBufferFactory bufferFactory()

Implements org.springframework.http.ReactiveHttpOutputMessage.bufferFactory.

Doc from org.springframework.http.ReactiveHttpOutputMessage.bufferFactory.

Return a DataBufferFactory that can be used to create the body.

Returns:DataBufferFactory

a buffer factory

Annotations
@Override
doCommitback to summary
protected Mono<Void> doCommit()

A variant of doCommit(Supplier) for a response without a body.

Returns:Mono<Void>

a completion publisher

doCommitback to summary
protected Mono<Void> doCommit(Supplier<? extends Mono<Void>> writeAction)

Apply beforeCommit actions, apply the response status and headers/cookies, and write the response body.

Parameters
writeAction:Supplier<? extends Mono<Void>>

the action to write the response body (may be null)

Returns:Mono<Void>

a completion publisher

getCookiesback to summary
public MultiValueMap<String, ResponseCookie> getCookies()

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

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

Return a mutable map with the cookies to send to the server.

Annotations
@Override
getHeadersback to summary
public HttpHeaders getHeaders()

Implements org.springframework.http.HttpMessage.getHeaders.

Doc from org.springframework.http.HttpMessage.getHeaders.

Return the headers of this message.

Returns:HttpHeaders

a corresponding HttpHeaders object (never null)

Annotations
@Override
getNativeResponseback to summary
public abstract <T> T getNativeResponse()

Return the underlying server response.

Note

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

getRawStatusCodeback to summary
public Integer 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
@Deprecated
@Override
@Nullable
getStatusCodeback to summary
public HttpStatusCode 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
@Nullable
isCommittedback to summary
public boolean isCommitted()

Implements org.springframework.http.ReactiveHttpOutputMessage.isCommitted.

Doc from org.springframework.http.ReactiveHttpOutputMessage.isCommitted.

Whether the HttpOutputMessage is committed.

Annotations
@Override
setCompleteback to summary
public Mono<Void> setComplete()

Implements org.springframework.http.ReactiveHttpOutputMessage.setComplete.

Doc from org.springframework.http.ReactiveHttpOutputMessage.setComplete.

Indicate that message handling is complete, allowing for any cleanup or end-of-processing tasks to be performed such as applying header changes made via getHeaders() to the underlying HTTP message (if not applied already).

This method should be automatically invoked at the end of message processing so typically applications should not have to invoke it. If invoked multiple times it should have no side effects.

Returns:Mono<Void>

a Mono that indicates completion or error

Annotations
@Override
setRawStatusCodeback to summary
public boolean setRawStatusCode(Integer statusCode)

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

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

Set the HTTP status code to the given value as an integer.

Parameters
statusCode:Integer

the status code value

Returns:boolean

false if the status code change wasn't processed because the HTTP response is committed, true if successfully set.

Annotations
@Override
setStatusCodeback to summary
public boolean setStatusCode(HttpStatusCode status)

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

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

Set the HTTP status code of the response.

Parameters
status:HttpStatusCode

the HTTP status as an HttpStatusCode value

Returns:boolean

false if the status code change wasn't processed because the HTTP response is committed, true if successfully set.

Annotations
@Override
touchDataBufferback to summary
protected void touchDataBuffer(DataBuffer buffer)

Allow subclasses to associate a hint with the data buffer if it is a pooled buffer and supports leak tracking.

Parameters
buffer:DataBuffer

the buffer to attach a hint to

Since
5.3.2
writeAndFlushWithback to summary
public final Mono<Void> writeAndFlushWith(Publisher<? extends Publisher<? extends DataBuffer>> body)

Implements org.springframework.http.ReactiveHttpOutputMessage.writeAndFlushWith.

Doc from org.springframework.http.ReactiveHttpOutputMessage.writeAndFlushWith.

Use the given Publisher of Publishers to write the body of the HttpOutputMessage to the underlying HTTP layer, flushing after each Publisher<DataBuffer>.

Parameters
body:Publisher<? extends Publisher<? extends DataBuffer>>

the body content publisher

Returns:Mono<Void>

a Mono that indicates completion or error

Annotations
@Override
writeAndFlushWithInternalback to summary
protected abstract Mono<Void> writeAndFlushWithInternal(Publisher<? extends Publisher<? extends DataBuffer>> body)

Write to the underlying the response, and flush after each Publisher<DataBuffer>.

Parameters
body:Publisher<? extends Publisher<? extends DataBuffer>>

the publisher to write and flush with

writeWithback to summary
public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body)

Implements org.springframework.http.ReactiveHttpOutputMessage.writeWith.

Doc from org.springframework.http.ReactiveHttpOutputMessage.writeWith.

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

Parameters
body:Publisher<? extends DataBuffer>

the body content publisher

Returns:Mono<Void>

a Mono that indicates completion or error

Annotations
@Override
@SuppressWarnings:unchecked
writeWithInternalback to summary
protected abstract Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> body)

Write to the underlying the response.

Parameters
body:Publisher<? extends DataBuffer>

the publisher to write with

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

private final Enum AbstractServerHttpResponse.State

extends Enum<AbstractServerHttpResponse.State>
Class Inheritance

COMMITTING -> COMMITTED is the period after doCommit is called but before the response status and headers have been applied to the underlying response during which time pre-commit actions can still make changes to the response status and headers.

Field Summary

Modifier and TypeField and Description
public static final AbstractServerHttpResponse.State
public static final AbstractServerHttpResponse.State
public static final AbstractServerHttpResponse.State
public static final AbstractServerHttpResponse.State

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AbstractServerHttpResponse.State
public static AbstractServerHttpResponse.State[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

COMMIT_ACTION_FAILEDback to summary
public static final AbstractServerHttpResponse.State COMMIT_ACTION_FAILED
COMMITTEDback to summary
public static final AbstractServerHttpResponse.State COMMITTED
COMMITTINGback to summary
public static final AbstractServerHttpResponse.State COMMITTING
NEWback to summary
public static final AbstractServerHttpResponse.State NEW

Constructor Detail

Stateback to summary
private State()

Method Detail

valueOfback to summary
public static AbstractServerHttpResponse.State valueOf(String name)
valuesback to summary
public static AbstractServerHttpResponse.State[] values()