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()StringgetContentEncoding()longgetContentLength()StringgetContentType()DocumentgetDocumentContent()Return the content as a XML Document object, or null if not defined.Map<String,String>getHeaders()Return the map of HTTP response headers.ObjectgetJsonContent()Return the content as a JSON object, or null if not defined.intgetStatus()StringgetStatusLine()StringgetTextContent()Return the content as a UTF-8 encoded string, or null if not defined.groovy.util.slurpersupport.GPathResultgetXmlContent()Return the content as a Groovy XML GPathResult object, or null if not defined.booleanisStatusNotFound()Return true if the HTTP response status code is NOT FOUND (404).booleanisStatusOK()Return 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)StringtoString()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.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
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
-
-