Class Response
- java.lang.Object
-
- com.yahoo.application.container.handler.Response
-
@Immutable @Beta public class Response extends java.lang.Object
A response for use withJDisc.handleRequest(Request)
.- Author:
- Einar M R Rosenvinge
- See Also:
Request
-
-
Constructor Summary
Constructors Constructor Description Response()
Creates a Response with an empty body, and 200 (OK) response code.Response(byte[] body)
Creates a Response with a message body, and 200 (OK) response code.Response(int status, byte[] body)
Creates a Response with a message body, and the given response code.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
getBody()
Returns the body of this Response.java.lang.String
getBodyAsString()
Attempts to decode the buffer returned bygetBody()
as a String in a best-effort manner.Headers
getHeaders()
Returns a mutable multi-map of headers for this Response.int
getStatus()
Returns the status code of this response.java.lang.String
toString()
-
-
-
Constructor Detail
-
Response
public Response()
Creates a Response with an empty body, and 200 (OK) response code.
-
Response
public Response(byte[] body)
Creates a Response with a message body, and 200 (OK) response code.- Parameters:
body
- the body of the response
-
Response
public Response(int status, byte[] body)
Creates a Response with a message body, and the given response code.- Parameters:
status
- the status code of the responsebody
- the body of the response- Since:
- 5.1.28
-
-
Method Detail
-
getStatus
public int getStatus()
Returns the status code of this response. This is an integer result code of the attempt to understand and satisfy the corresponding
Request
.- Returns:
- The status code.
- Since:
- 5.1.28
-
getBody
public byte[] getBody()
Returns the body of this Response.- Returns:
- the body of this Response
-
getBodyAsString
public java.lang.String getBodyAsString() throws java.nio.charset.CharacterCodingException
Attempts to decode the buffer returned bygetBody()
as a String in a best-effort manner. This is done using the Content-Type header - and defaults to UTF-8 encoding if the header is unparseable or not found. Note that this may very well throw aCharacterCodingException
.- Returns:
- a String with the decoded contents of the body buffer
- Throws:
java.nio.charset.CharacterCodingException
- if the body buffer was not well-formed
-
getHeaders
public Headers getHeaders()
Returns a mutable multi-map of headers for this Response.- Returns:
- a mutable multi-map of headers for this Response
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-