ScriptHTTPResp details

ScriptHTTPResp methods enable you to perform such tasks as getting data, getting metadata, and returning the HTTP response code.

Table 1. ScriptHTTPResp methods
ScriptHTTPResp methods Purpose
getData() Gets byte[] data response.
getMetaData() Gets the metadata java.util.Map object that was passed in to the endpoint. This method contains some of the JMS or Kafka message headers.
getEndPointName() Gets the name string of the endpoint.
getResponseMsg() Returns the response status message from the HTTP call.
getResponseCode() Returns the HTTP response code.
setError(Exception e) Sets the error java.lang.Exception instance by analyzing the HTTP response.
It is common to need a custom authentication before invoking the target URL. One way to do that is to attempt that authentication call in the headerProps(req) call back, as that provides the script the opportunity to set that custom authentication header to the request. Note that the script invokes the token API to set the generated token to the request header of the request for the target URL.
from psdi.iface.mic import MicUtil

def headerProps(req):

    authTokenUri = "http://sometokenurl/token"
    apikey = MicUtil.getProperty("mxe.customservice.apikey")
    headers = "apikey:"+apikey
    tokenJson = req.httpgetasjson(authTokenUri,None,headers,None)
    token = tokenJson.get("authtoken")