|
|
@ -72,7 +72,7 @@ var invokers = function () {
|
|
|
|
var xmlHttpRequest = new XMLHttpRequest();
|
|
|
|
var xmlHttpRequest = new XMLHttpRequest();
|
|
|
|
|
|
|
|
|
|
|
|
xmlHttpRequest.open(httpMethod, endpoint);
|
|
|
|
xmlHttpRequest.open(httpMethod, endpoint);
|
|
|
|
for(var i in headers){
|
|
|
|
for (var i in headers) {
|
|
|
|
xmlHttpRequest.setRequestHeader(headers[i].name, headers[i].value);
|
|
|
|
xmlHttpRequest.setRequestHeader(headers[i].name, headers[i].value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
|
|
|
xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
|
|
@ -117,7 +117,8 @@ var invokers = function () {
|
|
|
|
* @param endpoint Backend REST API url.
|
|
|
|
* @param endpoint Backend REST API url.
|
|
|
|
* @param responseCallback a function to be called with response retrieved.
|
|
|
|
* @param responseCallback a function to be called with response retrieved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
privateMethods["initiateXMLHTTPRequest"] = function (httpMethod, requestPayload, endpoint, responseCallback, headers) {
|
|
|
|
privateMethods["initiateXMLHTTPRequest"] =
|
|
|
|
|
|
|
|
function (httpMethod, requestPayload, endpoint, responseCallback, headers) {
|
|
|
|
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0, headers);
|
|
|
|
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0, headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -128,7 +129,8 @@ var invokers = function () {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicXMLHTTPInvokers["get"] = function (endpoint, responseCallback, headers) {
|
|
|
|
publicXMLHTTPInvokers["get"] = function (endpoint, responseCallback, headers) {
|
|
|
|
var requestPayload = null;
|
|
|
|
var requestPayload = null;
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback, headers);
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback,
|
|
|
|
|
|
|
|
headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -138,7 +140,8 @@ var invokers = function () {
|
|
|
|
* @param responseCallback a function to be called with response retrieved.
|
|
|
|
* @param responseCallback a function to be called with response retrieved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicXMLHTTPInvokers["post"] = function (endpoint, requestPayload, responseCallback, headers) {
|
|
|
|
publicXMLHTTPInvokers["post"] = function (endpoint, requestPayload, responseCallback, headers) {
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback, headers);
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback,
|
|
|
|
|
|
|
|
headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -148,7 +151,8 @@ var invokers = function () {
|
|
|
|
* @param responseCallback a function to be called with response retrieved.
|
|
|
|
* @param responseCallback a function to be called with response retrieved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicXMLHTTPInvokers["put"] = function (endpoint, requestPayload, responseCallback, headers) {
|
|
|
|
publicXMLHTTPInvokers["put"] = function (endpoint, requestPayload, responseCallback, headers) {
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback, headers);
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback,
|
|
|
|
|
|
|
|
headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -158,7 +162,8 @@ var invokers = function () {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicXMLHTTPInvokers["delete"] = function (endpoint, responseCallback, headers) {
|
|
|
|
publicXMLHTTPInvokers["delete"] = function (endpoint, responseCallback, headers) {
|
|
|
|
var requestPayload = null;
|
|
|
|
var requestPayload = null;
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback, headers);
|
|
|
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint,
|
|
|
|
|
|
|
|
responseCallback, headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -245,7 +250,8 @@ var invokers = function () {
|
|
|
|
* @param errorCallback a function to be called if en error is reserved.
|
|
|
|
* @param errorCallback a function to be called if en error is reserved.
|
|
|
|
* @param headers a list of name value pairs for additional http headers.
|
|
|
|
* @param headers a list of name value pairs for additional http headers.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
privateMethods["initiateHTTPClientRequest"] = function (method, url, successCallback, errorCallback, payload, headers) {
|
|
|
|
privateMethods["initiateHTTPClientRequest"] =
|
|
|
|
|
|
|
|
function (method, url, successCallback, errorCallback, payload, headers) {
|
|
|
|
//noinspection JSUnresolvedVariable
|
|
|
|
//noinspection JSUnresolvedVariable
|
|
|
|
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
|
|
|
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
|
|
|
var httpMethodObject;
|
|
|
|
var httpMethodObject;
|
|
|
@ -277,7 +283,7 @@ var invokers = function () {
|
|
|
|
|
|
|
|
|
|
|
|
//noinspection JSUnresolvedVariable
|
|
|
|
//noinspection JSUnresolvedVariable
|
|
|
|
var Header = Packages.org.apache.commons.httpclient.Header;
|
|
|
|
var Header = Packages.org.apache.commons.httpclient.Header;
|
|
|
|
for(var i in headers){
|
|
|
|
for (var i in headers) {
|
|
|
|
var header = new Header();
|
|
|
|
var header = new Header();
|
|
|
|
header.setName(headers[i].name);
|
|
|
|
header.setName(headers[i].name);
|
|
|
|
header.setValue(headers[i].value);
|
|
|
|
header.setValue(headers[i].value);
|
|
|
@ -321,14 +327,18 @@ var invokers = function () {
|
|
|
|
//noinspection JSUnresolvedFunction
|
|
|
|
//noinspection JSUnresolvedFunction
|
|
|
|
var status = httpMethodObject.getStatusCode();
|
|
|
|
var status = httpMethodObject.getStatusCode();
|
|
|
|
if (status == 200) {
|
|
|
|
if (status == 200) {
|
|
|
|
var responseContentDispositionHeader = httpMethodObject.getResponseHeader(constants["CONTENT_DISPOSITION_IDENTIFIER"]);
|
|
|
|
var responseContentDispositionHeader = httpMethodObject.getResponseHeader(
|
|
|
|
|
|
|
|
constants["CONTENT_DISPOSITION_IDENTIFIER"]);
|
|
|
|
if (responseContentDispositionHeader) {
|
|
|
|
if (responseContentDispositionHeader) {
|
|
|
|
return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders());
|
|
|
|
return successCallback(httpMethodObject.getResponseBodyAsStream(),
|
|
|
|
|
|
|
|
httpMethodObject.getResponseHeaders());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return successCallback(httpMethodObject.getResponseBody());
|
|
|
|
return successCallback(httpMethodObject.getResponseBodyAsString(),
|
|
|
|
|
|
|
|
httpMethodObject.getResponseHeaders());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return errorCallback(httpMethodObject.getResponseBody());
|
|
|
|
return errorCallback(httpMethodObject.getResponseBodyAsString(),
|
|
|
|
|
|
|
|
httpMethodObject.getResponseHeaders());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
} catch (e) {
|
|
|
|
return errorCallback(response);
|
|
|
|
return errorCallback(response);
|
|
|
@ -349,8 +359,8 @@ var invokers = function () {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicHTTPClientInvokers["get"] = function (url, successCallback, errorCallback, headers) {
|
|
|
|
publicHTTPClientInvokers["get"] = function (url, successCallback, errorCallback, headers) {
|
|
|
|
var requestPayload = null;
|
|
|
|
var requestPayload = null;
|
|
|
|
return privateMethods.
|
|
|
|
return privateMethods.initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback,
|
|
|
|
initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload, headers);
|
|
|
|
requestPayload, headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -362,8 +372,8 @@ var invokers = function () {
|
|
|
|
* @param headers a list of name value pairs for additional http headers.
|
|
|
|
* @param headers a list of name value pairs for additional http headers.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicHTTPClientInvokers["post"] = function (url, payload, successCallback, errorCallback, headers) {
|
|
|
|
publicHTTPClientInvokers["post"] = function (url, payload, successCallback, errorCallback, headers) {
|
|
|
|
return privateMethods.
|
|
|
|
return privateMethods.initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback,
|
|
|
|
initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload, headers);
|
|
|
|
payload, headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -375,8 +385,8 @@ var invokers = function () {
|
|
|
|
* @param headers a list of name value pairs for additional http headers.
|
|
|
|
* @param headers a list of name value pairs for additional http headers.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicHTTPClientInvokers["put"] = function (url, payload, successCallback, errorCallback, headers) {
|
|
|
|
publicHTTPClientInvokers["put"] = function (url, payload, successCallback, errorCallback, headers) {
|
|
|
|
return privateMethods.
|
|
|
|
return privateMethods.initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback,
|
|
|
|
initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload, headers);
|
|
|
|
payload, headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -388,8 +398,8 @@ var invokers = function () {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
publicHTTPClientInvokers["delete"] = function (url, successCallback, errorCallback, headers) {
|
|
|
|
publicHTTPClientInvokers["delete"] = function (url, successCallback, errorCallback, headers) {
|
|
|
|
var requestPayload = null;
|
|
|
|
var requestPayload = null;
|
|
|
|
return privateMethods.
|
|
|
|
return privateMethods.initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback,
|
|
|
|
initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload, headers);
|
|
|
|
requestPayload, headers);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var publicMethods = {};
|
|
|
|
var publicMethods = {};
|
|
|
|