Dears Team ,
I need a help for this . I have requirement, i need to build a https request in data power which will call the backend REST API without manipulating the request header and data . Its just like a passthrough , when client called the data power https URL , then datapower just need to send to backend API dynamically as it is , without manipulating the request.
The backed API is REST API with https protocol .
Client <----> Data power <---> Backend API
Thanks
Dear Morgan,
Thank you for your response . I am not using any TLS or TCP proxy . I am using MPGW as HTTPS handler and backend URL is dynamic ally calling using urlopen.open module , but the challenge for me is how to pass the "application/x-www-form-urlencoded" body parameter in "data" field . I try to use "apim.getvariable('request.body')" but did not work . Please find my gateway script
var urlopen = require ('urlopen');
var apim = require ('apim');
var hm = require('header-metadata');
var sm = require('service-metadata');
var query = require('querystring')
var list = sm.list();
var fullHeaders = hm.current.get();
// Retrieve a json object with all headers in another form
var fullHeaders = hm.current.headers;
console.debug("Full Header : "+JSON.stringify(fullHeaders));
console.debug("Full Service Data : "+JSON.stringify(list));
console.debug("Protocol Method: "+sm.protocolMethod);
console.debug("Protocol URL: "+sm.getVar('var://service/URL-in'));
// define the urlopen options
var options = {
// if target is https, supply a sslProxyProfile
target: "https://xxxxxx"+sm.URI,
sslClientProfile: "client-client-dp-profile",
method: sm.protocolMethod,
//headers: fullHeaders,
accept: 'application/json',
contentType: 'application/x-www-form-urlencoded',
xcorrelationId: '45678210',
timeout: 60,
//data: apim.getvariable('request.body')
data: "grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer&assertion=<Need to put the paramter coming from request>"
};
session.output.write("Request Body: "+options);
console.debug("Request Body: "+JSON.stringify(options));
// open connection to target and send data over
urlopen.open (options, function (error, response) {
if (error) {
// an error occurred during request sending or response header parsing
console.debug("urlopen connect error: " +JSON.stringify(error));
session.output.write ("urlopen connect error: " + JSON.stringify(error));
} else {
// read response data
// get the response status code
var responseStatusCode = response.statusCode;
var responseReasonPhrase = response.reasonPhrase;
console.debug("responseStatusCode: " +responseStatusCode);
if (responseStatusCode == 200) {
response.readAsBuffer(function(error, responseData) {
if (error) {
// error while reading response or transferring data to Buffer
session.output.write("readAsBuffer error: " + JSON.stringify(error));
} else {
session.output.write(responseData);
}
});
} else {
//var hm = require('header-metadata');
var contentType = hm.current.get('content-type');
// Retrieve a json object with all headers
var allHeaders = hm.current.get();
// Retrieve a json object with all headers in another form
var allHeaders = hm.current.headers;
session.output.write({
code: responseStatusCode,
message: responseReasonPhrase,
});
}
}
});
apim.output('application/json');
------------------------------
Anil Nayak
------------------------------