web stats
Mirth Community - View Single Post - Http sender session issue
View Single Post
  #6  
Old 06-03-2014, 05:09 AM
rts rts is offline
Mirth Guru
 
Join Date: Feb 2008
Posts: 215
rts is an unknown quantity at this point
Default

If I need more granular control of HTTP senders I typically use a javascript writer based on the following:
try {
var data = 'xxxx';

var destURL = $('DEST_IP');
if(destURL == '' || destURL == null)
destURL = 'https://xxxxxx'
var url = new java.net.URL(destURL);
var conn = url.openConnection();

conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-length", data.length);

conn.setRequestProperty("Content-type", "application/soap+xml");

var outStream = conn.getOutputStream();

var outWriter = new java.io.OutputStreamWriter(outStream);

outWriter.write(data);
outWriter.close();
var respCode = conn.getResponseCode(); // Get numeric code 200, 403 ..
// Get response
getResponse();
if (respCode != 200) {

// Do something with response
}
else {



}
catch(err) {
logger.info(' WebSvc - ERR : ' + err);
channelMap.put('RESPONSE', err);
responseMap.put('WEBSVC', ResponseFactory.getFailureResponse(err))

throw(err);
}



function getResponse()
{
var inputStream = conn.getInputStream();
var streamReader = new java.io.InputStreamReader(inputStream);
var respStream = new java.io.BufferedReader(streamReader);


var buffer = '';
var line = null;
while ((line = respStream.readLine()) != null) {

//buffer = buffer + line + '\n';
logger.info('LINE:' + line);
buffer = buffer + line;
}

channelMap.put('RESPONSE', buffer);
responseMap.put('WEBSVC', ResponseFactory.getSuccessResponse(buffer))
respStream.close();
logger.info('HTTP Class Soap Response:' + buffer);
}
Reply With Quote