Package com.avoka.component.http
Class HttpResponse
java.lang.Object
com.avoka.component.http.HttpResponse
Provides a HttpResponse value object class.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]longReturn the content as a XML Document object, or null if not defined.Return the map of HTTP response headers.Return the content as a JSON object, or null if not defined.intReturn the content as a UTF-8 encoded string, or null if not defined.groovy.util.slurpersupport.GPathResultReturn the content as a Groovy XML GPathResult object, or null if not defined.booleanReturn true if the HTTP response status code is NOT FOUND (404).booleanReturn true if the HTTP response status code is OK (200).voidsetContent(byte[] content) voidsetContentEncoding(String contentEncoding) voidsetContentLength(long contentLength) voidsetContentType(String contentType) voidsetHeaders(Map<String, String> headers) Set the map of HTTP response headers.voidsetStatus(int status) voidsetStatusLine(String statusLine) toString()Return the string representation of this class.
-
Constructor Details
-
HttpResponse
public HttpResponse()
-
-
Method Details
-
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
Return the content as a JSON object, or null if not defined. This method uses the Groovygroovy.json.JsonSlurperto 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.XmlSlurperto 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
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
Return the map of HTTP response headers.- Returns:
- the map of HTTP response headers
- Since:
- 5.0.0
-
setHeaders
Set the map of HTTP response headers.- Parameters:
headers- the map of HTTP response headers- Since:
- 5.0.0
-
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
- Returns:
- the statusLine
-
setStatusLine
- 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
- Returns:
- the contentType
-
setContentType
- Parameters:
contentType- the contentType to set
-
getContentEncoding
- Returns:
- the contentEncoding
-
setContentEncoding
- Parameters:
contentEncoding- the contentEncoding to set
-