public class Response extends Object
| Constructor and Description |
|---|
Response() |
Response(org.ballerinalang.jvm.values.ObjectValue responseObj) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(String headerName,
String headerValue)
Adds the specified header to the response.
|
byte[] |
getBinaryPayload()
Gets the response payload as a `byte[]`.
|
Entity[] |
getBodyParts()
Extracts body parts from the response.
|
ByteChannel |
getByteChannel()
Gets the response payload as a `ByteChannel` except in the case of multiparts.
|
String |
getContentType()
Gets the type of the payload of the response (i.e: the `content-type` header value).
|
Entity |
getEntity() |
Entity |
getEntityWithoutBody() |
String |
getHeader(String headerName)
Returns the value of the specified header.
|
String[] |
getHeaderNames()
Gets all the names of the headers of the request.
|
String[] |
getHeaders(String headerName)
Gets all the header values to which the specified header key maps to.
|
org.json.JSONArray |
getJsonArrayPayload()
Extracts `json array` payload from the response.
|
org.json.JSONObject |
getJsonPayload()
Extracts `json` payload from the response.
|
org.ballerinalang.jvm.values.ObjectValue |
getNativeRequestObject()
Returns the java native object of the ballerina level http:Response object.
|
String |
getResolvedRequestedURI()
Get the ultimate request URI that was made to receive the response when redirect is on.
|
long |
getResponseCode()
Get the http status code of the response.
|
protected org.ballerinalang.jvm.values.ObjectValue |
getResponseObjectValue() |
String |
getTextPayload()
Extracts `text` payload from the response.
|
org.ballerinalang.jvm.values.api.BXML |
getXmlPayload()
Extracts `xml` payload from the response.
|
boolean |
hasHeader(String headerName)
Checks whether the requested header key exists in the header map.
|
void |
removeAllHeaders()
Removes all the headers from the response.
|
void |
removeHeader(String headerName)
Removes the specified header from the response.
|
void |
setBinaryPayload(byte[] binaryPayload)
Sets a byte[] content as the payload.
|
void |
setBodyParts(Entity[] bodyParts,
String contentType)
Set multiparts as the payload.
|
void |
setByteChannel(org.ballerinalang.stdlib.io.channels.base.Channel byteChannel,
String contentType)
Set byte channel as the payload.
|
void |
setContentType(String contentType)
Sets the `content-type` header to the response.
|
void |
setEntity(Entity entity) |
void |
setHeader(String headerName,
String headerValue)
Sets the specified header to the response.
|
void |
setJsonPayload(org.json.JSONArray jsonArrayPayload)
Sets a json array as the payload.
|
void |
setJsonPayload(org.json.JSONObject jsonPayload)
Sets a json as the payload.
|
void |
setResponseCode(long statusCode)
Set the http status code for the response.
|
void |
setTextPayload(String textPayload)
Sets a string text content as the payload.
|
void |
setXmlPayload(org.ballerinalang.jvm.values.api.BXML xmlPayload)
Sets a xml as the payload.
|
public Response(org.ballerinalang.jvm.values.ObjectValue responseObj)
public Response()
public long getResponseCode()
public void setResponseCode(long statusCode)
statusCode - The status code to be set for the http response.public String getResolvedRequestedURI()
public boolean hasHeader(String headerName)
headerName - The header name.public String getHeader(String headerName)
headerName - The header name.public void addHeader(String headerName, String headerValue)
headerName - The header name.headerValue - The header value.public String[] getHeaders(String headerName)
headerName - The header name.public void setHeader(String headerName, String headerValue)
headerName - The header name.headerValue - The header value.public void removeHeader(String headerName)
headerName - The header name.public void removeAllHeaders()
public String[] getHeaderNames()
public void setContentType(String contentType)
contentType - Content type value to be set as the `content-type` header.public String getContentType()
public org.json.JSONObject getJsonPayload()
throws InterceptorException
JSONObject payload of the request. Null if json body is not found in the response.InterceptorException - If error while getting json payload.public org.json.JSONArray getJsonArrayPayload()
throws InterceptorException
JSONArray payload of the request. Null if json body is not found in the response.InterceptorException - If error while getting json array payload.public org.ballerinalang.jvm.values.api.BXML getXmlPayload()
throws InterceptorException
BXML The `xml` payload of the response.InterceptorException - If error while getting xml payload.public String getTextPayload() throws InterceptorException
InterceptorException - If error while getting text payload.public ByteChannel getByteChannel() throws InterceptorException
ByteChannel A byte channel from which the
message payload can be read.InterceptorException - If error while getting byte channel of the request.public byte[] getBinaryPayload()
throws InterceptorException
InterceptorException - If error while getting byte array of the request.public Entity[] getBodyParts() throws InterceptorException
InterceptorException - if there were any errors constructing the body parts from the reponse.public void setTextPayload(String textPayload)
textPayload - The text payload.public void setBinaryPayload(byte[] binaryPayload)
binaryPayload - The byte[] payload.public void setJsonPayload(org.json.JSONObject jsonPayload)
jsonPayload - JSONObject The json payload.public void setJsonPayload(org.json.JSONArray jsonArrayPayload)
jsonArrayPayload - JSONArray The json payload.public void setXmlPayload(org.ballerinalang.jvm.values.api.BXML xmlPayload)
xmlPayload - The xml BXML payload.public void setBodyParts(Entity[] bodyParts, String contentType)
bodyParts - The entities which make up the message bodycontentType - The content type of the top level message. Set this to override the default
`content-type` header value which is 'multipart/form-data'public void setByteChannel(org.ballerinalang.stdlib.io.channels.base.Channel byteChannel,
String contentType)
byteChannel - Channel Channel object which contains the payload data.contentType - The content type of the top level message. Set this to override the default
`content-type` header value which is 'application/octet-stream'public org.ballerinalang.jvm.values.ObjectValue getNativeRequestObject()
ObjectValue representing the response.public void setEntity(Entity entity)
protected org.ballerinalang.jvm.values.ObjectValue getResponseObjectValue()
public Entity getEntityWithoutBody()
public Entity getEntity()
Copyright © 2021 WSO2. All rights reserved.