java.lang.Object
de.turnertech.problemdetails.Problem
A POJO representation of the urn:ietf:rfc:7807 problem type.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionProblem()
Constructs an empty Problem with the type "about:blank" (RFC 9457 - 4.2.1.).Constructs a deep copy of the provided problem.Constructs a Problem with the provided parameters.Constructs a Problem with the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionboolean
protected boolean
extendJson
(OutputStream outputStream, Charset charset) Override this if you wish to extend the JSON response.protected void
extendXml
(XMLStreamWriter xmlStreamWriter, Charset charset) Override this if you wish to extend the XML response.static String
findStatusPhrase
(int statusCode) Helper for retrieving the HTTP Status Phrase for a HTTP Status Code.static String
findStatusPhrase
(int statusCode, Locale locale) Helper for retrieving the localised HTTP Status Phrase for a HTTP Status Code.Gets the problem detail.Gets the problem instance.Gets the problem status code (HTTP Status Code).getTitle()
Gets the problem title.getType()
Gets the problem type.int
hashCode()
void
Sets the problem detail.void
setInstance
(URI instance) Sets the problem instance.void
Sets the problem status code (HTTP Status Code).void
Sets the problem title.void
Sets the problem type.toJson()
Converts the contents to a String containing the JSON representation of this Problem.void
toJson
(OutputStream outputStream) Writes the Problem to the supplied stream in JSON format using UTF-8.void
toJson
(OutputStream outputStream, Charset charset) Writes the Problem to the supplied stream in JSON format using the supplied Charset.toString()
toXml()
Converts the contents to a String containing the XML representation of this Problem.void
toXml
(OutputStream outputStream, Charset charset, boolean writeStartDocument) Writes the Problem to the supplied stream in XML format using the supplied charset.void
toXml
(XMLStreamWriter xmlStreamWriter, Charset charset, boolean writeStartDocument) Writes the Problem to the supplied writer in XML format using the supplied charset.
-
Field Details
-
NAMESPACE
urn:ietf:rfc:7807- See Also:
-
MEDIA_TYPE_XML
application/problem+xml- See Also:
-
MEDIA_TYPE_JSON
application/problem+json- See Also:
-
-
Constructor Details
-
Problem
public Problem()Constructs an empty Problem with the type "about:blank" (RFC 9457 - 4.2.1.). -
Problem
Constructs a Problem with the provided parameters. Note that type may not be null.- Parameters:
type
- RFC 9457 - 3.1.1.- Throws:
NullPointerException
- if type is null.
-
Problem
Constructs a Problem with the provided parameters. Note that type may not be null.- Parameters:
type
- RFC 9457 - 3.1.1.instance
- RFC 9457 - 3.1.5.- Throws:
NullPointerException
- if type is null.
-
Problem
Constructs a deep copy of the provided problem. If you extend this class, make sure that your implementation of the copy constructor also returns deep copies.- Parameters:
other
- problem to copy.
-
-
Method Details
-
getType
Gets the problem type.- Returns:
- the problem type.
-
setType
Sets the problem type.- Parameters:
type
- the problem type.- Throws:
NullPointerException
- if type is null
-
getStatus
Gets the problem status code (HTTP Status Code).- Returns:
- the problem status code (HTTP Status Code)
-
setStatus
Sets the problem status code (HTTP Status Code). If set, this must be the same as the one used in your HTTP Response.- Parameters:
status
- the problem status code (HTTP Status Code).- See Also:
-
getTitle
Gets the problem title.- Returns:
- the problem title.
-
setTitle
Sets the problem title.- Parameters:
title
- the short human readable title.- See Also:
-
getDetail
Gets the problem detail.- Returns:
- the problem detail.
-
setDetail
Sets the problem detail.- Parameters:
detail
- the problem detail.
-
getInstance
Gets the problem instance.- Returns:
- the problem instance.
-
setInstance
Sets the problem instance.- Parameters:
instance
- the problem instance.
-
findStatusPhrase
Helper for retrieving the HTTP Status Phrase for a HTTP Status Code.- Parameters:
statusCode
- the HTTP Status Code.- Returns:
- the HTTP Status Phrase in English, may be null.
- See Also:
-
findStatusPhrase
Helper for retrieving the localised HTTP Status Phrase for a HTTP Status Code.- Parameters:
statusCode
- the HTTP Status Code.locale
- the desired language.- Returns:
- the HTTP Status Phrase, may be null.
- See Also:
-
toJson
Converts the contents to a String containing the JSON representation of this Problem.- Returns:
- the JSON String.
- Throws:
IOException
- if there are problems with extending the JSON.- See Also:
-
toJson
Writes the Problem to the supplied stream in JSON format using UTF-8.- Parameters:
outputStream
- the stream to write to.- Throws:
IOException
- if there are problems with extending the JSON.- See Also:
-
toJson
Writes the Problem to the supplied stream in JSON format using the supplied Charset.- Parameters:
outputStream
- the stream to write to.charset
- the Charset to use.- Throws:
IOException
- if there are problems with extending the JSON.
-
extendJson
Override this if you wish to extend the JSON response. This function is called directly before closing the problem element. Pay carefull attention to the namespaces!
- Parameters:
outputStream
- the stream to write tocharset
- the charset this XML is being written in- Returns:
- true if an element was inserted (so that the caller can decide whether or not to write a ",")
-
toXml
Converts the contents to a String containing the XML representation of this Problem.- Returns:
- the XML String.
- Throws:
XMLStreamException
- if there are problems with extending the XML.- See Also:
-
toXml
public void toXml(OutputStream outputStream, Charset charset, boolean writeStartDocument) throws XMLStreamException Writes the Problem to the supplied stream in XML format using the supplied charset.- Parameters:
outputStream
- to write to.charset
- to write using.writeStartDocument
- to indicate if the xml start document should also be written.- Throws:
XMLStreamException
- if there are problems with extending the XML.
-
toXml
public void toXml(XMLStreamWriter xmlStreamWriter, Charset charset, boolean writeStartDocument) throws XMLStreamException Writes the Problem to the supplied writer in XML format using the supplied charset.- Parameters:
xmlStreamWriter
- to write using.charset
- to write using.writeStartDocument
- to indicate if the xml start document should also be written.- Throws:
XMLStreamException
- if there are problems with extending the XML.
-
extendXml
protected void extendXml(XMLStreamWriter xmlStreamWriter, Charset charset) throws XMLStreamException Override this if you wish to extend the XML response. This function is called directly before closing the problem element. Pay carefull attention to the namespaces!- Parameters:
xmlStreamWriter
- the writer you must use to write to the streamcharset
- the charset this XML is being written in- Throws:
XMLStreamException
- if there are problems with extending the XML.
-
hashCode
public int hashCode() -
equals
-
toString
-