Wednesday, August 10, 2016

Calling Mobile Cloud REST Service from Oracle JET

Let's take a look how we can consume REST service exposed from Mobile Cloud Service (MCS). I will show how you could display data coming from MCS endpoint in Oracle JET. I will be using simple scenario in this post, based on HTTP Basic authentication method offered by MCS. In my next post I plan to review more advanced authentication described in this article - Hybrid Mobile Apps: Using the Mobile Cloud Service JavaScript SDK with Oracle JET.

JET application (download release package with sample code - release_jet_mcs_v1.zip) renders bar chart with data retrieved from MCS endpoint returning information about employees:


Once data is retrieved, I can see invocation statistics logged and reported in MCS dashboard. Calls are executed successfully:


To call MCS service from Oracle JET, we need to pass to extra headers - Authorization and Oracle-Mobile-Backend-ID. Values for both headers can be obtained from MCS dashboard. Go to Mobile Backend and navigate to Settings section. You will find required info under HTTP Basic section:


To bypass CORS issue, you can specify Security_AllowOrigin property in MCS (you need to be admin for this). Read more about it in MCS Developer Guide - Environment Policies and Their Values.  Download property file to your local environment, change it and upload back:


For test purposes, I have specified Security_AllowOrigin=allow:


Oracle JET application JS module is pointing to REST URL handled by MCS:


Fetch operation is configured to pass two headers specific to MCS - this will allow to complete REST request and get response:


NetBeans tool Network Monitor displays request headers (both MCS headers are included):


If request is successful, you should see data returned in the response:


1 comment:

Anonymous said...

Have you tried calling document cloud from a Jet app? I can't get past the CORS issue. Even trying hide it behind a custom MCS api with Security_AllowOrigin setting does not work.