TODO: Show turning off scope at bottom of lab
The purpose of the customer adapter is to call the MessageHub and DashDB adapter. This is so that if any server side changes are made they are easily changed without having to create a new service in the Ionic app. By having one point of entry, the client side of the app will not have to change if a resource changes on the backend.
- How to create a adapter that calls other adapters
To learn more please see our getting started labs here
1 - Go to where the adapter is located
cd MotoCorpService/Adapters/CustomerAdapter2 - Build the adapter
mfpdev adapter build3 - Deploy the adapter by uploading the CustomerAdapter.adapter file to the mfp console.
1 - Security
@OAuthSecurity(scope = "user-restricted")2 - Posting to MessagHub adapter Post to the url of the procedure you are calling and execute it using the AdaptersAPI
public Response newCustomer(JSONObject customer) throws IOException{
String MessageHubURL = "/MessageHubAdapter/resource/newCustomer";
HttpPost req = new HttpPost(MessageHubURL);
req.addHeader("Content-Type", "application/json");
String payload = customer.toString();
HttpEntity entity = new ByteArrayEntity(payload.getBytes("UTF-8"));
req.setEntity(entity);
HttpResponse response = adaptersAPI.executeAdapterRequest(req);
JSONObject jsonObj = adaptersAPI.getResponseAsJSON(response);
return Response.ok(jsonObj).build();
}3 - Getting from DashDB adapter Get to the url of the procedure you are calling and execute it using the AdaptersAPI
public Response customers() throws IOException{
String JavaSQLURL = "/DashDB/getAllUsers";
HttpUriRequest req = new HttpGet(JavaSQLURL);
HttpResponse response = adaptersAPI.executeAdapterRequest(req);
JSONObject jsonObj = adaptersAPI.getResponseAsJSON(response);
return Response.ok(jsonObj.get("responseText")).build();
}We will be testing the customer adapter functionality in the next lab MFP Ionic MobileApp.