<commit_before>/**
 * XSLT transformation scenario - transform the soap body so that the service can understand 
 * the request and client the response
 */

var SUPPORT_LIBS = '../lib/support/';
var XSLT_RES = './resources/xslt/';
var logger = require('../lib/logger');

var soapErrorMsg = require('../lib/util/errormsg/soap_err_msg');

exports.executeSample = function(zenithMessage, callback) {
	var reqUrl = zenithMessage.transportHeaders.url; // returns url object

	if (reqUrl.pathname === '/services/StockQuoteProxy') {

		var serviceURL = 'http://localhost:9000/services/SimpleStockQuoteService';
		logger.debug('SampleConfig', 'EPR: ' + serviceURL);

		var option = {
			url : serviceURL
		};

		var endpoint = require(SUPPORT_LIBS + 'ws_endpoint');
		var xslt = require(SUPPORT_LIBS + 'xml/xslt_processor');
		var saxProcessor = require(SUPPORT_LIBS + 'xml/sax_processor');
		
		var xsltFile = XSLT_RES + 'transform.xslt';
		var xsltFile_back = XSLT_RES + 'transform_back.xslt';
		
		//transform soap body to something that the real service can understand
		var transformedMsg = xslt
				.transformXML(zenithMessage.body, xsltFile, []);
		
		// create the soap message using original soap headers and transformed soap body
		saxProcessor.getTransformedSOAP(zenithMessage.body, transformedMsg, function(err, transformedSOAP){
			
			zenithMessage.body = transformedSOAP;
			endpoint.callService(zenithMessage, option, function(err, message) { 

				// transformed the response so that the client can understand the format.
				var transformedBckMsg = xslt.transformXML(message.body, xsltFile_back, []);
		
				saxProcessor.getTransformedSOAP(message.body, transformedBckMsg, function(err, transformedBckSOAP){
					message.body = transformedBckSOAP;
					callback(null, message);
				});
			});
		});
		

	} else {
		var errMsg = 'Invalid EPR value.';
		zenithMessage.body = soapErrorMsg.getSOAP11Fault(errMsg);
		callback(null, zenithMessage);

	}

};<commit_msg>add error handling conditions<commit_after>/**
 * XSLT transformation scenario - transform the soap body so that the service can understand 
 * the request and client the response
 */

var SUPPORT_LIBS = '../lib/support/';
var XSLT_RES = './resources/xslt/';
var logger = require('../lib/logger');
var soapErrorMsg = require('../lib/util/errormsg/soap_err_msg');
var zenithErrorMsg = require('../lib/util/errormsg/zenith_err_msg');

exports.executeSample = function(zenithMessage, callback) {
	var reqUrl = zenithMessage.transportHeaders.url; // returns url object

	if (reqUrl.pathname === '/services/StockQuoteProxy') {

		var serviceURL = 'http://localhost:9000/services/SimpleStockQuoteService';
		logger.debug('SampleConfig', 'EPR: ' + serviceURL);

		var option = {
			url : serviceURL
		};

		var endpoint = require(SUPPORT_LIBS + 'ws_endpoint');
		var xslt = require(SUPPORT_LIBS + 'xml/xslt_processor');
		var saxProcessor = require(SUPPORT_LIBS + 'xml/sax_processor');
		
		var xsltFile = XSLT_RES + 'transform.xslt';
		var xsltFile_back = XSLT_RES + 'transform_back.xslt';
		
		//transform soap body to something that the real service can understand
		var transformedMsg = xslt
				.transformXML(zenithMessage.body, xsltFile, []);
		
		// create the soap message using original soap headers and transformed soap body
		saxProcessor.getTransformedSOAP(zenithMessage.body, transformedMsg, function(err, transformedSOAP){
			
			zenithMessage.body = transformedSOAP;
			endpoint.callService(zenithMessage, option, function(err, message) { 
				
				if(!err){
					// transformed the response so that the client can understand the format.
					var transformedBckMsg = xslt.transformXML(message.body, xsltFile_back, []);
			
					saxProcessor.getTransformedSOAP(message.body, transformedBckMsg, function(err, transformedBckSOAP){
						message.body = transformedBckSOAP;
						callback(null, message);
					});
					
				} else {
					//send error message for external web service error
					//can create more detailed errors by reading fields in 'err' object
					var errMsg = soapErrorMsg.getSOAP11Fault('Connection Refused.'); 
					var errZenithMessage = zenithErrorMsg.getZenithErrorMSG(errMsg, 'text/xml', '503');
					callback(null, errZenithMessage);
				}
				
			});
		});
		

	} else {
		
		var errMsg = oapErrorMsg.getSOAP11Fault('Invalid EPR value.'); 
		var errZenithMessage = zenithErrorMsg.getZenithErrorMSG(errMsg, 'text/xml', '500');
		callback(null, errZenithMessage);

	}

};
{'fraction_non_alphanumeric': 0.11401743796109994, 'fraction_numerical': 0.004471272076905879, 'mean_word_length': 4.190255220417633, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2087385', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1355, 'n_words': 331}