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

public Interface ServerResponse

Known Direct Subinterfaces
org.springframework.web.servlet.function.AsyncServerResponse, org.springframework.web.servlet.function.EntityResponse, org.springframework.web.servlet.function.RenderingResponse
Known Direct Implementers
org.springframework.web.servlet.function.ErrorHandlingServerResponse
Imports
java.io.IOException, java.net.URI, java.time.Duration, .Instant, .ZonedDateTime, java.util.Collection, .List, .Map, .Set, java.util.concurrent.CompletableFuture, .CompletionStage, java.util.function.Consumer, jakarta.servlet.ServletException, jakarta.servlet.http.Cookie, .HttpServletRequest, .HttpServletResponse, org.reactivestreams.Publisher, org.springframework.core.ParameterizedTypeReference, .ReactiveAdapterRegistry, org.springframework.http.CacheControl, .HttpHeaders, .HttpMethod, .HttpStatus, .HttpStatusCode, .MediaType, org.springframework.http.converter.HttpMessageConverter, org.springframework.lang.Nullable, org.springframework.util.MultiValueMap, org.springframework.web.ErrorResponse, org.springframework.web.servlet.ModelAndView

Represents a typed server-side HTTP response, as returned by a handler function or filter function.
Author
Arjen Poutsma
Since
5.2

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ServerResponse.BodyBuilder

Defines a builder that adds a body to the response.

public static interface
public static interface
ServerResponse.HeadersBuilder<
the builder subclass
B extends ServerResponse.HeadersBuilder<B>
>

Defines a builder that adds headers to the response.

public static interface
ServerResponse.SseBuilder

Defines a builder for a body that sends server-sent events.

Method Summary

Modifier and TypeMethod and Description
public static ServerResponse.BodyBuilder

Returns:

the created builder
accepted
()

Create a builder with a 202 Accepted status.

public static ServerResponse

Returns:

the asynchronous response
async
(Object
a CompletableFuture<ServerResponse> or Publisher<ServerResponse>
asyncResponse
)

Create a (built) response with the given asynchronous response.

public static ServerResponse

Returns:

the asynchronous response
async
(Object
a CompletableFuture<ServerResponse> or Publisher<ServerResponse>
asyncResponse
,
Duration
maximum time period to wait for before timing out
timeout
)

Create a (built) response with the given asynchronous response.

public static ServerResponse.BodyBuilder

Returns:

the created builder
badRequest
()

Create a builder with a 400 Bad Request status.

public MultiValueMap<String, Cookie>
cookies()

Return the cookies of this response.

public static ServerResponse.BodyBuilder

Returns:

the created builder
created
(URI
the location URI
location
)

Create a builder with a 201 Created status and a location header set to the given URI.

public static ServerResponse.BodyBuilder

Returns:

the created builder
from
(ServerResponse
the response to copy the status and headers from
other
)

Create a builder with the status code and headers of the given response.

public static ServerResponse

Returns:

the built response
from
(ErrorResponse
the ErrorResponse to initialize from
response
)

Create a ServerResponse from the given ErrorResponse.

public HttpHeaders
headers()

Return the headers of this response.

public static ServerResponse.HeadersBuilder<?>

Returns:

the created builder
noContent
()

Create a builder with a 204 No Content status.

public static ServerResponse.HeadersBuilder<?>

Returns:

the created builder
notFound
()

Create a builder with a 404 Not Found status.

public static ServerResponse.BodyBuilder

Returns:

the created builder
ok
()

Create a builder with the status set to 200 OK.

public static ServerResponse.BodyBuilder

Returns:

the created builder
permanentRedirect
(URI
the location URI
location
)

Create a builder with a 308 Permanent Redirect status and a location header set to the given URI.

public int

Returns:

the status as an integer
rawStatusCode
()
Deprecated since 6.0. as of 6.0, in favor of statusCode()

Return the status code of this response as integer.

public static ServerResponse.BodyBuilder

Returns:

the created builder
seeOther
(URI
the location URI
location
)

Create a builder with a 303 See Other status and a location header set to the given URI.

public static ServerResponse

Returns:

the server-side event response
sse
(Consumer<ServerResponse.SseBuilder>
consumer that will be provided with an event builder
consumer
)

Create a server-sent event response.

public static ServerResponse

Returns:

the server-side event response
sse
(Consumer<ServerResponse.SseBuilder>
consumer that will be provided with an event builder
consumer
,
Duration
maximum time period to wait before timing out
timeout
)

Create a server-sent event response.

public static ServerResponse.BodyBuilder

Returns:

the created builder
status
(HttpStatusCode
the response status
status
)

Create a builder with the given HTTP status.

public static ServerResponse.BodyBuilder

Returns:

the created builder
status
(int
the response status
status
)

Create a builder with the given HTTP status.

public HttpStatusCode

Returns:

the status as an HttpStatusCode value
statusCode
()

Return the status code of this response.

public static ServerResponse.BodyBuilder

Returns:

the created builder
temporaryRedirect
(URI
the location URI
location
)

Create a builder with a 307 Temporary Redirect status and a location header set to the given URI.

public static ServerResponse.BodyBuilder

Returns:

the created builder
unprocessableEntity
()

Create a builder with a 422 Unprocessable Entity status.

public ModelAndView

Returns:

a ModelAndView to render, or null if handled directly
writeTo
(HttpServletRequest
the current request
request
,
HttpServletResponse
the response to write to
response
,
ServerResponse.Context
the context to use when writing
context
)

Write this response to the given servlet response.