1836 lines
64 KiB
JavaScript
1836 lines
64 KiB
JavaScript
// --------------------------------------------------------------------------------------
|
|
// Common.js
|
|
// Copyright 2014 SG|facilitor. 053-4800 700, helpdesk@sgfacilitor.nl
|
|
// Written by MB (2014)
|
|
//
|
|
// MAREON Connector/Adapter Ax -> FACILITOR en Facilitor -> Ax
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
//var proxy = "127.0.0.1:8888"; // Voor debugging met Fiddler
|
|
|
|
|
|
// Helper functies
|
|
// 2013-11-13T07:00:00
|
|
|
|
function AX_or_Tobias(){
|
|
if (G_ax_url != "") return "A";
|
|
else {if (G_tobias_url != "") return "T";
|
|
else {if (G_ax2012_url != "") return "A12";
|
|
else {if (G_ax365_url_supplierservice != "" || G_ax365_url_serviceax != "") return "A365";
|
|
else {if (G_fclt_url != "") return "F";
|
|
else {if (G_rems_opdracht_xmlfolder != "") return "R";
|
|
else {if (G_twinq_url != "") return "TQ";
|
|
else return "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function api_F_PutXML(v_xml, v_API)
|
|
{
|
|
|
|
var v_APIKEY = G_marx_apikey;
|
|
var v_req = v_xml;
|
|
var v_type = 1; // xml
|
|
var v_soap_envelop = 0;
|
|
__Log(v_req,3);
|
|
|
|
var l_result_data = apiFCLT(G_marx_url, v_API, v_APIKEY, v_req, v_type, v_soap_envelop, 0);
|
|
//l_result_data is XML object, use method .xml to return xml-text.
|
|
return l_result_data.xml;
|
|
|
|
}
|
|
|
|
// v_type = 0 (JSon Plain text is returned)
|
|
// v_type = 1 (XMLresponse is returned)
|
|
function apiFCLT(v_URL, v_API, v_APIKEY, v_req, v_type, v_soap_envelope, v_discard_active_abort)
|
|
{
|
|
var l_result = apiFCLT_inner(v_URL, v_API, v_APIKEY, v_req, v_type, v_soap_envelope, v_discard_active_abort);
|
|
return l_result.api_response_message;
|
|
}
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
|
|
function apiFCLT_inner(v_URL, v_API, v_APIKEY, v_req, v_type, v_soap_envelope, v_discard_active_abort)
|
|
{
|
|
__Log("Version Mareon Adapter: " + G_Mareon_Adapter,3);
|
|
__Log("apiFCLT v_URL: " + v_URL,3);
|
|
__Log("apiFCLT v_API: " + v_API,3);
|
|
__Log("apiFCLT v_APIKEY: " + v_APIKEY,4);
|
|
__Log("apiFCLT v_type: " + v_type,3);
|
|
__Log("apiFCLT v_soap_envelope: " + v_soap_envelope,3);
|
|
__Log("apiFCLT v_discard_active_abort: " + v_discard_active_abort,3);
|
|
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
// var xmlhttp = new ActiveXObject("WinHTTP.WinHTTPRequest.5.1");
|
|
var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
|
|
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
var xmlUrl = v_URL + "?API=" + v_API + "&APIKEY=" + v_APIKEY + "&MareonAdapter=" + G_Mareon_Adapter;
|
|
__Log("apiFCLT - Open Command",4);
|
|
xmlhttp.open("POST", xmlUrl, false);
|
|
__Log("apiFCLT - setRequestHeader",4);
|
|
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
|
|
|
|
if (v_type == 0){
|
|
var msg = v_req;
|
|
}
|
|
else if (v_type == 1){
|
|
var msg = "" + v_req;
|
|
}
|
|
if (v_soap_envelope == 1){
|
|
__Log("apiFCLT - Extra Soap Envelop",4);
|
|
msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
+ "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"
|
|
+ " xmlns:xsd='http://www.w3.org/2001/XMLSchema'"
|
|
+ " xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
|
|
+ " <soap:Body>"
|
|
+ v_req
|
|
+ " </soap:Body>"
|
|
+ "</soap:Envelope>";
|
|
}
|
|
|
|
__Log("apiFCLT - Send msg: " + msg,4);
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
try{
|
|
xmlhttp.send(msg);
|
|
if (v_type == 1){
|
|
var result_data = xmlhttp.responseXML;
|
|
if (v_API != "MAREONINFO"){
|
|
//Mareon info bevat secrets, die gaan we nooit loggen...
|
|
__Log("apiFCLT - XML :" + result_data.xml, 3);
|
|
if (G_log_level == 4){
|
|
var l_xml = xmlhttp.responseBody;
|
|
var l_logfolder = GetLogFolder();
|
|
WriteXML2File(l_logfolder + "/", v_API, "xml" , l_xml);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{ if (v_API != "MAREONINFO"){
|
|
//Mareon info bevat secrets, die gaan we nooit loggen...
|
|
var txt = xmlhttp.responseText || "{}";
|
|
var result_data = eval("(" + txt + ")");
|
|
__Log("apiFCLT - XML :" + result_data,3);
|
|
}
|
|
}
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
__Log("apiFCLT failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: "", api_response_message: ""};
|
|
//return "";
|
|
}
|
|
|
|
var txt = "";
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: result_data};
|
|
}
|
|
else
|
|
{
|
|
__Log("apiFCLT - HTTP <> 2xx",1);
|
|
__Log("Status: "+ xmlhttp.status + " " + xmlhttp.statusText,1);
|
|
__Log("ResponseText:" + xmlhttp.responseText,1);
|
|
var l_statusText = xmlhttp.status + " " + xmlhttp.statusText + " " + xmlhttp.responseText;
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: result_data};
|
|
}
|
|
}
|
|
|
|
|
|
function FcltAPI2(v_apikey, v_method, v_url, v_req, v_discard_active_abort, v_suppress_req_logging)
|
|
{
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
__Log("FcltAPI2 v_method: " + v_method, 3);
|
|
__Log("FcltAPI2 v_url: " + v_url, 3);
|
|
__Log("FcltAPI2 v_suppress_req_logging: " + v_suppress_req_logging, 3);
|
|
if (!v_suppress_req_logging){
|
|
__Log("FcltAPI2 v_req: " + v_req, 3);
|
|
}
|
|
__Log("FcltAPI2 v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
|
|
try
|
|
{
|
|
var objXMLHTTP = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
|
|
var SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
objXMLHTTP.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
objXMLHTTP.open(v_method, v_url, false);
|
|
|
|
objXMLHTTP.setRequestHeader ("X-FACILITOR-API-Key", v_apikey);
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
objXMLHTTP.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
|
|
try{
|
|
objXMLHTTP.send(v_req);
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
__Log("FcltAPI2 failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
if (objXMLHTTP.status >= 200 && objXMLHTTP.status <= 299)
|
|
{
|
|
return objXMLHTTP;
|
|
}
|
|
else{
|
|
__Log("FcltAPI2 - HTTP status < 200 or status >= 300",1);
|
|
__Log("objXMLHTTP.status: " + objXMLHTTP.status + " " + objXMLHTTP.statusText ,1);
|
|
__Log("objXMLHTTP.responseText: " + objXMLHTTP.responseText ,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
catch (e){
|
|
__Log("FcltAPI2 failed: " + e.description,1);
|
|
}
|
|
}
|
|
|
|
|
|
function MARX_Send_Succes_Or_Failure(p_ref_key, p_import_action, p_extra_omschr){
|
|
var l_marx_api = "ACTION_REF_KEY";
|
|
var l_xml = "<action><action_code>" + p_import_action + "</action_code>" + "<ref_key>" + p_ref_key + "</ref_key>" + "<extra_omschr>" + p_extra_omschr + "</extra_omschr></action>";
|
|
l_xml = "<xml>" + l_xml + "</xml>";
|
|
api_F_PutXML(l_xml, l_marx_api);
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// Resultaat is response-bericht
|
|
// Wrapper om apiAX_GENERAL heen, zodat de bestaande functie apiAX blijft doen wat die altijd al deed (compatibiliteit).
|
|
function apiAX (v_API, v_req, v_type, v_soapAction, v_discard_active_abort)
|
|
{
|
|
var v_soort_api = 1; // (nav MARX#61048: Documenten versturen van Mareon naar AX) is waarde 1 (oude/huidige api via SupplierService) of waarde 2 (nieuwe api via CustomerPortalAX)
|
|
var l_result = apiAX_GENERAL(v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api);
|
|
return l_result.api_response_message;
|
|
}
|
|
|
|
|
|
//MARX#61048: Documenten versturen van Mareon naar AX (Stadgenoot)
|
|
//API van document-upload verloopt op geheel andere wijze, NIET obv de huidige SupplierService/SupplierPortal webservice
|
|
//Maar op basis van CustomerPortalAX (oid)..., zeg maar de 2e variant, die noemen we api_AX2
|
|
function api_AX2 (v_API, v_req, v_type, v_soapAction, v_discard_active_abort)
|
|
{
|
|
var v_soort_api = 2; // (nav MARX#61048: Documenten versturen van Mareon naar AX) is waarde 1 (oude/huidige api via SupplierService) of waarde 2 (nieuwe api via CustomerPortalAX)
|
|
var l_result = apiAX_GENERAL(v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api);
|
|
return l_result.api_response_message;
|
|
}
|
|
|
|
// v_discard_active_abort , values 0 or 1, 0/false = do NOT discard active-abort-flag from Mareon, 1/true = do discard active-abort flag from Mareon
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
// v_soort_api (nav MARX#61048: Documenten versturen van Mareon naar AX) is waarde 1 (oude/huidige api via SupplierService) of waarde 2 (nieuwe api via CustomerPortalAX)
|
|
function apiAX_GENERAL (v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api)
|
|
{
|
|
__Log("-Start---------------------" + v_API + "---------------------------------",3);
|
|
var l_result;
|
|
if (AX_or_Tobias() == "A")
|
|
{
|
|
switch (v_soort_api){
|
|
case 1: var v_url = G_ax_url; break;
|
|
case 2: var v_url = G_ax_url_serviceax; break;
|
|
}
|
|
l_result = api2AX_inner(v_url, v_API, v_req, v_type, v_discard_active_abort, v_soort_api);
|
|
}
|
|
if (AX_or_Tobias() == "A12")
|
|
{
|
|
switch (v_soort_api){
|
|
case 1: var v_url = G_ax2012_url; break;
|
|
case 2: var v_url = G_ax2012_url_serviceax + "/" + v_API; break;
|
|
}
|
|
l_result = api2_AX2012_inner(v_url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api);
|
|
}
|
|
if (AX_or_Tobias() == "A365")
|
|
{
|
|
switch (v_soort_api){
|
|
case 1: var v_url = G_ax365_url_supplierservice; var v_token = G_Token_supplierservice; break;
|
|
case 2: var v_url = G_ax365_url_serviceax + "/" + v_API; var v_token = G_Token_saxton; break;
|
|
}
|
|
l_result = api2_AX365_inner(v_url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api, v_token);
|
|
}
|
|
if (AX_or_Tobias() == "TQ")
|
|
{
|
|
var v_url = G_twinq_url;
|
|
var v_token = G_Token_saxton;
|
|
l_result = api2_TWINQ_inner(v_url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api, v_token);
|
|
}
|
|
if (AX_or_Tobias() == "T")
|
|
{
|
|
// laatste parameter is runmethod, hier altijd 0 (= standaard runmethod van Tobias)
|
|
l_result = api2Tobias_inner(G_tobias_url, v_API, v_req, v_type, 0, v_discard_active_abort);
|
|
}
|
|
if (AX_or_Tobias() == "F")
|
|
{
|
|
l_result = apiFCLT_inner (G_fclt_url, v_API, G_fclt_apikey, v_req, v_type, v_soapAction, v_discard_active_abort);
|
|
}
|
|
__Log("api_status_code: " + l_result.api_status_code,3);
|
|
__Log("api_status_message " + l_result.api_status_message,3);
|
|
__Log("api_response_message: " + l_result.api_response_message,3);
|
|
__Log("-End -------------------" + v_API + "---------------------------------",3);
|
|
|
|
return l_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function api2AX_RequestXML(p_url, p_api, p_req_xml){
|
|
var v_msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
+ "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">"
|
|
+ "<s:Header>"
|
|
+ "<a:Action s:mustUnderstand=\"1\">http://tempuri.org/ISupplierService/" + p_api + "</a:Action>"
|
|
+ "<a:To s:mustUnderstand=\"1\">"+ p_url + "</a:To>"
|
|
+ "</s:Header>"
|
|
+ "<s:Body>"
|
|
+ p_req_xml
|
|
+ "</s:Body>"
|
|
+ "</s:Envelope>";
|
|
return v_msg;
|
|
}
|
|
function api_AX2_RequestXML(p_url, p_api, p_req_xml){
|
|
var v_msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
+ "<s:Envelope xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\" xmlns:cus=\"http://www.SG.nl/services/20121122/CustomerPortalAX\" xmlns:sg=\"http://schemas.datacontract.org/2004/07/SG.Models.Global\">"
|
|
+ "<s:Header>"
|
|
+ "<a:Action s:mustUnderstand=\"1\">http://www.SG.nl/services/20121122/CustomerPortalAX/IServiceCustomerPortalAX/" + p_api + "</a:Action>"
|
|
+ "</s:Header>"
|
|
+ "<s:Body>"
|
|
+ p_req_xml
|
|
+ "</s:Body>"
|
|
+ "</s:Envelope>"
|
|
return v_msg;
|
|
}
|
|
|
|
function api2AX_Dispose(p_url, p_xmlhttp, v_discard_active_abort){
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
// Close de business connector elke keer weer (zou intern in webservice kunnen/moeten).
|
|
var v_API_dispose = "Dispose";
|
|
var v_req_dispose = "<Dispose xmlns=\"http://tempuri.org/\">"
|
|
+ "</Dispose>";
|
|
try
|
|
{
|
|
v_msg = api2AX_RequestXML(p_url, v_API_dispose, v_req_dispose);
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
p_xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
p_xmlhttp.send(v_msg);
|
|
}
|
|
catch (e)
|
|
{
|
|
// Error op dispose
|
|
__Log("api2AX_Dispose failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
}
|
|
}
|
|
|
|
function api2_AX2012_RequestXML(p_url, p_api, p_req_xml){
|
|
var v_msg = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> '+
|
|
'<s:Header>' +
|
|
'<h:CallContext xmlns:h="http://schemas.microsoft.com/dynamics/2010/01/datacontracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">' +
|
|
'<h:Company i:nil="true"/>'+
|
|
'<h:Language i:nil="true"/>'+
|
|
'<h:LogonAsUser>'+ G_ax2012_logonAs + '</h:LogonAsUser>' +
|
|
'<h:MessageId i:nil="true"/>'+
|
|
'<h:PartitionKey i:nil="true"/>'+
|
|
'<h:PropertyBag i:nil="true" xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>'+
|
|
'</h:CallContext>' +
|
|
'</s:Header>' +
|
|
'<s:Body>'+ p_req_xml +
|
|
'</s:Body>'+
|
|
'</s:Envelope>';
|
|
return v_msg;
|
|
}
|
|
|
|
function api2_AX2012_RequestJSON(p_url, p_api, p_req_json){
|
|
var v_msg = p_req_json;
|
|
return v_msg;
|
|
}
|
|
|
|
function api2_AX365_RequestXML(p_url, p_api, p_req_xml){
|
|
var v_msg = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> '+
|
|
'<s:Header>' +
|
|
'<h:CallContext xmlns:h="http://schemas.microsoft.com/dynamics/2010/01/datacontracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"/>' +
|
|
'</s:Header>' +
|
|
'<s:Body>'+ p_req_xml +
|
|
'</s:Body>'+
|
|
'</s:Envelope>';
|
|
return v_msg;
|
|
}
|
|
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
function api2AX_inner (v_Url, v_API, v_req, v_type, v_discard_active_abort, v_soort_api)
|
|
{
|
|
|
|
__Log("api2AX_inner v_API: " + v_API, 3);
|
|
__Log("api2AX_inner v_type: " + v_type, 3);
|
|
__Log("api2AX_inner v_req: " + v_req, 3);
|
|
__Log("api2AX_inner v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
__Log("api2AX_inner v_soort_api: " + v_soort_api, 3);
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
var xmlhttp = new ActiveXObject("WinHTTP.WinHTTPRequest.5.1");
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
xmlhttp.open("POST", v_Url, false);
|
|
xmlhttp.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
|
|
|
|
switch (v_soort_api){
|
|
case 1: var v_msg = api2AX_RequestXML(v_Url, v_API, v_req); break;
|
|
case 2: var v_msg = api_AX2_RequestXML(v_Url, v_API, v_req); break;
|
|
}
|
|
__Log("api2AX_inner v_msg: " + v_msg, 4);
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
try{
|
|
xmlhttp.send(v_msg);
|
|
switch (v_type)
|
|
{
|
|
case 0:
|
|
var txt = xmlhttp.responseText;
|
|
break;
|
|
case 1:
|
|
var txt = xmlhttp.responseBody;
|
|
break;
|
|
}
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
__Log("api2AX_inner failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: "", api_response_message: ""};
|
|
//return "";
|
|
}
|
|
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{
|
|
try
|
|
{
|
|
__Log("api2AX_inner XML Response = TRUE :", 3);
|
|
__Log("api2AX_inner XML Response :" + txt, 3);
|
|
if (v_soort_api == 1){
|
|
// Alleen in geval van api-1 een dispose...
|
|
api2AX_Dispose(v_Url, xmlhttp, v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return txt;
|
|
}
|
|
catch (e)
|
|
{
|
|
// Waarschijnlijk http-error terug gekregen
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return "";
|
|
|
|
}
|
|
}
|
|
else
|
|
{ __Log("api2AX_inner XML Response = FALSE :",1);
|
|
__Log("api2AX_inner api2AX - HTTP <> 2xx",1);
|
|
__Log("api2AX_inner URL: " + v_Url,1);
|
|
__Log("api2AX_inner Message: " + v_msg.substr(0,4*1024),1);
|
|
__Log("api2AX_inner Status: "+ xmlhttp.status + " " + xmlhttp.statusText,1);
|
|
__Log("api2AX_inner ResponseText:" + xmlhttp.responseText,1);
|
|
if (v_soort_api == 1){
|
|
api2AX_Dispose(v_Url, xmlhttp, v_discard_active_abort);
|
|
}
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return ""
|
|
}
|
|
}
|
|
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
function api2_AX2012_inner (v_Url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api)
|
|
{
|
|
|
|
__Log("api2_AX2012_inner v_API: " + v_API, 3);
|
|
__Log("api2_AX2012_inner v_type: " + v_type, 3);
|
|
__Log("api2_AX2012_inner v_req: " + v_req, 3);
|
|
__Log("api2_AX2012_inner v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
__Log("api2_AX2012_inner v_soort_api: " + v_soort_api, 3);
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
var xmlhttp = new ActiveXObject("WinHTTP.WinHTTPRequest.5.1");
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
xmlhttp.open("POST", v_Url, false);
|
|
|
|
if (v_soort_api == 1){
|
|
xmlhttp.setRequestHeader("Content-Type", "text/xml");
|
|
xmlhttp.setRequestHeader("Authorization", "Basic " + G_ax2012_bcProxy);
|
|
xmlhttp.setRequestHeader("SOAPAction", '"http://tempuri.org/'+v_soapAction+'"');
|
|
var v_msg = api2_AX2012_RequestXML(v_Url, v_API, v_req);
|
|
}
|
|
if (v_soort_api == 2){
|
|
xmlhttp.setRequestHeader("Content-Type", "application/json"),
|
|
__Log("api2_AX2012_inner G_Token_saxton: " + G_Token_saxton, 4);
|
|
xmlhttp.setRequestHeader("Authorization", "Bearer " + G_Token_saxton);
|
|
//xmlhttp.setRequestHeader("SOAPAction", '"http://tempuri.org/'+v_soapAction+'"');
|
|
var v_msg = api2_AX2012_RequestJSON(v_Url, v_API, v_req);
|
|
}
|
|
|
|
__Log("api2_AX2012_inner v_msg: " + v_msg, 4);
|
|
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
try {
|
|
xmlhttp.send(v_msg);
|
|
switch (v_type)
|
|
{
|
|
case 0:
|
|
var txt = xmlhttp.responseText;
|
|
break;
|
|
case 1:
|
|
var txt = xmlhttp.responseBody;
|
|
break;
|
|
}
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
__Log("api2_AX2012_inner failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: "", api_response_message: ""};
|
|
//return "";
|
|
}
|
|
|
|
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{
|
|
try
|
|
{
|
|
__Log("api2_AX2012_inner XML Response = TRUE :", 3);
|
|
__Log("api2_AX2012_inner XML Response :" + txt, 3);
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return txt;
|
|
}
|
|
catch (e)
|
|
{
|
|
// Waarschijnlijk http-error terug gekregen
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return "";
|
|
}
|
|
}
|
|
else
|
|
{ __Log("api2_AX2012_inner XML Response = FALSE :",1);
|
|
__Log("api2_AX2012_inner - HTTP <> 2xx",1);
|
|
__Log("api2_AX2012_inner URL: " + v_Url,1);
|
|
__Log("api2_AX2012_inner Message: " + v_msg.substr(0,4*1024),1);
|
|
__Log("api2_AX2012_inner Status: "+ xmlhttp.status + " " + xmlhttp.statusText,1);
|
|
l_resp = xmlhttp.responseText;
|
|
__Log("api2_AX2012_inner ResponseText:" + l_resp,1);
|
|
|
|
|
|
if (v_soort_api== 2 && xmlhttp.status == 401){
|
|
// In geval van soort-api=2, is Token expired? Kan heel goed mogelijk zijn, token heeft geldigheid van uur
|
|
// In dit geval wordt een HTTP 401 (Unautorized) geretourneerd, (itt AX365, die doet HTTP-500)
|
|
|
|
// Forbidden gevonden, we doen een retry, door een nieuwe token op te halen / op te vragen, max. 3 x in een sync (G_AX365_Allowed_Get_Token > 0)
|
|
if (G_AX365_Allowed_Get_Token > 0){
|
|
G_AX365_Allowed_Get_Token = G_AX365_Allowed_Get_Token - 1;
|
|
G_Token_saxton = A2012_saxton_GetToken();
|
|
// We mogen nu de functie zelf nog eens aanroepen (iteratief).
|
|
l_result = api2_AX2012_inner (v_Url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api);
|
|
return l_result;
|
|
}
|
|
else{
|
|
__Log("api2_AX2012_inner: Token problem, maximum van 3 pogingen zijn allemaal mislukt" ,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
}
|
|
}
|
|
else{
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
}
|
|
}
|
|
}
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
function api2_AX365_inner (v_Url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api, v_token)
|
|
{
|
|
|
|
|
|
__Log("api2_AX365_inner v_API: " + v_API, 3);
|
|
__Log("api2_AX365_inner v_type: " + v_type, 3);
|
|
__Log("api2_AX365_inner v_req: " + v_req, 3);
|
|
__Log("api2_AX365_inner v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
__Log("api2_AX365_inner v_soort_api: " + v_soort_api, 3);
|
|
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
|
|
var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
xmlhttp.open("POST", v_Url, false);
|
|
|
|
__Log("api2_AX365_inner v_token: " + v_token, 4);
|
|
xmlhttp.setRequestHeader("Authorization", "Bearer " + v_token);
|
|
|
|
if (v_soort_api == 1){
|
|
xmlhttp.setRequestHeader("Content-Type", "text/xml");
|
|
xmlhttp.setRequestHeader("SOAPAction", '"http://tempuri.org/'+v_soapAction+'"');
|
|
var v_msg = api2_AX365_RequestXML(v_Url, v_API, v_req);
|
|
}
|
|
else {
|
|
xmlhttp.setRequestHeader("Content-Type", "application/json");
|
|
var v_msg = v_req;
|
|
}
|
|
__Log("api2_AX365_inner v_msg: " + v_msg, 4);
|
|
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
try {
|
|
xmlhttp.send(v_msg);
|
|
switch (v_type)
|
|
{
|
|
case 0:
|
|
var txt = xmlhttp.responseText;
|
|
break;
|
|
case 1:
|
|
var txt = xmlhttp.responseBody;
|
|
break;
|
|
}
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
var txt = "api2_AX365_inner failed/timeout: " + e.description;
|
|
__Log(txt,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: "", api_response_message: txt};
|
|
//return "";
|
|
}
|
|
var l_statusText = xmlhttp.status + " " + xmlhttp.statusText;
|
|
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{
|
|
try
|
|
{
|
|
__Log("api2_AX365_inner XML Response = TRUE :", 3);
|
|
__Log("api2_AX365_inner XML Response :" + txt, 3);
|
|
return {api_status_code: 1, api_status_message: l_statusText, api_response_message: txt};
|
|
//return txt;
|
|
}
|
|
catch (e)
|
|
{
|
|
// Waarschijnlijk http-error terug gekregen
|
|
return {api_status_code: 1, api_status_message: l_statusText, api_response_message: txt};
|
|
//return "";
|
|
}
|
|
}
|
|
else
|
|
{ __Log("api2_AX365_inner XML Response = FALSE :",1);
|
|
__Log("api2_AX365_inner - HTTP <> 2xx",1);
|
|
__Log("api2_AX365_inner URL: " + v_Url,1);
|
|
__Log("api2_AX365_inner Message: " + v_msg.substr(0,4*1024),1);
|
|
__Log("api2_AX365_inner Status: "+ l_statusText,1);
|
|
l_resp = xmlhttp.responseText;
|
|
__Log("api2_AX365_inner ResponseText:" + l_resp,1);
|
|
|
|
if (xmlhttp.status == 500 || xmlhttp.status == 401){
|
|
// SupplierService geeft HTTP 500 in geval van Unauthorized, AX Saxton webservice 'CustomerPortalAX' geeft HTTP 401
|
|
// Token expired? Kan heel goed mogelijk zijn, token heeft geldigheid van uur, en is om
|
|
// Als in response (dit is XML) de faultcode forbidden is, dan is dat het geval:
|
|
// <faultcode xmlns:a="http://schemas.microsoft.com/2009/WebFault">a:Forbidden</faultcode>
|
|
// Bij HTTP401 (in geval CustomerPortalAX) is er geen XML die terugkomt.
|
|
// MARX#69545 Factuur scanning 365 werkt niet door update in Tobias 365, vandaar extra check op NativeErrorCode 1287
|
|
if (xmlhttp.status == 401 || l_resp.search(">a:Forbidden</faultcode>") != -1 || l_resp.search(">1287</NativeErrorCode>") != -1) {
|
|
// Forbidden gevonden, we doen een retry, door een nieuwe token op te halen / op te vragen, max. 3 x in een sync (G_AX365_Allowed_Get_Token > 0)
|
|
if (G_AX365_Allowed_Get_Token > 0){
|
|
G_AX365_Allowed_Get_Token = G_AX365_Allowed_Get_Token - 1;
|
|
switch (v_soort_api){
|
|
case 1: G_Token_supplierservice = A365_supplierservice_GetToken(); var l_token = G_Token_supplierservice; break;
|
|
case 2: G_Token_saxton = A365_saxton_GetToken(); var l_token = G_Token_saxton; break;
|
|
}
|
|
|
|
// We mogen nu de functie zelf nog eens aanroepen (iteratief).
|
|
l_result = api2_AX365_inner (v_Url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api, l_token);
|
|
return l_result;
|
|
}
|
|
else{
|
|
__Log("api2_AX365_inner: Token problem, maximum van 3 pogingen zijn allemaal mislukt" ,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: txt};
|
|
//return ""
|
|
}
|
|
|
|
}
|
|
else{
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: txt};
|
|
//return ""
|
|
}
|
|
}
|
|
else {
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: txt};
|
|
}
|
|
}
|
|
}
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
function api2_TWINQ_inner (v_Url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api, v_token)
|
|
{
|
|
__Log("api2_TWINQ_inner v_API: " + v_API, 3);
|
|
__Log("api2_TWINQ_inner v_type: " + v_type, 3);
|
|
__Log("api2_TWINQ_inner v_req: " + v_req, 3);
|
|
__Log("api2_TWINQ_inner v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
__Log("api2_TWINQ_inner v_soort_api: " + v_soort_api, 3);
|
|
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
|
|
var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
xmlhttp.open("POST", v_Url, false);
|
|
|
|
__Log("api2_TWINQ_inner v_token: " + v_token, 4);
|
|
xmlhttp.setRequestHeader("Authorization", "Bearer " + v_token);
|
|
xmlhttp.setRequestHeader("Content-Type", "text/plain");
|
|
var v_msg = v_req;
|
|
|
|
__Log("api2_TWINQ_inner v_msg: " + v_msg, 4);
|
|
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
try {
|
|
xmlhttp.send(v_msg);
|
|
var txt = xmlhttp.responseText;
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
var txt = "api2_TWINQ_inner failed/timeout: " + e.description;
|
|
__Log(txt,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: "", api_response_message: txt};
|
|
//return "";
|
|
}
|
|
var l_statusText = xmlhttp.status + " " + xmlhttp.statusText;
|
|
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{
|
|
try
|
|
{
|
|
__Log("api2_TWINQ_inner XML Response = TRUE :", 3);
|
|
__Log("api2_TWINQ_inner XML Response :" + txt, 3);
|
|
return {api_status_code: 1, api_status_message: l_statusText, api_response_message: txt};
|
|
//return txt;
|
|
}
|
|
catch (e)
|
|
{
|
|
// Waarschijnlijk http-error terug gekregen
|
|
return {api_status_code: 1, api_status_message: l_statusText, api_response_message: txt};
|
|
//return "";
|
|
}
|
|
}
|
|
else
|
|
{ __Log("api2_TWINQ_inner XML Response = FALSE :",1);
|
|
__Log("api2_TWINQ_inner - HTTP <> 2xx",1);
|
|
__Log("api2_TWINQ_inner URL: " + v_Url,1);
|
|
__Log("api2_TWINQ_inner Message: " + v_msg.substr(0,4*1024),1);
|
|
__Log("api2_TWINQ_inner Status: "+ l_statusText,1);
|
|
l_resp = xmlhttp.responseText;
|
|
__Log("api2_TWINQ_inner ResponseText:" + l_resp,1);
|
|
|
|
if (xmlhttp.status == 500 || xmlhttp.status == 401){
|
|
// SupplierService geeft HTTP 500 in geval van Unauthorized, AX Saxton webservice 'CustomerPortalAX' geeft HTTP 401
|
|
// Token expired? Kan heel goed mogelijk zijn, token heeft geldigheid van uur, en is om
|
|
// Als in response (dit is XML) de faultcode forbidden is, dan is dat het geval:
|
|
// <faultcode xmlns:a="http://schemas.microsoft.com/2009/WebFault">a:Forbidden</faultcode>
|
|
// Bij HTTP401 (in geval CustomerPortalAX) is er geen XML die terugkomt.
|
|
// MARX#69545 Factuur scanning 365 werkt niet door update in Tobias 365, vandaar extra check op NativeErrorCode 1287
|
|
if (xmlhttp.status == 401) {
|
|
// Forbidden gevonden, we doen een retry, door een nieuwe token op te halen / op te vragen, max. 3 x in een sync (G_AX365_Allowed_Get_Token > 0)
|
|
if (G_AX365_Allowed_Get_Token > 0){
|
|
G_AX365_Allowed_Get_Token = G_AX365_Allowed_Get_Token - 1;
|
|
G_Token_saxton = TWINQ_GetToken(); var l_token = G_Token_saxton;
|
|
|
|
|
|
// We mogen nu de functie zelf nog eens aanroepen (iteratief).
|
|
l_result = api2_TWINQ_inner (v_Url, v_API, v_req, v_type, v_soapAction, v_discard_active_abort, v_soort_api, l_token);
|
|
return l_result;
|
|
}
|
|
else{
|
|
__Log("api2_TWINQ_inner: Token problem, maximum van 3 pogingen zijn allemaal mislukt" ,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: txt};
|
|
//return ""
|
|
}
|
|
|
|
}
|
|
else{
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: txt};
|
|
//return ""
|
|
}
|
|
}
|
|
else {
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: l_statusText, api_response_message: txt};
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function apiIDentity (v_url, v_req, v_type, v_contenttype, v_discard_active_abort, v_basic_authentication, v_secret)
|
|
{
|
|
|
|
__Log("apiIDentity v_url: " + v_url, 3);
|
|
__Log("apiIDentity v_req: " + v_req, 3);
|
|
__Log("apiIDentity v_type: " + v_type, 3);
|
|
__Log("apiIDentity v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
__Log("apiIDentity v_basic_authentication: " + v_basic_authentication, 3);
|
|
|
|
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP.6.0");
|
|
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
xmlhttp.open("POST", v_url, false);
|
|
xmlhttp.setRequestHeader("Content-Type", v_contenttype);
|
|
if (v_basic_authentication == 1)
|
|
{
|
|
__Log("apiIDentity l_secret: " + v_secret, 4);
|
|
xmlhttp.setRequestHeader("Authorization", "Basic " + v_secret);
|
|
}
|
|
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
|
|
try {
|
|
xmlhttp.send(v_req);
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
__Log("apiIDentity failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{
|
|
try
|
|
{ var txt = xmlhttp.responseText;
|
|
|
|
__Log("apiIDentity Response :" + txt, 3);
|
|
return txt;
|
|
}
|
|
catch (e)
|
|
{
|
|
// Waarschijnlijk http-error terug gekregen
|
|
|
|
__Log("apiIDentity failed: " + e.description,1);
|
|
__Log(txt,1);
|
|
return "";
|
|
}
|
|
}
|
|
else
|
|
{ __Log("apiIDentity - HTTP <> 2xx",1);
|
|
__Log("URL: " + v_url,1);
|
|
__Log("Request: " + v_req.substr(0,4*1024),1);
|
|
__Log("Status: "+ xmlhttp.status + " " + xmlhttp.statusText,1);
|
|
__Log("ResponseText:" + xmlhttp.responseText,1);
|
|
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {}
|
|
}
|
|
}
|
|
|
|
|
|
// Parameter RunMethod = 0 of 1.
|
|
// Tobias kent 2 methoden:
|
|
// 1. RunMethod (dan parameter v_runmethod = 0)
|
|
// 2. RunStream (dan parameter v_runmethod = 1)
|
|
|
|
// Levert/retourneert een rij (struct) op van de volgende waarden:
|
|
// api_status_code: 0 of 1, 0 = fout gegaan, 1 = goed gegaan
|
|
// api_status_message: statustekst behorende bij status_code (http.statusText)
|
|
// api_response_message: response-berecht van webservice (api) die wordt aangeroepen.
|
|
|
|
function api2Tobias_inner (v_Url, v_API, v_req, v_type, v_runmethod, v_discard_active_abort)
|
|
{
|
|
|
|
|
|
__Log("apiTobias v_API: " + v_API, 3);
|
|
__Log("apiTobias v_type: " + v_type, 3);
|
|
__Log("apiTobias v_req: " + v_req, 3);
|
|
__Log("apiTobias v_discard_active_abort: " + v_discard_active_abort, 3);
|
|
|
|
var lResolve = 0;
|
|
var lConnect = 60 * 1000;
|
|
var lSend = 30 * 1000;
|
|
|
|
var xmlhttp = new ActiveXObject("WinHTTP.WinHTTPRequest.5.1");
|
|
SXH_PROXY_SET_PROXY = 2;
|
|
if (typeof proxy != "undefined" && proxy)
|
|
xmlhttp.setProxy(SXH_PROXY_SET_PROXY, proxy);
|
|
|
|
xmlhttp.open("POST", v_Url, false);
|
|
|
|
xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=UTF-8");
|
|
|
|
var l_tobias_appserver = Read_Ini_Setting("tobias","appserver");
|
|
var l_methodlocation = Read_Ini_Setting("tobias","methodlocation");
|
|
|
|
var v_msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
+ "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tob=\"http://sg.nl/TobiasConnect/\">"
|
|
+ "<soapenv:Header/>"
|
|
+ "<soapenv:Body>";
|
|
//+ "<tob:RunMethod>"
|
|
//+ " <!--Optional:-->"
|
|
//+ " <tob:Methode>" + v_API + "</tob:Methode>"
|
|
//+ " <!--Optional:-->"
|
|
//+ " <tob:Parameters>"
|
|
//+ " <!--Optional:-->"
|
|
//+ " <tob:AppServer>" + l_tobias_appserver + "</tob:AppServer>"
|
|
//+ " <!--Optional:-->"
|
|
//+ " <tob:MethodLocation>" + l_methodlocation + "</tob:MethodLocation>"
|
|
//+ " <!--Optional:-->"
|
|
//+ " <tob:ParameterList>"
|
|
//+ v_req
|
|
//+ " </tob:ParameterList>"
|
|
//+ " </tob:Parameters>"
|
|
//+ "</tob:RunMethod>"
|
|
//+ "</soapenv:Body>"
|
|
//+ " </soapenv:Envelope>"
|
|
|
|
|
|
if (v_API != "$RUNSTREAM"){
|
|
|
|
v_msg = v_msg
|
|
+ "<tob:RunMethod>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:Methode>" + v_API + "</tob:Methode>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:Parameters>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:AppServer>" + l_tobias_appserver + "</tob:AppServer>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:MethodLocation>" + l_methodlocation + "</tob:MethodLocation>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:ParameterList>"
|
|
+ v_req
|
|
+ " </tob:ParameterList>"
|
|
+ " </tob:Parameters>"
|
|
+ "</tob:RunMethod>";
|
|
|
|
}
|
|
else
|
|
{
|
|
v_msg = v_msg
|
|
+ "<tob:RunStream>"
|
|
+ " <tob:xml>"
|
|
+ v_req
|
|
+ " </tob:xml>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:appserver>" + l_tobias_appserver + "</tob:appserver>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:systeem>IeWorX</tob:systeem>"
|
|
+ " <!--Optional:-->"
|
|
+ " <tob:functie>AanbiedenFactuur</tob:functie>"
|
|
+ " <tob:deleteXml>false</tob:deleteXml>"
|
|
+ "</tob:RunStream>";
|
|
|
|
|
|
}
|
|
|
|
v_msg = v_msg
|
|
+ "</soapenv:Body>"
|
|
+ " </soapenv:Envelope>";
|
|
if (G_mar_timeout != 0){
|
|
//MARX#57502: AX Adapter robuuster maken, instelbare timeout
|
|
xmlhttp.setTimeouts(lResolve, lConnect, lSend, G_mar_timeout * 1000);
|
|
}
|
|
try{
|
|
xmlhttp.send(v_msg);
|
|
switch (v_type)
|
|
{
|
|
case 0:
|
|
var txt = xmlhttp.responseText;
|
|
break;
|
|
case 1:
|
|
var txt = xmlhttp.responseBody;
|
|
break;
|
|
}
|
|
}
|
|
catch (e)
|
|
{
|
|
//MARX#57502: AX Adapter robuuster maken: Waarschijnlijk timeout-error
|
|
__Log("api2Tobias failed/timeout: " + e.description,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: "", api_response_message: ""};
|
|
//return "";
|
|
}
|
|
|
|
if (xmlhttp.status >= 200 && xmlhttp.status <= 299)
|
|
{ var txt = "";
|
|
try
|
|
{
|
|
__Log("XML :" + txt, 3);
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return txt;
|
|
}
|
|
catch (e)
|
|
{
|
|
// Waarschijnlijk http-error terug gekregen
|
|
return {api_status_code: 1, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
__Log("api2Tobias - HTTP <> 2xx",1);
|
|
__Log("URL: " + v_Url,1);
|
|
__Log("Request: " + v_req.substr(0,4*1024),1);
|
|
__Log("Status: "+ xmlhttp.status + " " + xmlhttp.statusText,1);
|
|
__Log("ResponseText:" + xmlhttp.responseText,1);
|
|
if (G_abort_http_error == 1)
|
|
{
|
|
MARXQUIT(v_discard_active_abort);
|
|
}
|
|
return {api_status_code: 0, api_status_message: xmlhttp.statusText, api_response_message: txt};
|
|
//return ""
|
|
}
|
|
}
|
|
|
|
|
|
function WriteXML2File(p_path, p_filenaam, p_extension, p_xml) {
|
|
|
|
v_timestamp = displayTimeStamp();
|
|
var v_filename = p_path + p_filenaam + v_timestamp + "." + p_extension;
|
|
|
|
oStream = new ActiveXObject("ADODB.Stream");
|
|
oStream.Open();
|
|
oStream.Type = 1; // adTypeBinary
|
|
oStream.Write(p_xml); // responseText geeft encoding problemen!
|
|
oStream.SaveToFile (v_filename, 2); // adSaveCreateOverWrite
|
|
oStream.Close();
|
|
}
|
|
|
|
function WriteText2File(p_path, p_filenaam, p_extension, p_txt, p_timestamp_in_filename, p_adodb_stream) {
|
|
__Log("WriteText2File - p_path: " + p_path, 2);
|
|
__Log("WriteText2File - p_filenaam: " + p_filenaam, 2);
|
|
__Log("WriteText2File - p_extension: " + p_extension, 2);
|
|
__Log("WriteText2File - p_txt: " + p_txt, 3);
|
|
v_timestamp = "";
|
|
if (p_timestamp_in_filename == 1){
|
|
v_timestamp = displayTimeStamp();
|
|
}
|
|
var v_filename = p_path + p_filenaam + v_timestamp + "." + p_extension;
|
|
|
|
if (p_adodb_stream == 1){
|
|
oStream = new ActiveXObject("ADODB.Stream");
|
|
oStream.Open();
|
|
//oStream.Type = 1; // adTypeBinary
|
|
oStream.WriteText(p_txt); // responseText geeft encoding problemen!
|
|
oStream.SaveToFile (v_filename, 2); // adSaveCreateOverWrite
|
|
oStream.Close();
|
|
}
|
|
else {
|
|
var flog = fso.OpenTextFile(v_filename, 2 /* ForWriting */, true /*Create if not exists */);
|
|
flog.WriteLine(p_txt);
|
|
flog.Close();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function displayTimeStamp() {
|
|
var str = "";
|
|
|
|
var currentTime = new Date();
|
|
var currentTime = new Date();
|
|
|
|
var jaar = currentTime.getFullYear();
|
|
var maand = currentTime.getMonth();
|
|
var dag = currentTime.getDate();
|
|
var hours = currentTime.getHours();
|
|
var minutes = currentTime.getMinutes();
|
|
var seconds = currentTime.getSeconds();
|
|
var millsec = currentTime.getMilliseconds();
|
|
|
|
maand = maand + 1;
|
|
if (maand < 10) {
|
|
maand = "0" + maand
|
|
}
|
|
if (dag < 10) {
|
|
dag = "0" + dag
|
|
}
|
|
if (minutes < 10) {
|
|
minutes = "0" + minutes
|
|
}
|
|
if (seconds < 10) {
|
|
seconds = "0" + seconds
|
|
}
|
|
if (millsec < 10) {
|
|
millsec = "0" + millsec
|
|
}
|
|
if (millsec < 100) {
|
|
millsec = "0" + millsec
|
|
}
|
|
str += jaar + "-" + maand + "-" + dag + "T" + hours + "_" + minutes + "_" + seconds + "_" + millsec;
|
|
|
|
return str;
|
|
}
|
|
|
|
|
|
function xmltojsdate(datestamp)
|
|
{
|
|
var pattern = /^(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)$/;
|
|
var pieces = datestamp.match(pattern);
|
|
if(!pieces || pieces.length < 6)
|
|
return null;
|
|
|
|
return new Date(pieces[1], pieces[2]-1, pieces[3], pieces[4], pieces[5], pieces[6]);
|
|
}
|
|
function jsdatextoxml(dt)
|
|
{
|
|
return toDateString(dt) + "T" + toTimeString(dt);
|
|
}
|
|
function jsdatetoiso(dt)
|
|
{
|
|
return dt.getUTCFullYear() + '-'
|
|
+ padout(dt.getUTCMonth() + 1) + '-'
|
|
+ padout(dt.getUTCDate()) + 'T'
|
|
+ padout(dt.getUTCHours()) + ':'
|
|
+ padout(dt.getUTCMinutes()) + ':'
|
|
+ padout(dt.getUTCSeconds()) + 'Z';
|
|
}
|
|
|
|
function jsdatetosqls(jsDate)
|
|
{
|
|
return jsDate.getVarDate();
|
|
}
|
|
function padout(n) { return (n < 10) ? "0" + n : String(n); }
|
|
|
|
// Noot: altijd jaar vooraan, goed voor logfiles, niet bedoeld voor presentatie
|
|
function toDateString(jsDate)
|
|
{
|
|
return padout(jsDate.getFullYear()) + "-" + padout(jsDate.getMonth() + 1) + "-" + padout(jsDate.getDate());
|
|
}
|
|
|
|
function toTimeString(jsDate)
|
|
{
|
|
return padout(jsDate.getHours()) + ":" + padout(jsDate.getMinutes()) + ":" + padout(jsDate.getSeconds());
|
|
}
|
|
|
|
|
|
function __Log(s, level)
|
|
{
|
|
try{
|
|
if (level == undefined) level=0;
|
|
if (G_log_level > 0 || level==0){
|
|
if (level <= G_log_level){
|
|
WScript.Echo(s);
|
|
// MARX#34568: Foutmelding "path not found". De LOG-folder aanmaken voorkomt dit...
|
|
var v_log_folder = GetLogFolder();
|
|
CreateFolder(v_log_folder)
|
|
var logname = GetLogFileNameInclPath("", "");
|
|
var flog = fso.OpenTextFile(logname, 8 /* ForAppending */, true /* create */);
|
|
var tms = toDateString(new Date) + " " + toTimeString(new Date);
|
|
flog.WriteLine(tms + " " +s);
|
|
flog.Close();
|
|
}
|
|
}
|
|
}
|
|
catch (e)
|
|
{
|
|
try{
|
|
var logname = GetLogFileNameInclPath("", "");
|
|
var flog = fso.OpenTextFile(logname, 8 , true );
|
|
flog.WriteLine("Warning/Error in functie __Log, kan 's' niet loggen: houdt verband met MARX#52225: " + e.description);
|
|
flog.Close();
|
|
}
|
|
catch(e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
//Maak nieuwe folder.
|
|
//bv. p_folder = c:/temp/maaknieuwefolder, dan worden folders temp en maaknieuwefolder nieuwe anagemaakt (als ze nog niet bestonden)
|
|
function CreateFolder(p_folder){
|
|
var l_folders = p_folder.split("/");
|
|
var i = 0;
|
|
var l_folder = l_folders[i];
|
|
while (i<l_folders.length){
|
|
if (l_folder.indexOf(":") == -1){
|
|
//geen directory/drive met : (we moeten bij c:/temp/...) de c: overslaan, hier kunnen we uiteraard geen folder van maken
|
|
// en anders wel, d.w.z. als deze niet al bestaat ;-)
|
|
if (!fso.FolderExists(l_folder)) fso.CreateFolder(l_folder);
|
|
}
|
|
i = i + 1;
|
|
l_folder = l_folder + "/" + l_folders[i]
|
|
}
|
|
}
|
|
|
|
function GetLogFolder()
|
|
{
|
|
//MARX#66742: De logging van de sync adapter voor AX365 per klant
|
|
var l_log_folder = "Log";
|
|
var l_cust_name = GetFileNameWithoutExtensieFromPath(G_settings_xml_file);
|
|
if (l_cust_name.length > 0){
|
|
l_log_folder = l_log_folder + "/" + l_cust_name;
|
|
}
|
|
return l_log_folder;
|
|
}
|
|
function GetFileNameWithExtensieFromPath(v_file_incl_pad)
|
|
{
|
|
var l_folder_split = v_file_incl_pad.split("/");
|
|
if (l_folder_split != v_file_incl_pad){
|
|
// Er zitten / in het pad, dit pad is nu gesplitst (=ongelijk aan origineel), we pakken nu het laatste deel op (daar staat de filenaam immers)
|
|
var l_cust_file = l_folder_split.slice(-1).join();
|
|
}
|
|
else{
|
|
var l_folder_split = v_file_incl_pad.split("\\");
|
|
if (l_folder_split != v_file_incl_pad){
|
|
// Er zitten \\ in het pad, dit pad is nu gesplitst (=ongelijk aan origineel), we pakken nu het laatste deel op (daar staat de filenaam immers)
|
|
var l_cust_file = l_folder_split.slice(-1).join();
|
|
}
|
|
else l_cust_file = v_file_incl_pad;
|
|
}
|
|
return l_cust_file;
|
|
}
|
|
|
|
// Retourneert uit een pad incl de bestandsnaam alleen bestandsnaam ZONDER extensie en Zonder pad
|
|
function GetFileNameWithoutExtensieFromPath(v_file_incl_pad)
|
|
{
|
|
var l_cust_file = GetFileNameWithExtensieFromPath(v_file_incl_pad);
|
|
l_cust_file = l_cust_file.split(".").shift();
|
|
return l_cust_file;
|
|
}
|
|
|
|
function GetLogFileNameInclPath(v_datum, v_dagdeel)
|
|
{
|
|
var l_folder = GetLogFolder();
|
|
var l_filenaam = GetLogFileName(v_datum, v_dagdeel);
|
|
return l_folder + "/Mareon_" + l_filenaam;
|
|
}
|
|
|
|
//Bepaalt de naam van het logbestand:
|
|
//v_datum is leeg, dan de huidige datum (sysdate), anders de datum in formaat yyyy-mm-dd van welke dag de logbestand geupload moet worden
|
|
//v_dagdeel is a, b, c of d (a=nacht tot 6h, b=ochtend tot12h, c = middag tot 18h, d=avond vanaf 18h)
|
|
function GetLogFileName(v_datum, v_dagdeel)
|
|
{
|
|
var l_dagdeel = v_dagdeel;
|
|
if (v_datum == ""){
|
|
var dt = new Date;
|
|
var h = dt.getHours();
|
|
|
|
if (h<6) l_dagdeel = "a";
|
|
else if (h<12) l_dagdeel = "b";
|
|
else if (h<18) l_dagdeel = "c";
|
|
else l_dagdeel = "d";
|
|
|
|
date_of_logging = padout(dt.getFullYear()) + "_" + padout(dt.getMonth() + 1) + "_" + padout(dt.getDate());
|
|
}
|
|
else {
|
|
date_of_logging = v_datum.replace('-','_').replace('-','_');
|
|
}
|
|
return date_of_logging + "_" + l_dagdeel + ".log";
|
|
}
|
|
|
|
function FCLT_SendLogFile(v_datum){
|
|
// Ophalen van alle 4 logbestanden van de dag (mogelijk zijn ze nog niet allemaal aanwezig, dat mag):
|
|
// a, b, c of d (a=nacht tot 6h, b=ochtend tot12h, c = middag tot 18h, d=avond vanaf 18h)
|
|
var logfilename = GetLogFileName(v_datum, "a");
|
|
var logfilename_path = GetLogFileNameInclPath(v_datum, "a");
|
|
FCLT_SendLogFile_Inner(logfilename, logfilename_path);
|
|
var logfilename = GetLogFileName(v_datum, "b");
|
|
var logfilename_path = GetLogFileNameInclPath(v_datum, "b");
|
|
FCLT_SendLogFile_Inner(logfilename, logfilename_path);
|
|
var logfilename = GetLogFileName(v_datum, "c");
|
|
var logfilename_path = GetLogFileNameInclPath(v_datum, "c");
|
|
FCLT_SendLogFile_Inner(logfilename, logfilename_path);
|
|
var logfilename = GetLogFileName(v_datum, "d");
|
|
var logfilename_path = GetLogFileNameInclPath(v_datum, "d");
|
|
FCLT_SendLogFile_Inner(logfilename, logfilename_path);
|
|
}
|
|
|
|
|
|
function FCLT_SendLogFile_Inner (logfilename, logfilename_path){
|
|
|
|
__Log("Start Sending logfile:" + logfilename_path, 2);
|
|
var jsonXMLhttp = FcltAPI2(G_marx_apikey, "GET", G_marx_url + "api2/persons.json?id=self", "", 0, 0); // data van jezelf
|
|
__Log("jsonXMLhttp binnen", 4);
|
|
var data = JSON.parse(jsonXMLhttp.responseText);
|
|
__Log("Data:" + data, 4);
|
|
|
|
var prs_perslid_key = data.person.id;
|
|
var kenmerk_key = 22; // Van folder bijlage kenmerk 'logfiles'
|
|
|
|
// POST naar https://marx.facilitor.nl/api2/persons/12345/attachments/20/Mareon_2018_04_19.log.txt
|
|
// Extensie .log mag wellicht niet, daarom .txt erachter geplakt...
|
|
__Log("Start Read Logfile: ", 4);
|
|
var v_filecontent = ReadAsciiFile(logfilename_path);
|
|
__Log("End Read Logfile: ", 4);
|
|
var v_url = G_marx_url + "api2/persons/" + prs_perslid_key + "/attachments/" + kenmerk_key + "/" + logfilename + ".txt" + "?filesize=" + v_filecontent.length;
|
|
|
|
if (v_filecontent != ""){
|
|
__Log("Begin Sending logfile:" + logfilename_path, 1);
|
|
//MARX#61654: Mareon sync adapter: upload logbestand logt ook het logbestand zelf
|
|
var v_suppress_req_logging = 1; // Filecontent (logbestand) wil je niet zelf (nogeens/dubbelop) in het logbestand gelogd hebben (dubbelop), dus onderdrukken.
|
|
FcltAPI2(G_marx_apikey, "POST", v_url, v_filecontent, 0, v_suppress_req_logging);
|
|
__Log("End Sending logfile:" + logfilename_path, 1);
|
|
}
|
|
else{
|
|
__Log("Cannot send logfile, does not exist:" + logfilename_path, 1);
|
|
}
|
|
}
|
|
|
|
// Values v_section = ax, facilitor of common.
|
|
// Values v_ini -> allerlei
|
|
function Read_Ini_Setting(v_section, v_ini){
|
|
var v_result = "";
|
|
try{
|
|
var l_node = "//ini/" + v_section + "/" + v_ini;
|
|
var v_result = Read_XML_File_Node(G_settings_xml_file, l_node);
|
|
return v_result;
|
|
}
|
|
catch (e)
|
|
{
|
|
__Log("Warning Read_Ini_Setting not found: " + l_node + " - " + e.description, 4);
|
|
return v_result;
|
|
}
|
|
}
|
|
|
|
function Read_XML (v_xml_file){
|
|
var l_xml = null;
|
|
__Log("Read_XML: " + v_xml_file, 4);
|
|
try{
|
|
l_xml=new ActiveXObject("Microsoft.XMLDOM");
|
|
l_xml.async=false;
|
|
l_xml.load(v_xml_file);
|
|
return l_xml;
|
|
}
|
|
catch (e)
|
|
{
|
|
__Log("Warning Read_XML: " + v_xml_file + " - " + e.description,1);
|
|
return l_xml;
|
|
}
|
|
}
|
|
|
|
//Neemt van string v_str het gedeelte van positie 1 tot de eerste (v_last = 0) of tot de laatste (v_last = 1) voorkomende karakter (teken) v_char
|
|
//Dus MARX_substr("marcel.bestand.txt", ".", 0) --> "marcel"
|
|
//En MARX_substr("marcel.bestand.txt", ".", 1) --> "marcel.bestand"
|
|
//Als v_char niet in v_str staat, dan wordt lege string "" opgeleverd.
|
|
function MARX_substr (v_str, v_char, v_last){
|
|
var l_result = "";
|
|
var l_pos_T = v_str.indexOf(v_char);
|
|
if (l_pos_T >= 0){
|
|
l_result = v_str.substr(0, l_pos_T);
|
|
if (v_last == 1){
|
|
l_rest = v_str.substr(l_pos_T + 1);
|
|
l_result2 = MARX_substr (l_rest, v_char, v_last);
|
|
if (l_result2 != ""){
|
|
l_result = l_result + v_char + l_result2;
|
|
}
|
|
}
|
|
}
|
|
return l_result;
|
|
}
|
|
|
|
function MARX_replaceAll(str, find, replace) {
|
|
return str.replace(new RegExp(find, 'g'), replace);
|
|
}
|
|
|
|
function STR_2_XML (v_str){
|
|
var xmldoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
|
|
xmldoc.async = false;
|
|
xmldoc.loadXML(v_str);
|
|
return xmldoc;
|
|
}
|
|
|
|
|
|
function Read_XML_File_Node(v_xml_file, v_node_name){
|
|
var v_result = "";
|
|
try{
|
|
l_xml = Read_XML(v_xml_file);
|
|
var v_result = Read_XML_Node(l_xml, v_node_name);
|
|
return v_result;
|
|
}
|
|
catch (e)
|
|
{
|
|
__Log("Warning Read_XML_File_Node: " + v_node_name + " - " + e.description,3);
|
|
return v_result;
|
|
}
|
|
}
|
|
|
|
|
|
function Read_XML_Node(v_xml, v_node_name){
|
|
var v_result = "";
|
|
try{
|
|
var v_result = v_xml.selectSingleNode(v_node_name).text;
|
|
return v_result;
|
|
}
|
|
catch (e)
|
|
{
|
|
__Log("Warning: node: '" + v_node_name + "' not found " + e.description,3);
|
|
return v_result;
|
|
}
|
|
}
|
|
|
|
function __Log_XML(p_xmldoc, p_node, level){
|
|
|
|
if (p_xmldoc){
|
|
x=p_xmldoc.documentElement.childNodes;
|
|
for (i=0;i<x.length;i++)
|
|
{
|
|
if (x[i].nodeType==1)
|
|
{//Process only element nodes (type 1)
|
|
__Log("__Log_XML: " + x[i].nodeName, level, 2);
|
|
//__Log_XML(x[i], x[i].nodeName + "/", level);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Copied from \UTILS\PutOrders\puo_base64.js
|
|
function Base64Cls()
|
|
{
|
|
// Private variabelen
|
|
this._keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
|
|
|
// Public functies
|
|
this.encode = _encode;
|
|
this.decode = _decode;
|
|
|
|
|
|
// private method for UTF-8 encoding
|
|
function utf8_encode(string)
|
|
{
|
|
string = string.replace(/\r\n/g,"\n");
|
|
var utftext = "";
|
|
|
|
for (var n = 0; n < string.length; n++)
|
|
{
|
|
var c = string.charCodeAt(n);
|
|
|
|
if (c < 128)
|
|
{
|
|
utftext += String.fromCharCode(c);
|
|
}
|
|
else if((c > 127) && (c < 2048))
|
|
{
|
|
utftext += String.fromCharCode((c >> 6) | 192);
|
|
utftext += String.fromCharCode((c & 63) | 128);
|
|
}
|
|
else
|
|
{
|
|
utftext += String.fromCharCode((c >> 12) | 224);
|
|
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
utftext += String.fromCharCode((c & 63) | 128);
|
|
}
|
|
}
|
|
return utftext;
|
|
}
|
|
|
|
// private method for UTF-8 decoding
|
|
function utf8_decode(utftext)
|
|
{
|
|
var string = "";
|
|
var i = 0;
|
|
var c = c1 = c2 = 0;
|
|
|
|
while ( i < utftext.length )
|
|
{
|
|
c = utftext.charCodeAt(i);
|
|
|
|
if (c < 128)
|
|
{
|
|
string += String.fromCharCode(c);
|
|
i++;
|
|
}
|
|
else if((c > 191) && (c < 224))
|
|
{
|
|
c2 = utftext.charCodeAt(i+1);
|
|
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
|
|
i += 2;
|
|
}
|
|
else
|
|
{
|
|
c2 = utftext.charCodeAt(i+1);
|
|
c3 = utftext.charCodeAt(i+2);
|
|
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
|
|
i += 3;
|
|
}
|
|
|
|
}
|
|
return string;
|
|
}
|
|
|
|
|
|
function _encode(input)
|
|
{
|
|
var output = "";
|
|
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
var i = 0;
|
|
|
|
input = utf8_encode(input);
|
|
|
|
while (i < input.length)
|
|
{
|
|
chr1 = input.charCodeAt(i++);
|
|
chr2 = input.charCodeAt(i++);
|
|
chr3 = input.charCodeAt(i++);
|
|
|
|
enc1 = chr1 >> 2;
|
|
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
|
|
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
|
|
enc4 = chr3 & 63;
|
|
|
|
if (isNaN(chr2))
|
|
{
|
|
enc3 = enc4 = 64;
|
|
}
|
|
else if (isNaN(chr3))
|
|
{
|
|
enc4 = 64;
|
|
}
|
|
|
|
output = output +
|
|
this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
|
|
this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
|
|
|
|
}
|
|
return output;
|
|
}
|
|
|
|
function _decode(input)
|
|
{
|
|
var output = "";
|
|
var chr1, chr2, chr3;
|
|
var enc1, enc2, enc3, enc4;
|
|
var i = 0;
|
|
|
|
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
|
|
|
while (i < input.length)
|
|
{
|
|
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
|
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
|
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
|
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
|
|
|
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
|
|
output = output + String.fromCharCode(chr1);
|
|
|
|
if (enc3 != 64)
|
|
{
|
|
output = output + String.fromCharCode(chr2);
|
|
}
|
|
if (enc4 != 64)
|
|
{
|
|
output = output + String.fromCharCode(chr3);
|
|
}
|
|
}
|
|
output = utf8_decode(output);
|
|
|
|
return output;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function encodeBase64(p_bytes){
|
|
l_xml=new ActiveXObject("Msxml2.DOMDocument.6.0");
|
|
// Create temporary node with Base64 data type
|
|
xml_element = l_xml.createElement("tmp");
|
|
xml_element.dataType = "bin.base64";
|
|
// Set bytes, get encoded String
|
|
xml_element.nodeTypedValue = p_bytes
|
|
return xml_element.text;
|
|
}
|
|
|
|
function ReadBinaryFile (p_filename)
|
|
{
|
|
oStream = new ActiveXObject("ADODB.Stream");
|
|
oStream.Open();
|
|
oStream.Type = 1; // adTypeBinary
|
|
oStream.LoadFromFile(p_filename);
|
|
return oStream.Read;
|
|
}
|
|
|
|
function BinaryFile_2_Base64(p_filename)
|
|
{
|
|
var v_base64="";
|
|
__Log("Start BinaryFile_2_Base64: " + p_filename, 2);
|
|
if (fso.FileExists(p_filename)){
|
|
__Log("File Exists: " + p_filename, 2);
|
|
var bytes = ReadBinaryFile(p_filename);
|
|
v_base64 = encodeBase64(bytes);
|
|
__Log("Einde BinaryFile_2_Base64: " + v_base64, 4);
|
|
}
|
|
return v_base64;
|
|
}
|
|
|
|
function BinaryStream_2_Base64(p_apikey, p_url)
|
|
{
|
|
var v_base64="";
|
|
__Log("Start BinaryStream_2_Base64", 2);
|
|
var fileXMLHTTP = FcltAPI2(p_apikey, "GET", p_url, "", 0, 0);
|
|
if (fileXMLHTTP){
|
|
__Log("BinaryStream_2_Base64 URL Exists: " + p_url, 3);
|
|
v_base64 = encodeBase64(fileXMLHTTP.responseBody);
|
|
}
|
|
else{
|
|
__Log("BinaryStream_2_Base64 URL NOT Exists: " + p_url, 3);
|
|
}
|
|
__Log("Einde BinaryFile_2_Base64: " + v_base64, 4);
|
|
return v_base64;
|
|
}
|
|
|
|
function ReadAsciiFile (p_filename)
|
|
{
|
|
__Log("ReadAsciiFile: " + p_filename, 2);
|
|
if (fso.FileExists(p_filename)){
|
|
__Log("ReadAsciiFile Exists: " + p_filename, 2);
|
|
flog=fso.OpenTextFile(p_filename,1, false);
|
|
v_result=flog.ReadAll();
|
|
flog.Close()
|
|
return v_result;
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
function ReadLineAsciiFile (p_filename)
|
|
{
|
|
__Log("ReadLineAsciiFile: " + p_filename, 2);
|
|
if (fso.FileExists(p_filename)){
|
|
__Log("ReadLineAsciiFile Exists: " + p_filename, 2);
|
|
flog=fso.OpenTextFile(p_filename,1, false);
|
|
v_result=flog.ReadLine();
|
|
flog.Close()
|
|
return v_result;
|
|
}
|
|
else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
//Move van bestand p_filename naar p_bckfolder. Let op, p_bckfolder moet eindigen met een slash '/'
|
|
//Met p_prefix kun je een prefix (string) meegeven, b.v. een timestamp die in de backup-bestand moet worden opgenomen tbv b.v. uniciteit.
|
|
function Move_file_2_bck_folder(p_filename, p_bckfolder, p_new_filename){
|
|
try
|
|
{
|
|
if (!fso.FolderExists(p_bckfolder)){
|
|
fso.CreateFolder(p_bckfolder);
|
|
}
|
|
fso.MoveFile(p_filename, p_bckfolder + p_new_filename);
|
|
}
|
|
catch (e)
|
|
{
|
|
__Log("Error in backup function Move_file_2_bck_folder " + p_filename + " - " + p_bckfolder + p_new_filename + ":" + e.description, 1);
|
|
MARXQUIT(0);
|
|
}
|
|
|
|
}
|
|
|
|
// Vervangt de XML reserved char's door gelijknamige XML equivalent.
|
|
function escapeXml (s) {
|
|
var XML_CHAR_MAP = {
|
|
'<': '<',
|
|
'>': '>',
|
|
'&': '&',
|
|
'"': '"',
|
|
"'": '''
|
|
};
|
|
|
|
return s.replace(/[<>&"']/g, function (ch) {
|
|
return XML_CHAR_MAP[ch];
|
|
});
|
|
}
|
|
|
|
myJSON =
|
|
{
|
|
internal_parsedate: function (key, value)
|
|
{
|
|
var a;
|
|
if (typeof value === 'string') {
|
|
a = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
|
if (a) {
|
|
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4], +a[5], +a[6]));
|
|
}
|
|
}
|
|
return value;
|
|
},
|
|
// myJSON.parse doet hetzelfde als JSON.parse maar herkent automatisch datum variabelen
|
|
parse: function _parse(text)
|
|
{
|
|
return JSON.parse(text, myJSON.internal_parsedate);
|
|
}
|
|
}
|
|
|
|
function MARXQUIT(v_discard_active_abort){
|
|
if (v_discard_active_abort == 0)
|
|
{
|
|
__Log("MARXQUIT: ------------------------------------------------------------",0);
|
|
__Log("MARXQUIT: ACTIVE ABORT MAREON SYNC ADAPTER (COMMUNICATION)ERROR",0);
|
|
__Log("MARXQUIT: ------------------------------------------------------------",0);
|
|
WScript.Quit();
|
|
}
|
|
}
|
|
|
|
//---------------------------------------------------------------------------------------------------------------------------------
|