Business Console 10.11 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Programming Gadgets | Invoking RESTful Services | Using CORS Support for Invoking RESTful Services
 
Using CORS Support for Invoking RESTful Services
Business Console gadget supports direct invocation of URLs to a remote server, if the remote server supports Cross-Origin Resource Sharing (CORS). To make a cross-origin request, ensure that the remote server is configured with all the CORS settings.
For example, In Integration Server, provide the following in Extended Settings to support CORS headers.
watt.server.cors.allowedOrigins=http://localhost:8585, (Please specify the URLs
from where the invocation is happening)
watt.server.cors.enabled=true
watt.server.cors.exposedHeaders=Set-Cookie,X-Frame-Options,Access-Control
-Allow-Origin
watt.server.cors.maxAge=1000000
watt.server.cors.supportedHeaders=samlassertion,accept,
withcredentials,content-type
watt.server.cors.supportedMethods=GET,POST,PUT,DELETE,OPTIONS,HEAD
watt.server.cors.supportsCredentials=true
After configuring CORS settings, you can invoke a RESTful service with cors (true) and remote (true) options.
$scope.restClient.url($scope.URLS.MY_REST_SERVICE1)
// POINT TO THE RESTful SERVICE TO INVOKE
.serverAlias("IS1")
// POINT TO THE SERVER ALIAS FROM THE GADGET CONFIGURATION
.remote(true)
// IF LOCAL OR REMOTE CALL
.cors(true)
// IF CORS SUPPORTED FOR REMOTE CALLS ONLY
.scope($scope)
.gadgetConfig(gadgetConfig)
.success(function(response,$scope){
$scope.responseData = response;
// HANDLE THE RESPONSE IN A SCOPE OBJECT
}).error(function(response,$scope,status, headers, config){
$scope.eventBus.fireEvent(NotificationConstants.ERROR,
"Unable to invoke REST ");
// HANDLE ANY ERROR IN INVOCATION
}).invoke();