Class BasicHttpResponse<SELF extends BasicHttpResponse<SELF>>
- Type Parameters:
SELF- The self type for fluent setters.
- All Implemented Interfaces:
HttpResponseMessage
- Direct Known Subclasses:
Accepted,AlreadyReported,Continue,Created,EarlyHints,Found,IMUsed,MovedPermanently,MultipleChoices,MultiStatus,NoContent,NonAuthoritativeInformation,NotModified,Ok,PartialContent,PermanentRedirect,Processing,ResetContent,SeeOther,SwitchingProtocols,TemporaryRedirect,UseProxy
org.apache.juneau.http stack.
Holds a status line, an optional body, and an ordered list of headers. Provides classic-style
fluent setters that mutate state and return this.
Immutability is expressed with the "funnel + nested Unmodifiable snapshot" paradigm: every mutator routes
through the single protected modify(Runnable) choke-point, and each concrete leaf gets a nested
X.Unmodifiable whose only behavioral override is a throwing modify(...). A leaf's
unmodifiable() factory returns a point-in-time snapshot of type X.Unmodifiable; any attempt to set a
property on it throws an UnsupportedOperationException.
This is a self-typed (CRTP) root: a leaf declares
See Also:
- Since:
- 9.2.1
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBasicHttpResponse(HttpStatusLine statusLine) Constructor with no body.protectedBasicHttpResponse(HttpStatusLine statusLine, String body) Constructor with a string body (UTF-8,text/plain).protectedBasicHttpResponse(HttpStatusLine statusLine, List<HttpHeader> headers, HttpBody body) Constructor with headers and an optional body.protectedBasicHttpResponse(HttpStatusLine statusLine, HttpBody body) Constructor with a body.protectedBasicHttpResponse(BasicHttpResponse<?> copyFrom) Copy constructor. -
Method Summary
Modifier and TypeMethodDescriptionAppends a header to the end of the header list.addHeader(HttpHeader value) Appends a header to the end of the header list.booleanprotected voidfreeze()Deep-freeze hook invoked from the nestedUnmodifiableconstructor after the snapshot copy completes.getBody()Returns the response body, ornull if the response has no body.Returns all response headers, in the order they were received.Returns the locale associated with this response, if any.intReturns the HTTP status code from the status line.Returns the status line of this response.inthashCode()booleanReturns whether this instance is an unmodifiable snapshot.protected SELFSingle mutation funnel — the only choke-point through which all state changes on this bean flow.protected final SELFself()Returns this object cast to the self type.Sets the response body.setContent(String value) Sets the response body to a plain-text string body (UTF-8,text/plain).setContent(HttpBody value) Sets the response body.Sets a single header, replacing any existing header with the same name.setHeader(HttpHeader value) Sets a single header, replacing any existing header with the same name.setHeaders(List<HttpHeader> values) Replaces all headers with the given list.setHeaders(HttpHeader... values) Replaces all headers with the given array.Sets the locale associated with this response.setLocation(String value) Sets the value of theLocationheader.setLocation(URI value) Sets the value of theLocationheader.Sets the protocol version, preserving the existing status code and reason phrase.setReasonPhrase(String value) Sets the reason phrase, preserving the existing protocol version and status code.setStatusCode(int value) Sets the status code, preserving the existing protocol version and reason phrase.setStatusLine(HttpStatusLine value) Sets the status line.toString()abstract SELFReturns an unmodifiable snapshot of this bean.Sets the body on this response as a plain-text string.Sets the body on this response.withHeader(String name, String value) Appends a header to this response.withHeader(HttpHeader header) Appends a header to this response.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.juneau.http.response.HttpResponseMessage
getFirstHeader, getHeaders
-
Constructor Details
-
BasicHttpResponse
Constructor with no body.- Parameters:
statusLine- The status line. Must not benull .
-
BasicHttpResponse
Constructor with a body.- Parameters:
statusLine- The status line. Must not benull .body- The response body. May benull .
-
BasicHttpResponse
Constructor with a string body (UTF-8,text/plain).- Parameters:
statusLine- The status line. Must not benull .body- The response body as a plain-text string. May benull .
-
BasicHttpResponse
Constructor with headers and an optional body.- Parameters:
statusLine- The status line. Must not benull .headers- The response headers. Can benull (treated as an empty list).body- The response body. May benull .
-
BasicHttpResponse
Copy constructor.- Parameters:
copyFrom- The instance to copy. Must not benull .
-
-
Method Details
-
getStatusLine
Description copied from interface:HttpResponseMessageReturns the status line of this response.- Specified by:
getStatusLinein interfaceHttpResponseMessage- Returns:
- The status line. Never
null .
-
getHeaders
Description copied from interface:HttpResponseMessageReturns all response headers, in the order they were received.- Specified by:
getHeadersin interfaceHttpResponseMessage- Returns:
- An unmodifiable list of response headers. Never
null .
-
getBody
Description copied from interface:HttpResponseMessageReturns the response body, ornull if the response has no body.- Specified by:
getBodyin interfaceHttpResponseMessage- Returns:
- The response body, possibly
null .
-
getStatusCode
Returns the HTTP status code from the status line.- Returns:
- The status code.
-
getLocale
Returns the locale associated with this response, if any.- Returns:
- The locale, possibly
null .
-
setStatusLine
Sets the status line.- Parameters:
value- New status line. Must not benull .- Returns:
- This object.
-
setStatusCode
Sets the status code, preserving the existing protocol version and reason phrase.- Parameters:
value- New status code.- Returns:
- This object.
-
setReasonPhrase
Sets the reason phrase, preserving the existing protocol version and status code.- Parameters:
value- New reason phrase. May benull .- Returns:
- This object.
-
setProtocolVersion
Sets the protocol version, preserving the existing status code and reason phrase.- Parameters:
value- New protocol version. Must not benull .- Returns:
- This object.
-
setHeaders
Replaces all headers with the given list.- Parameters:
values- New headers.nullis treated as an empty list.- Returns:
- This object.
-
setHeaders
Replaces all headers with the given array.- Parameters:
values- New headers.nullis treated as an empty array.- Returns:
- This object.
-
setHeader
Sets a single header, replacing any existing header with the same name.- Parameters:
value- The header to set.nullis ignored.- Returns:
- This object.
-
setHeader
Sets a single header, replacing any existing header with the same name.- Parameters:
name- Header name. Must not benull .value- Header value. May benull .- Returns:
- This object.
-
addHeader
Appends a header to the end of the header list.- Parameters:
value- The header to add.nullis ignored.- Returns:
- This object.
-
addHeader
Appends a header to the end of the header list.- Parameters:
name- Header name. Must not benull .value- Header value. May benull .- Returns:
- This object.
-
setBody
Sets the response body.- Parameters:
value- New body. May benull .- Returns:
- This object.
-
setContent
Sets the response body to a plain-text string body (UTF-8,text/plain).- Parameters:
value- Body text. May benull .- Returns:
- This object.
-
setContent
Sets the response body.- Parameters:
value- New body. May benull .- Returns:
- This object.
-
setLocale
Sets the locale associated with this response.- Parameters:
value- New locale. May benull .- Returns:
- This object.
-
setLocation
Sets the value of theLocationheader.- Parameters:
value- The new location value. May benull .- Returns:
- This object.
-
setLocation
Sets the value of theLocationheader.- Parameters:
value- The new location value. May benull .- Returns:
- This object.
-
isUnmodifiable
Returns whether this instance is an unmodifiable snapshot.- Returns:
true if this bean is anUnmodifiableBeansnapshot.
-
unmodifiable
Returns an unmodifiable snapshot of this bean.The returned instance is a point-in-time copy of the leaf's nested
Unmodifiabletype; any attempt to set a property on it throws anUnsupportedOperationException. This method is idempotent: if this bean is already unmodifiable it returns itself rather than taking another snapshot. The receiver is left unchanged (and still modifiable unless it was already unmodifiable).- Returns:
- An unmodifiable snapshot of this bean, or this bean if it is already unmodifiable.
-
withBody
Sets the body on this response.- Parameters:
value- The new body. May benull .- Returns:
- This object.
-
withBody
Sets the body on this response as a plain-text string.- Parameters:
value- The new body as a plain-text string. May benull .- Returns:
- This object.
-
withHeader
Appends a header to this response.- Parameters:
header- The header to add. Must not benull .- Returns:
- This object.
-
withHeader
Appends a header to this response.- Parameters:
name- The header name. Must not benull .value- The header value. May benull .- Returns:
- This object.
-
self
Returns this object cast to the self type.- Returns:
- This object.
-
modify
Single mutation funnel — the only choke-point through which all state changes on this bean flow.Every fluent setter routes through this method. The nested
Unmodifiablesnapshot overrides only this method to throw, which freezes the entire mutation surface with a single override.- Parameters:
mutation- The state change to apply.- Returns:
- This object.
-
freeze
Deep-freeze hook invoked from the nestedUnmodifiableconstructor after the snapshot copy completes.The mutable sub-beans are frozen here by direct field assignment (never via a setter, which would route through the throwing
modify(Runnable)and blow up during construction). A leaf that adds its own mutable sub-bean overrides this method (callingsuper.freeze()first). -
equals
-
hashCode
-
toString
-