Package com.avoka.component.http
Class HttpResponse
- java.lang.Object
-
- com.avoka.component.http.HttpResponse
-
public class HttpResponse extends Object
Provides a HttpResponse value object class.
-
-
Constructor Summary
Constructors Constructor Description HttpResponse()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
getContent()
String
getContentEncoding()
long
getContentLength()
String
getContentType()
Document
getDocumentContent()
Return the content as a XML Document object, or null if not defined.Map<String,String>
getHeaders()
Return the map of HTTP response headers.Object
getJsonContent()
Return the content as a JSON object, or null if not defined.int
getStatus()
String
getStatusLine()
String
getTextContent()
Return the content as a UTF-8 encoded string, or null if not defined.groovy.util.slurpersupport.GPathResult
getXmlContent()
Return the content as a Groovy XML GPathResult object, or null if not defined.boolean
isStatusNotFound()
Return true if the HTTP response status code is NOT FOUND (404).boolean
isStatusOK()
Return true if the HTTP response status code is OK (200).void
setContent(byte[] content)
void
setContentEncoding(String contentEncoding)
void
setContentLength(long contentLength)
void
setContentType(String contentType)
void
setHeaders(Map<String,String> headers)
Set the map of HTTP response headers.void
setStatus(int status)
void
setStatusLine(String statusLine)
String
toString()
Return the string representation of this class.
-
-
-
Method Detail
-
getTextContent
public String getTextContent()
Return the content as a UTF-8 encoded string, or null if not defined.- Returns:
- the content as a UTF-8 encoded string, or null if not defined.
-
getJsonContent
public Object getJsonContent()
Return the content as a JSON object, or null if not defined. This method uses the Groovygroovy.json.JsonSlurper
to parse the response text content into a JSON object.- Returns:
- the content as a JSON object, or null if not defined.
-
getXmlContent
public groovy.util.slurpersupport.GPathResult getXmlContent()
Return the content as a Groovy XML GPathResult object, or null if not defined. This method uses the Groovygroovy.util.XmlSlurper
to parse the response text content into a Groovy XML GPathResult object. Example GPathResult object graph navigation provided below:// XML Content <root><one a1="uno!"/><two>Some text!</two></root> // Perform request, and parse response .. def rootNode = response.getXmlContent() assert rootNode.name() == 'root' assert rootNode.one[0].@a1 == 'uno!' assert rootNode.two.text() == 'Some text!' rootNode.children().each { assert it.name() in ['one','two'] }
Note that in some cases, a 'selector' expression may not resolve to a single node. For example:
// XML Content <root> <a>one!</a> <a>two!</a> </root> // Perform request, and parse response .. def rootNode = response.getXmlContent() assert rootNode.a.size() == 2 rootNode.a.each { assert it.text() in ['one!','two!'] }
- Returns:
- the content as a Groovy XML GPathResult, or null if not defined
- Since:
- 4.3.0
-
getDocumentContent
public Document getDocumentContent()
Return the content as a XML Document object, or null if not defined. This method usesXmlUtils.buildDocument(byte[])
to parse the response content into an Document object.- Returns:
- the content as a XML Document object, or null if not defined.
-
getHeaders
public Map<String,String> getHeaders()
Return the map of HTTP response headers.- Returns:
- the map of HTTP response headers
- Since:
- 5.0.0
-
setHeaders
public void setHeaders(Map<String,String> headers)
Set the map of HTTP response headers.- Parameters:
headers
- the map of HTTP response headers- Since:
- 5.0.0
-
toString
public String toString()
Return the string representation of this class.
-
isStatusOK
public boolean isStatusOK()
Return true if the HTTP response status code is OK (200).- Returns:
- true if the HTTP response status code is OK (200).
-
isStatusNotFound
public boolean isStatusNotFound()
Return true if the HTTP response status code is NOT FOUND (404).- Returns:
- true if the HTTP response status code is NOT FOUND (404).
-
getStatus
public int getStatus()
- Returns:
- the HTTP response status code
-
setStatus
public void setStatus(int status)
- Parameters:
status
- the status to set
-
getStatusLine
public String getStatusLine()
- Returns:
- the statusLine
-
setStatusLine
public void setStatusLine(String statusLine)
- Parameters:
statusLine
- the statusLine to set
-
getContent
public byte[] getContent()
- Returns:
- the content
-
setContent
public void setContent(byte[] content)
- Parameters:
content
- the content to set
-
getContentLength
public long getContentLength()
- Returns:
- the contentLength
-
setContentLength
public void setContentLength(long contentLength)
- Parameters:
contentLength
- the contentLength to set
-
getContentType
public String getContentType()
- Returns:
- the contentType
-
setContentType
public void setContentType(String contentType)
- Parameters:
contentType
- the contentType to set
-
getContentEncoding
public String getContentEncoding()
- Returns:
- the contentEncoding
-
setContentEncoding
public void setContentEncoding(String contentEncoding)
- Parameters:
contentEncoding
- the contentEncoding to set
-
-