Fixing invoker service return nothing on httpClient requests.

revert-70aa11f8
Rasika Perera 8 years ago
parent 98ab29fe94
commit 3e2731a772

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

Loading…
Cancel
Save