<commit_before>var soap = require("soap");


var config;
exports.withConfig = function(theConfig) {
   config = theConfig;
   return this;
};


var CustomError = function(msg, httpStatus) {
   this.message = msg || "Unexpected error!";
   this.httpStatus = httpStatus || 500;
};
CustomError.prototype = Error.prototype;


var resolveWsdl = function(req, res, next) {
   var serviceName = req.params.service,
       wsdlUrl = config.zapiUrl + serviceName + "?wsdl";

   soap.createClient(wsdlUrl, function(err, client) {
      if (err) { 
         throw new CustomError(err.message);
      }

      if (typeof client === "undefined") { 
         throw new CustomError("Unknown WSDL: " + serviceName, 400);
      }

      req._client = client;
      next();
   });
};


var resolveService = function(req, res, next) {
   var client = req._client;

   var description = client.describe(),
       availableMethods = description[req.params.service][req.params.service+"HttpPort"],
       msg = "Unknown method: " + req.params.method + "\nUse one of: " + Object.keys(availableMethods).join(", ");

   if (typeof client[req.params.method] !== "function") {
      console.log(description);
      throw new CustomError(msg, 400);
   }

//    console.log(JSON.stringify(description));
   console.log(availableMethods[req.params.method]);
   req._service = client[req.params.method];
   next();
};


var normalizeQuerystring = function(req, res, next) {
   // TODO
   req._query = req.query;
   next();
};


exports.withServer = function(server) {
   server.error(function(err, req, res, next) {
      if (err instanceof CustomError) {
         res.send(err.message, err.httpStatus);
      } else {
         next(err);
      }
   });<commit_msg>[wip] normalize query string<commit_after>var soap = require("soap");


var config;
exports.withConfig = function(theConfig) {
   config = theConfig;
   return this;
};


var CustomError = function(msg, httpStatus) {
   this.message = msg || "Unexpected error!";
   this.httpStatus = httpStatus || 500;
};
CustomError.prototype = Error.prototype;


var resolveWsdl = function(req, res, next) {
   var serviceName = req.params.service,
       wsdlUrl = config.zapiUrl + serviceName + "?wsdl";

   soap.createClient(wsdlUrl, function(err, client) {
      if (err) { 
         throw new CustomError(err.message);
      }

      if (typeof client === "undefined") { 
         throw new CustomError("Unknown WSDL: " + serviceName, 400);
      }

      req._client = client;
      next();
   });
};


var resolveService = function(req, res, next) {
   var client = req._client;

   var description = client.describe(),
       availableMethods = description[req.params.service][req.params.service+"HttpPort"],
       msg = "Unknown method: " + req.params.method + "\nUse one of: " + Object.keys(availableMethods).join(", ");

   if (typeof client[req.params.method] !== "function") {
      console.log(description);
      throw new CustomError(msg, 400);
   }

   req._query = availableMethods[req.params.method].input;
   console.log(JSON.stringify(req._query));
   req._service = client[req.params.method];
   next();
};


var normalizeQuerystring = function(req, res, next) {
//    req._query = {
//       documentTypeList: { 'DocumentType': ['ALD','MONO'] },
//       productId: 4002
//    }
   for (var key in req._query) {
      if (req._query.hasOwnProperty(key)) {
         req._query[key] = req.query[key];
      }
   }
   next();
};


exports.withServer = function(server) {
   server.error(function(err, req, res, next) {
      if (err instanceof CustomError) {
         res.send(err.message, err.httpStatus);
      } else {
         next(err);
      }
   });
{'fraction_non_alphanumeric': 0.1490397619691642, 'fraction_numerical': 0.005950770895320531, 'mean_word_length': 3.0108459869848154, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7174673', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1119, 'n_words': 246}