Top Description Inners Fields Constructors Methods
org.springframework.web.servlet.function

pack-priv Class DefaultServerResponseBuilder

extends Object
implements BodyBuilder
Class Inheritance
All Implemented Interfaces
org.springframework.web.servlet.function.ServerResponse.BodyBuilder, org.springframework.web.servlet.function.ServerResponse.HeadersBuilder
Imports
java.net.URI, java.time.Instant, .ZonedDateTime, java.util.Arrays, .LinkedHashSet, .Map, .Set, java.util.function.Consumer, jakarta.servlet.http.Cookie, .HttpServletRequest, .HttpServletResponse, org.springframework.core.ParameterizedTypeReference, org.springframework.http.CacheControl, .HttpHeaders, .HttpMethod, .HttpStatusCode, .MediaType, org.springframework.util.Assert, .LinkedMultiValueMap, .MultiValueMap, org.springframework.web.servlet.ModelAndView

Default ServerResponse.BodyBuilder implementation.
Author
Arjen Poutsma
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final MultiValueMap<String, Cookie>
private final HttpHeaders
private final HttpStatusCode

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
public ServerResponse.BodyBuilder
allow(HttpMethod...
the allowed methods
allowedMethods
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.allow.

Set the set of allowed HTTP methods, as specified by the Allow header.

public ServerResponse.BodyBuilder
allow(Set<HttpMethod>
the allowed methods
allowedMethods
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.allow.

Set the set of allowed HTTP methods, as specified by the Allow header.

public ServerResponse
body(Object
the body of the response
body
)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.body.

Set the body of the response to the given Object and return it.

public <T> ServerResponse
body(T
the body of the response
body
,
ParameterizedTypeReference<T>
the type of the body, used to capture the generic type
bodyType
)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.body.

Set the body of the response to the given Object and return it.

public ServerResponse
build()

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.build.

Build the response entity with no body.

public ServerResponse
build(ServerResponse.HeadersBuilder.WriteFunction
the function used to write to the HttpServletResponse
writeFunction
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.build.

Build the response entity with a custom write function.

public ServerResponse.BodyBuilder
cacheControl(CacheControl
a builder for cache-related HTTP response headers
cacheControl
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.cacheControl.

Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.

public ServerResponse.BodyBuilder
contentLength(long
the content length
contentLength
)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.contentLength.

Set the length of the body in bytes, as specified by the Content-Length header.

public ServerResponse.BodyBuilder
contentType(MediaType
the content type
contentType
)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.contentType.

Set the media type of the body, as specified by the Content-Type header.

public ServerResponse.BodyBuilder
cookies(Consumer<MultiValueMap<String, Cookie>>
a function that consumes the cookies
cookiesConsumer
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.cookies.

Manipulate this response's cookies with the given consumer.

public ServerResponse.BodyBuilder
eTag(String
the new entity tag
etag
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.eTag.

Set the entity tag of the body, as specified by the ETag header.

public ServerResponse.BodyBuilder
header(String
the header name
headerName
,
String...
the header value(s)
headerValues
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.header.

Add the given header value(s) under the given name.

public ServerResponse.BodyBuilder
headers(Consumer<HttpHeaders>
a function that consumes the HttpHeaders
headersConsumer
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.headers.

Manipulate this response's headers with the given consumer.

public ServerResponse.BodyBuilder
lastModified(ZonedDateTime
the last modified date
lastModified
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.lastModified.

Set the time the resource was last changed, as specified by the Last-Modified header.

public ServerResponse.BodyBuilder
lastModified(Instant
the last modified date
lastModified
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.lastModified.

Set the time the resource was last changed, as specified by the Last-Modified header.

public ServerResponse.BodyBuilder
location(URI
the location
location
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.location.

Set the location of a resource, as specified by the Location header.

public ServerResponse
render(String
the name of the template to be rendered
name
,
Object...
the modelAttributes used to render the template
modelAttributes
)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.render.

Render the template with the given name using the given modelAttributes.

public ServerResponse
render(String
the name of the template to be rendered
name
,
Map<String, ?>
the model used to render the template
model
)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.render.

Render the template with the given name using the given model.

public ServerResponse.BodyBuilder
varyBy(String...
request header names
requestHeaders
)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.varyBy.

Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cookiesback to summary
private final MultiValueMap<String, Cookie> cookies
headersback to summary
private final HttpHeaders headers
statusCodeback to summary
private final HttpStatusCode statusCode

Constructor Detail

DefaultServerResponseBuilderback to summary
public DefaultServerResponseBuilder(ServerResponse other)
DefaultServerResponseBuilderback to summary
public DefaultServerResponseBuilder(HttpStatusCode status)

Method Detail

allowback to summary
public ServerResponse.BodyBuilder allow(HttpMethod... allowedMethods)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.allow.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.allow.

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods:HttpMethod[]

the allowed methods

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
allowback to summary
public ServerResponse.BodyBuilder allow(Set<HttpMethod> allowedMethods)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.allow.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.allow.

Set the set of allowed HTTP methods, as specified by the Allow header.

Parameters
allowedMethods:Set<HttpMethod>

the allowed methods

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
bodyback to summary
public ServerResponse body(Object body)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.body.

Doc from org.springframework.web.servlet.function.ServerResponse.BodyBuilder.body.

Set the body of the response to the given Object and return it.

Asynchronous response bodies are supported by providing a CompletionStage or Publisher as body (or any asynchronous producer of a single entity that can be adapted via the ReactiveAdapterRegistry).

Parameters
body:Object

the body of the response

Returns:ServerResponse

the built response

Annotations
@Override
bodyback to summary
public <T> ServerResponse body(T body, ParameterizedTypeReference<T> bodyType)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.body.

Doc from org.springframework.web.servlet.function.ServerResponse.BodyBuilder.body.

Set the body of the response to the given Object and return it. The parameter bodyType is used to capture the generic type.

Parameters
body:T

the body of the response

bodyType:ParameterizedTypeReference<T>

the type of the body, used to capture the generic type

Returns:ServerResponse

the built response

Annotations
@Override
buildback to summary
public ServerResponse build()

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.build.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.build.

Build the response entity with no body.

Annotations
@Override
buildback to summary
public ServerResponse build(ServerResponse.HeadersBuilder.WriteFunction writeFunction)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.build.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.build.

Build the response entity with a custom write function.

Parameters
writeFunction:ServerResponse.HeadersBuilder.WriteFunction

the function used to write to the HttpServletResponse

Annotations
@Override
cacheControlback to summary
public ServerResponse.BodyBuilder cacheControl(CacheControl cacheControl)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.cacheControl.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.cacheControl.

Set the caching directives for the resource, as specified by the HTTP 1.1 Cache-Control header.

A CacheControl instance can be built like CacheControl.maxAge(3600).cachePublic().noTransform().

Parameters
cacheControl:CacheControl

a builder for cache-related HTTP response headers

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
contentLengthback to summary
public ServerResponse.BodyBuilder contentLength(long contentLength)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.contentLength.

Doc from org.springframework.web.servlet.function.ServerResponse.BodyBuilder.contentLength.

Set the length of the body in bytes, as specified by the Content-Length header.

Parameters
contentLength:long

the content length

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
contentTypeback to summary
public ServerResponse.BodyBuilder contentType(MediaType contentType)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.contentType.

Doc from org.springframework.web.servlet.function.ServerResponse.BodyBuilder.contentType.

Set the media type of the body, as specified by the Content-Type header.

Parameters
contentType:MediaType

the content type

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
cookiesback to summary
public ServerResponse.BodyBuilder cookies(Consumer<MultiValueMap<String, Cookie>> cookiesConsumer)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.cookies.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.cookies.

Manipulate this response's cookies with the given consumer. The cookies provided to the consumer are "live", so that the consumer can be used to overwrite existing cookies, remove cookies, or use any of the other MultiValueMap methods.

Parameters
cookiesConsumer:Consumer<MultiValueMap<String, Cookie>>

a function that consumes the cookies

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
eTagback to summary
public ServerResponse.BodyBuilder eTag(String etag)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.eTag.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.eTag.

Set the entity tag of the body, as specified by the ETag header.

Parameters
etag:String

the new entity tag

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
headerback to summary
public ServerResponse.BodyBuilder header(String headerName, String... headerValues)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.header.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.header.

Add the given header value(s) under the given name.

Parameters
headerName:String

the header name

headerValues:String[]

the header value(s)

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
headersback to summary
public ServerResponse.BodyBuilder headers(Consumer<HttpHeaders> headersConsumer)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.headers.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.headers.

Manipulate this response's headers with the given consumer. The headers provided to the consumer are "live", so that the consumer can be used to overwrite existing header values, remove values, or use any of the other HttpHeaders methods.

Parameters
headersConsumer:Consumer<HttpHeaders>

a function that consumes the HttpHeaders

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
lastModifiedback to summary
public ServerResponse.BodyBuilder lastModified(ZonedDateTime lastModified)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.lastModified.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.lastModified.

Set the time the resource was last changed, as specified by the Last-Modified header.

Parameters
lastModified:ZonedDateTime

the last modified date

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
lastModifiedback to summary
public ServerResponse.BodyBuilder lastModified(Instant lastModified)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.lastModified.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.lastModified.

Set the time the resource was last changed, as specified by the Last-Modified header.

Parameters
lastModified:Instant

the last modified date

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
locationback to summary
public ServerResponse.BodyBuilder location(URI location)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.location.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.location.

Set the location of a resource, as specified by the Location header.

Parameters
location:URI

the location

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
renderback to summary
public ServerResponse render(String name, Object... modelAttributes)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.render.

Doc from org.springframework.web.servlet.function.ServerResponse.BodyBuilder.render.

Render the template with the given name using the given modelAttributes. The model attributes are mapped under a generated name.

Note

Empty Collections are not added to the model when using this method because we cannot correctly determine the true convention name.

Parameters
name:String

the name of the template to be rendered

modelAttributes:Object[]

the modelAttributes used to render the template

Returns:ServerResponse

the built response

Annotations
@Override
renderback to summary
public ServerResponse render(String name, Map<String, ?> model)

Implements org.springframework.web.servlet.function.ServerResponse.BodyBuilder.render.

Doc from org.springframework.web.servlet.function.ServerResponse.BodyBuilder.render.

Render the template with the given name using the given model.

Parameters
name:String

the name of the template to be rendered

model:Map<String, ?>

the model used to render the template

Returns:ServerResponse

the built response

Annotations
@Override
varyByback to summary
public ServerResponse.BodyBuilder varyBy(String... requestHeaders)

Implements org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.varyBy.

Doc from org.springframework.web.servlet.function.ServerResponse.HeadersBuilder.varyBy.

Configure one or more request header names (e.g. "Accept-Language") to add to the "Vary" response header to inform clients that the response is subject to content negotiation and variances based on the value of the given request headers. The configured request header names are added only if not already present in the response "Vary" header.

Parameters
requestHeaders:String[]

request header names

Returns:ServerResponse.BodyBuilder

this builder

Annotations
@Override
org.springframework.web.servlet.function back to summary

private Class DefaultServerResponseBuilder.WriteFunctionResponse

extends AbstractServerResponse
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final ServerResponse.HeadersBuilder.WriteFunction

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected ModelAndView
Inherited from org.springframework.web.servlet.function.AbstractServerResponse:
cookiesheadersrawStatusCodestatusCodewriteTo

Field Detail

writeFunctionback to summary
private final ServerResponse.HeadersBuilder.WriteFunction writeFunction

Constructor Detail

WriteFunctionResponseback to summary
public WriteFunctionResponse(HttpStatusCode statusCode, HttpHeaders headers, MultiValueMap<String, Cookie> cookies, ServerResponse.HeadersBuilder.WriteFunction writeFunction)

Method Detail

writeToInternalback to summary
protected ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, ServerResponse.Context context) throws Exception

Implements abstract org.springframework.web.servlet.function.AbstractServerResponse.writeToInternal.

Annotations
@Override