@ -1,5 +1,5 @@
/ *
* Copyright ( c ) 201 6 , WSO2 Inc . ( http : //www.wso2.org) All Rights Reserved.
* Copyright ( c ) 201 5 , WSO2 Inc . ( http : //www.wso2.org) All Rights Reserved.
*
* WSO2 Inc . licenses this file to you under the Apache License ,
* Version 2.0 ( the "License" ) ; you may not use this file except
@ -10,34 +10,38 @@
*
* Unless required by applicable law or agreed to in writing ,
* software distributed under the License is distributed on an
* "AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied . See the License for the
* "AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND ,
* either express or implied . See the License for the
* specific language governing permissions and limitations
* under the License .
* /
/ * *
* This backendServiceInvoker contains the wrappers for back end jagg a ry calls .
* This backendServiceInvoker contains the wrappers for back end jagg e ry calls .
* /
var backendServiceInvoker = function ( ) {
var log = new Log ( "/app/modules/backend-service-invoker.js" ) ;
var publicXMLHTTPInvokers = { } ;
var publicHTTPClientInvokers = { } ;
var privateMethods = { } ;
var publicWSInvokers = { } ;
var publicHTTPClientInvokers = { } ;
var IS _OAUTH _ENABLED = true ;
var TOKEN _EXPIRED = "Access token expired" ;
var TOKEN _INVALID = "Invalid input. Access token validation failed" ;
var devicemgtProps = require ( "/app/conf/reader/main.js" ) [ "conf" ] ;
var constants = require ( "/app/modules/constants.js" ) ;
var tokenUtil = require ( "/app/modules/api-wrapper-util.js" ) . apiWrapperUtil ;
var devicemgtProps = require ( '/app/conf/devicemgt-props.js' ) . config ( ) ;
var userModule = require ( "/app/modules/user.js" ) [ "userModule" ] ;
var tokenUtil = require ( "/app/modules/api-wrapper-util.js" ) [ "apiWrapperUtil" ] ;
/ * *
* This metho a d reads the token pair from the session and return the access token .
* This metho d reads the token pair from the session and return the access token .
* If the token pair s not set in the session this will send a redirect to the login page .
* /
privateMethods . getAccessToken = function ( ) {
var tokenPair = session . get ( constants .ACCESS _TOKEN _PAIR _IDENTIFIER ) ;
var tokenPair = session . get ( constants ["ACCESS_TOKEN_PAIR_IDENTIFIER" ] ) ;
if ( tokenPair ) {
return tokenPair . accessToken ;
} else {
@ -46,152 +50,119 @@ var backendServiceInvoker = function () {
} ;
/ * *
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled .
* @ param method HTTP request type .
* @ param url target url .
* @ param payload payload / data which need to be send .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
* Start of XML - HTTP - REQUEST based Interceptor implementations
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
* /
/ * *
* This method add Oauth authentication header to outgoing XML - HTTP Requests if Oauth authentication is enabled .
* @ param httpMethod HTTP request type .
* @ param requestPayload payload / data if exists which is needed to be send .
* @ param endpoint Backend REST API url .
* @ param responseCallback a function to be called with response retrieved .
* @ param count a counter which hold the number of recursive execution
* /
privateMethods . execute = function ( method , url , successCallback , errorCallback , payload , count , contentType , acceptType ) {
privateMethods . execute = function ( httpMethod, requestPayload , endpoint , responseCallback , count ) {
var xmlHttpRequest = new XMLHttpRequest ( ) ;
xmlHttpRequest . open ( method , url ) ;
if ( ! contentType ) {
contentType = constants . APPLICATION _JSON ;
}
if ( ! acceptType ) {
acceptType = constants . APPLICATION _JSON ;
}
xmlHttpRequest . setRequestHeader ( constants . CONTENT _TYPE _IDENTIFIER , contentType ) ;
xmlHttpRequest . setRequestHeader ( constants . ACCEPT _IDENTIFIER , acceptType ) ;
xmlHttpRequest . setRequestHeader ( constants . REFERER , String ( privateMethods . getClientDomain ( ) ) ) ;
if ( IS _OAUTH _ENABLED ) {
xmlHttpRequest . open ( httpMethod , endpoint ) ;
xmlHttpRequest . setRequestHeader ( constants [ "CONTENT_TYPE_IDENTIFIER" ] , constants [ "APPLICATION_JSON" ] ) ;
xmlHttpRequest . setRequestHeader ( constants [ "ACCEPT_IDENTIFIER" ] , constants [ "APPLICATION_JSON" ] ) ;
if ( devicemgtProps [ "isOAuthEnabled" ] ) {
var accessToken = privateMethods . getAccessToken ( ) ;
if ( ! accessToken ) {
response . sendRedirect ( devicemgtProps [ "httpsURL" ] + "/devicemgt/login" ) ;
userModule . logout ( function ( ) {
response . sendRedirect ( devicemgtProps [ "appContext" ] + "login" ) ;
} ) ;
} else {
xmlHttpRequest . setRequestHeader ( constants . AUTHORIZATION _HEADER , constants . BEARER _PREFIX + accessToken ) ;
xmlHttpRequest .
setRequestHeader ( constants [ "AUTHORIZATION_HEADER" ] , constants [ "BEARER_PREFIX" ] + accessToken ) ;
}
}
if ( payload ) {
xmlHttpRequest . send ( payload ) ;
if ( requestPayload ) {
xmlHttpRequest . send ( requestPayload ) ;
} else {
xmlHttpRequest . send ( ) ;
}
if ( ( xmlHttpRequest . status >= 200 && xmlHttpRequest . status < 300 ) || xmlHttpRequest . status == 302 ) {
if ( xmlHttpRequest . responseText != null ) {
return successCallback ( parse ( xmlHttpRequest . responseText ) ) ;
} else {
return successCallback ( { "status" : xmlHttpRequest . status , "messageFromServer" : "Operation Completed" } ) ;
}
} else if ( xmlHttpRequest . status == 401 && ( xmlHttpRequest . responseText == TOKEN _EXPIRED ||
log . debug ( "Service Invoker-URL: " + endpoint ) ;
log . debug ( "Service Invoker-Method: " + httpMethod ) ;
log . info ( "Request : " + httpMethod + " " + endpoint ) ;
log . info ( "Request payload if any : " + stringify ( requestPayload ) ) ;
log . info ( "Response status : " + xmlHttpRequest . status ) ;
log . info ( "Response payload if any : " + xmlHttpRequest . responseText ) ;
//log.info("Response headers : " + xmlHttpRequest.getAllResponseHeaders());
if ( xmlHttpRequest . status == 401 && ( xmlHttpRequest . responseText == TOKEN _EXPIRED ||
xmlHttpRequest . responseText == TOKEN _INVALID ) && count < 5 ) {
tokenUtil . refreshToken ( ) ;
return privateMethods . execute ( method , url , successCallback , errorCallback , payload , ( count + 1 ) ) ;
} else if ( xmlHttpRequest . status == 500 ) {
return errorCallback ( xmlHttpRequest ) ;
return privateMethods . execute ( httpMethod , requestPayload , endpoint , responseCallback , ++ count ) ;
} else {
return error Callback( xmlHttpRequest ) ;
return responseCallback ( xmlHttpRequest ) ;
}
} ;
/ * *
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled .
* @ param method HTTP request type .
* @ param url target url .
* @ param payload payload / data which need to be send .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* This method add Oauth authentication header to outgoing XML - HTTP Requests if Oauth authentication is enabled .
* @ param httpMethod HTTP request type .
* @ param requestPayload payload / data if exists which is needed to be send .
* @ param endpoint Backend REST API url .
* @ param responseCallback a function to be called with response retrieved .
* /
privateMethods . initiateXMLHTTPRequest = function ( method , url , successCallback , errorCallback , payload , contentType , acceptType ) {
if ( privateMethods . getAccessToken ( ) ) {
return privateMethods . execute ( method , url , successCallback , errorCallback , payload , 0 , contentType , acceptType ) ;
}
privateMethods . initiateXMLHTTPRequest = function ( httpMethod , requestPayload , endpoint , responseCallback ) {
return privateMethods . execute ( httpMethod , requestPayload , endpoint , responseCallback , 0 ) ;
} ;
/ * *
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled .
* @ param method HTTP request type .
* @ param url target url .
* @ param payload payload / data which need to be send .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* This method invokes return initiateXMLHttpRequest for get calls
* @ param endpoint Backend REST API url .
* @ param responseCallback a function to be called with response retrieved .
* /
privateMethods . initiateHTTPClientRequest = function ( method , url , successCallback , errorCallback , payload , contentType , acceptType ) {
var HttpClient = Packages . org . apache . commons . httpclient . HttpClient ;
var httpMethodObject ;
switch ( method ) {
case constants . HTTP _POST :
var PostMethod = Packages . org . apache . commons . httpclient . methods . PostMethod ;
httpMethodObject = new PostMethod ( url ) ;
break ;
case constants . HTTP _PUT :
var PutMethod = Packages . org . apache . commons . httpclient . methods . PutMethod ;
httpMethodObject = new PutMethod ( url ) ;
break ;
case constants . HTTP _GET :
var GetMethod = Packages . org . apache . commons . httpclient . methods . GetMethod ;
httpMethodObject = new GetMethod ( url ) ;
break ;
case constants . HTTP _DELETE :
var DeleteMethod = Packages . org . apache . commons . httpclient . methods . DeleteMethod ;
httpMethodObject = new DeleteMethod ( url ) ;
break ;
default :
throw new IllegalArgumentException ( "Invalid HTTP request type: " + method ) ;
}
var Header = Packages . org . apache . commons . httpclient . Header ;
var header = new Header ( ) ;
header . setName ( constants . CONTENT _TYPE _IDENTIFIER ) ;
header . setValue ( contentType ) ;
httpMethodObject . addRequestHeader ( header ) ;
header = new Header ( ) ;
header . setName ( constants . ACCEPT _IDENTIFIER ) ;
header . setValue ( acceptType ) ;
httpMethodObject . addRequestHeader ( header ) ;
header = new Header ( ) ;
header . setName ( constants . REFERER ) ;
header . setValue ( String ( privateMethods . getClientDomain ( ) ) ) ;
httpMethodObject . addRequestHeader ( header ) ;
if ( IS _OAUTH _ENABLED ) {
var accessToken = privateMethods . getAccessToken ( ) ;
if ( accessToken ) {
header = new Header ( ) ;
header . setName ( constants . AUTHORIZATION _HEADER ) ;
header . setValue ( constants . BEARER _PREFIX + accessToken ) ;
httpMethodObject . addRequestHeader ( header ) ;
} else {
response . sendRedirect ( devicemgtProps [ "httpsURL" ] + "/devicemgt/login" ) ;
}
publicXMLHTTPInvokers . get = function ( endpoint , responseCallback ) {
var requestPayload = null ;
return privateMethods . initiateXMLHTTPRequest ( constants [ "HTTP_GET" ] , requestPayload , endpoint , responseCallback ) ;
} ;
}
if ( payload ) {
var stringRequestEntity = new StringRequestEntity ( stringify ( payload ) ) ;
httpMethodObject . setRequestEntity ( stringRequestEntity ) ;
}
var client = new HttpClient ( ) ;
try {
client . executeMethod ( httpMethodObject ) ;
var status = httpMethodObject . getStatusCode ( ) ;
if ( status == 200 ) {
var responseContentDispositionHeader = httpMethodObject . getResponseHeader ( constants . CONTENT _DISPOSITION _IDENTIFIER ) ;
if ( responseContentDispositionHeader ) {
return successCallback ( httpMethodObject . getResponseBodyAsStream ( ) , httpMethodObject . getResponseHeaders ( ) ) ;
} else {
return successCallback ( httpMethodObject . getResponseBody ( ) ) ;
}
} else {
return errorCallback ( httpMethodObject . getResponseBody ( ) ) ;
}
} catch ( e ) {
return errorCallback ( response ) ;
} finally {
httpMethodObject . releaseConnection ( ) ;
}
/ * *
* This method invokes return initiateXMLHttpRequest for post calls
* @ param endpoint Backend REST API url .
* @ param requestPayload payload / data if exists which is needed to be send .
* @ param responseCallback a function to be called with response retrieved .
* /
publicXMLHTTPInvokers . post = function ( endpoint , requestPayload , responseCallback ) {
return privateMethods . initiateXMLHTTPRequest ( constants [ "HTTP_POST" ] , requestPayload , endpoint , responseCallback ) ;
} ;
/ * *
* This method invokes return initiateXMLHttpRequest for put calls
* @ param endpoint Backend REST API url .
* @ param requestPayload payload / data if exists which is needed to be send .
* @ param responseCallback a function to be called with response retrieved .
* /
publicXMLHTTPInvokers . put = function ( endpoint , requestPayload , responseCallback ) {
return privateMethods . initiateXMLHTTPRequest ( constants [ "HTTP_PUT" ] , requestPayload , endpoint , responseCallback ) ;
} ;
/ * *
* This method invokes return initiateXMLHttpRequest for delete calls
* @ param endpoint Backend REST API url .
* @ param responseCallback a function to be called with response retrieved .
* /
publicXMLHTTPInvokers . delete = function ( endpoint , responseCallback ) {
var requestPayload = null ;
return privateMethods . initiateXMLHTTPRequest ( constants [ "HTTP_DELETE" ] , requestPayload , endpoint , responseCallback ) ;
} ;
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
* Start of WS - REQUEST based Interceptor implementations
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
* /
/ * *
* This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled .
* @ param action
@ -202,32 +173,26 @@ var backendServiceInvoker = function () {
* @ param soapVersion soapVersion which need to used .
* /
privateMethods . initiateWSRequest = function ( action , endpoint , successCallback , errorCallback , soapVersion , payload ) {
var ws = require ( 'ws' ) ;
var ws = require ( "ws" ) ;
var wsRequest = new ws . WSRequest ( ) ;
var options = [ ] ;
if ( IS_OAUTH _ENABLED ) {
if ( devicemgtProps[ "isOAuthEnabled" ] ) {
var accessToken = privateMethods . getAccessToken ( ) ;
if ( accessToken ) {
var authenticationHeaderName = String ( constants .AUTHORIZATION _HEADER ) ;
var authenticationHeaderValue = String ( constants .BEARER _PREFIX + accessToken ) ;
var authenticationHeaderName = String ( constants ["AUTHORIZATION_HEADER" ] ) ;
var authenticationHeaderValue = String ( constants ["BEARER_PREFIX" ] + accessToken ) ;
var headers = [ ] ;
var oAuthAuthenticationData = { } ;
oAuthAuthenticationData . name = authenticationHeaderName ;
oAuthAuthenticationData . value = authenticationHeaderValue ;
headers . push ( oAuthAuthenticationData ) ;
var referrerData = { } ;
referrerData . name = constants . REFERER ;
referrerData . value = String ( privateMethods . getClientDomain ( ) ) ;
headers . push ( referrerData ) ;
options . HTTPHeaders = headers ;
} else {
response . sendRedirect ( devicemgtProps [ " httpsURL"] + "/devicemgt/ login") ;
response . sendRedirect ( devicemgtProps [ "appContext" ] + "login" ) ;
}
}
options . useSOAP = soapVersion ;
options . useWSA = constants .WEB _SERVICE _ADDRESSING _VERSION ;
options . useWSA = constants ["WEB_SERVICE_ADDRESSING_VERSION" ] ;
options . action = action ;
var wsResponse ;
try {
@ -245,68 +210,104 @@ var backendServiceInvoker = function () {
} ;
/ * *
* This method invokes return initiateXMLHttpRequest for get calls
* @ param url target url .
* This method invokes return initiateWSRequest for soap calls
* @ param action describes particular soap action .
* @ param requestPayload SOAP request payload which is needed to be send .
* @ param endpoint service end point to be triggered .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* @ param soapVersion soapVersion which need to used .
* /
public XMLHTTPInvokers. get = function ( url , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiate XMLHTTPRequest( constants . HTTP _GET , url , successCallback , errorCallback , contentType , acceptType ) ;
public WSInvokers. soapRequest = function ( action , requestPayload , endpoint , successCallback , errorCallback , soapVersion ) {
return privateMethods . initiate WSRequest( action , endpoint , successCallback , errorCallback , soapVersion , requestPayload ) ;
} ;
/ * *
* This method invokes return initiateXMLHttpRequest for post calls
* @ param url target url .
* @ param payload payload / data which need to be send .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
* Start of HTTP - CLIENT - REQUEST based Interceptor implementations
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
* /
publicXMLHTTPInvokers . post = function ( url , payload , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiateXMLHTTPRequest ( constants . HTTP _POST , url , successCallback , errorCallback , payload , contentType , acceptType ) ;
} ;
/ * *
* This method invokes return initiateXMLHttpRequest for put calls
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled .
* @ param method HTTP request type .
* @ param url target url .
* @ param payload payload / data which need to be send .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* /
publicXMLHTTPInvokers . put = function ( url , payload , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiateXMLHTTPRequest ( constants . HTTP _PUT , url , successCallback , errorCallback , payload , contentType , acceptType ) ;
} ;
/ * *
* This method invokes return initiateXMLHttpRequest for delete calls
* @ param url target url .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* /
publicXMLHTTPInvokers . delete = function ( url , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiateXMLHTTPRequest ( constants . HTTP _DELETE , url , successCallback , errorCallback , contentType , acceptType ) ;
} ;
privateMethods . initiateHTTPClientRequest = function ( method , url , successCallback , errorCallback , payload ) {
var HttpClient = Packages . org . apache . commons . httpclient . HttpClient ;
var httpMethodObject ;
switch ( method ) {
case constants [ "HTTP_GET" ] :
var GetMethod = Packages . org . apache . commons . httpclient . methods . GetMethod ;
httpMethodObject = new GetMethod ( url ) ;
break ;
case constants [ "HTTP_POST" ] :
var PostMethod = Packages . org . apache . commons . httpclient . methods . PostMethod ;
httpMethodObject = new PostMethod ( url ) ;
break ;
case constants [ "HTTP_PUT" ] :
var PutMethod = Packages . org . apache . commons . httpclient . methods . PutMethod ;
httpMethodObject = new PutMethod ( url ) ;
break ;
case constants [ "HTTP_DELETE" ] :
var DeleteMethod = Packages . org . apache . commons . httpclient . methods . DeleteMethod ;
httpMethodObject = new DeleteMethod ( url ) ;
break ;
default :
throw new IllegalArgumentException ( "Invalid HTTP request method: " + method ) ;
}
var Header = Packages . org . apache . commons . httpclient . Header ;
var header = new Header ( ) ;
header . setName ( constants [ "CONTENT_TYPE_IDENTIFIER" ] ) ;
header . setValue ( constants [ "APPLICATION_JSON" ] ) ;
httpMethodObject . addRequestHeader ( header ) ;
header = new Header ( ) ;
header . setName ( constants [ "ACCEPT_IDENTIFIER" ] ) ;
header . setValue ( constants [ "APPLICATION_JSON" ] ) ;
httpMethodObject . addRequestHeader ( header ) ;
/ * *
* This method invokes return initiateWSRequest for soap calls
* @ param endpoint service end point to be triggered .
* @ param payload soap payload which need to be send .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* @ param soapVersion soapVersion which need to used .
* /
publicWSInvokers . soapRequest = function ( action , endpoint , payload , successCallback , errorCallback , soapVersion ) {
return privateMethods . initiateWSRequest ( action , endpoint , successCallback , errorCallback , soapVersion , payload ) ;
if ( devicemgtProps [ "isOAuthEnabled" ] ) {
var accessToken = privateMethods . getAccessToken ( ) ;
if ( accessToken ) {
header = new Header ( ) ;
header . setName ( constants [ "AUTHORIZATION_HEADER" ] ) ;
header . setValue ( constants [ "BEARER_PREFIX" ] + accessToken ) ;
httpMethodObject . addRequestHeader ( header ) ;
} else {
response . sendRedirect ( devicemgtProps [ "appContext" ] + "login" ) ;
}
}
var stringRequestEntity = new StringRequestEntity ( stringify ( payload ) ) ;
httpMethodObject . setRequestEntity ( stringRequestEntity ) ;
var client = new HttpClient ( ) ;
try {
client . executeMethod ( httpMethodObject ) ;
var status = httpMethodObject . getStatusCode ( ) ;
if ( status == 200 ) {
return successCallback ( httpMethodObject . getResponseBody ( ) ) ;
} else {
return errorCallback ( httpMethodObject . getResponseBody ( ) ) ;
}
} catch ( e ) {
return errorCallback ( response ) ;
} finally {
method . releaseConnection ( ) ;
}
} ;
/ * *
* This method invokes return initiateHTTPClientRequest for get calls
* @ param url target url .
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* /
publicHTTPClientInvokers . get = function ( url , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiateHTTPClientRequest ( constants . HTTP _GET , url , successCallback , errorCallback , null , contentType , acceptType ) ;
publicHTTPClientInvokers . get = function ( url , successCallback , errorCallback ) {
var requestPayload = null ;
return privateMethods .
initiateHTTPClientRequest ( constants [ "HTTP_GET" ] , url , successCallback , errorCallback , requestPayload ) ;
} ;
/ * *
@ -316,9 +317,9 @@ var backendServiceInvoker = function () {
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* /
publicHTTPClientInvokers . post = function ( url , payload , successCallback , errorCallback , contentType , acceptType ) {
publicHTTPClientInvokers . post = function ( url , payload , successCallback , errorCallback ) {
return privateMethods .
initiateHTTPClientRequest ( constants .HTTP _POST , url , successCallback , errorCallback , payload , contentType , acceptType ) ;
initiateHTTPClientRequest ( constants ["HTTP_POST" ] , url , successCallback , errorCallback , payload ) ;
} ;
/ * *
@ -328,8 +329,9 @@ var backendServiceInvoker = function () {
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* /
publicHTTPClientInvokers . put = function ( url , payload , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiateHTTPClientRequest ( constants . HTTP _PUT , url , successCallback , errorCallback , payload , contentType , acceptType ) ;
publicHTTPClientInvokers . put = function ( url , payload , successCallback , errorCallback ) {
return privateMethods .
initiateHTTPClientRequest ( constants [ "HTTP_PUT" ] , url , successCallback , errorCallback , payload ) ;
} ;
/ * *
@ -338,23 +340,16 @@ var backendServiceInvoker = function () {
* @ param successCallback a function to be called if the respond if successful .
* @ param errorCallback a function to be called if en error is reserved .
* /
publicHTTPClientInvokers . delete = function ( url , successCallback , errorCallback , contentType , acceptType ) {
return privateMethods . initiateHTTPClientRequest ( constants . HTTP _DELETE , url , successCallback , errorCallback , contentType , acceptType ) ;
publicHTTPClientInvokers . delete = function ( url , successCallback , errorCallback ) {
var requestPayload = null ;
return privateMethods .
initiateHTTPClientRequest ( constants [ "HTTP_DELETE" ] , url , successCallback , errorCallback , requestPayload ) ;
} ;
/ * *
* This method fetch the current logged user from the session and returns
* the tenant domain name of the user
* @ returns { tenantDomain }
* /
privateMethods . getClientDomain = function ( ) {
var user = session . get ( constants . USER _SESSION _KEY ) ;
return user . domain ;
}
var publicMethods = { } ;
publicMethods . XMLHttp = publicXMLHTTPInvokers ;
publicMethods . WS = publicWSInvokers ;
publicMethods . HttpClient = publicHTTPClientInvokers ;
var publicInvokers = { } ;
publicInvokers . XMLHttp = publicXMLHTTPInvokers ;
publicInvokers . WS = publicWSInvokers ;
publicInvokers . HttpClient = publicHTTPClientInvokers ;
return publicInvokers ;
return publicMethods ;
} ( ) ;