Class BasicHttpException
- All Implemented Interfaces:
Serializable,HttpResponseMessage
- Direct Known Subclasses:
BadGateway,BadRequest,BasicHttpException.Unmodifiable,Conflict,ExpectationFailed,FailedDependency,Forbidden,GatewayTimeout,Gone,HttpVersionNotSupported,InsufficientStorage,InternalServerError,LengthRequired,Locked,LoopDetected,MethodNotAllowed,MisdirectedRequest,NetworkAuthenticationRequired,NotAcceptable,NotExtended,NotFound,NotImplemented,PayloadTooLarge,PreconditionFailed,PreconditionRequired,RangeNotSatisfiable,RequestHeaderFieldsTooLarge,ServiceUnavailable,TooManyRequests,Unauthorized,UnavailableForLegalReasons,UnprocessableEntity,UnsupportedMediaType,UpgradeRequired,UriTooLong,VariantAlsoNegotiates
org.apache.juneau.http stack.
Extends RuntimeException while also implementing HttpResponseMessage, so that HTTP
error responses can be both thrown as exceptions and used as response objects. 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; any attempt to set a property on it throws an
UnsupportedOperationException.
This is a Throwable-rooted hierarchy, so (unlike BasicHttpResponse) it cannot be a self-typed (CRTP)
root — JLS §8.1.2 forbids a generic Throwable. The funnel therefore returns the base type and each leaf
keeps its covariant setter overrides.
See Also:
- Since:
- 9.2.1
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classUnmodifiable point-in-time snapshot of the enclosingBasicHttpException. -
Constructor Summary
ConstructorsModifierConstructorDescriptionBasicHttpException(int statusCode, String reasonPhrase) Constructor with no message body.BasicHttpException(int statusCode, String reasonPhrase, String msg, Object... args) Constructor with aString.format-style message body.BasicHttpException(int statusCode, String reasonPhrase, Throwable cause) Constructor with a status code and a cause.BasicHttpException(int statusCode, String reasonPhrase, Throwable cause, String msg, Object... args) Constructor with a cause and aString.format-style message body.protectedBasicHttpException(BasicHttpException 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.getFullStackMessage(boolean scrubForXssVulnerabilities) Returns all error messages from all errors in this exception's cause chain joined into a single string.Returns all response headers, in the order they were received.Returns the locale associated with this response, if any.Returns the root cause of this exception.intReturns the HTTP status code.Returns the status line of this response.inthashCode()booleanReturns whether this instance is an unmodifiable snapshot.protected BasicHttpExceptionSingle mutation funnel — the only choke-point through which all state changes on this bean flow.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.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()Returns an unmodifiable snapshot of this bean.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTraceMethods 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
-
BasicHttpException
Constructor with no message body.- Parameters:
statusCode- The HTTP status code.reasonPhrase- The reason phrase (e.g."Internal Server Error"). May benull .
-
BasicHttpException
Constructor with a status code and a cause.- Parameters:
statusCode- The HTTP status code.reasonPhrase- The reason phrase. May benull .cause- The cause. May benull .
-
BasicHttpException
Constructor with aString.format-style message body.- Parameters:
statusCode- The HTTP status code.reasonPhrase- The reason phrase. May benull .msg- The exception message and response body. May benull . Treated as aString.format-style format string (%s placeholders) whenargsis non-empty.args- Optional message arguments.
-
BasicHttpException
public BasicHttpException(int statusCode, String reasonPhrase, Throwable cause, String msg, Object... args) Constructor with a cause and aString.format-style message body.- Parameters:
statusCode- The HTTP status code.reasonPhrase- The reason phrase. May benull .cause- The cause. May benull .msg- The exception message. May benull . Treated as aString.format-style format string (%s placeholders) whenargsis non-empty.args- Optional message arguments.
-
BasicHttpException
Copy constructor.The mutable sub-beans are deep-copied by direct field assignment, never through a funneled setter. This is the snapshot path used by
unmodifiable(): the constructor runs inside anUnmodifiableinstance whosemodify(Runnable)already throws, so a setter-based copy would blow up during construction.- 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 .
-
getMessage
- Overrides:
getMessagein classThrowable
-
getStatusCode
Returns the HTTP status code.- 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.
-
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.
-
getRootCause
Returns the root cause of this exception.The root cause is the first exception in the init-cause parent chain that's not one of the following:
- Returns:
- The root cause of this exception, or
null if no root cause was found.
-
getFullStackMessage
Returns all error messages from all errors in this exception's cause chain joined into a single string.- Parameters:
scrubForXssVulnerabilities- Iftrue, replaces<,>, and&characters with spaces.- Returns:
- A multi-line string of messages. Never
null .
-
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. Because this is aThrowable-rooted hierarchy (no CRTP self-type), the funnel returns the base type.- 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
-