I was blogging previously about Oracle Mobile Suite and REST service transformation from ADF BC SOAP service. Today I'm going to blog the next step in the same series - MAF client consuming REST service exposed from Oracle Mobile Suite ESB. I'm going to highlight improvements in debugging process for MAF, provided with the latest 2.1 release. I had couple of challenges implementing and mapping programmatic MAF client for REST service, all these were solved and I would like to share the solution with you.
Previous posts on the same topic:
- Oracle Mobile Suite Service Bus REST and ADF BC SOAP
- How To Add New Operation in Oracle Mobile Suite Service Bus REST Service
Here you can download sample application implemented for today post (contains ADF BC SOAP, Mobile Suite Service Bus and MAF client apps) - MobileServiceBusApp_v3.zip.
High level view of the implemented use case - there are three parts. Service Bus is acting as a proxy to transform ADF BC SOAP service to light REST consumed by mobile REST client (implemented in MAF):
I would not recommend to use auto generated Data Control for REST service - I didn't had positive experience using it. You should invoke REST service from Java, using MAF helper classes (read - here). There must be REST connection defined and tested, later it can be accessed and used directly from Java. REST connection endpoint must include REST service URL (in my case, it by default points to getEmployeesListAll operation):
It is enough to define REST connection, now we can start using it.
Sample application implements REST helper class. Here actual REST call is made through MAF RestServiceAdapter class - see invokeRestService method. Public method invokeFind(requestURI) is supposed to be used to initiate search request. Content type is set to be JSON. Search parameter is always passed as a part of requestURI, therefore we are passing empty post data value:
MAF application contains Java class - ServiceHelper, this class is used to implement Data Control. Each time when search parameter is set, applyFilter method is invoked and it makes REST request. Response is received and with the help of MAF utility (highlighted) is transformed from String to the array of objects:
ServiceHelper class includes a set of variables required to perform successful REST request. Data collection object - employees of type EmployeeBO[] is defined here and later exposed through Data Control:
As you can see from above example of applyFilter method - response String is transformed to the array of objects. I'm using EmployeesList class for conversion. This class contains array of objects to parse from REST response. It is very important to have exactly the same name for array variable as your REST response result set name. In my example, this name is employees:
Finally there is class to represent response object - EmployeeBO. This class is a POJO with attribute definitions:
ServiceHelper class is exposed to Data Control - defined methods will be accessible from MAF bindings layer:
This is all about REST client in MAF implementation - I would say quite straightforward, when you are on the right path.
Let's have a few words about debugger in MAF 2.1. I would say I was positively impressed with debugger improvements. There is no need to do any extra configuration steps anymore, simply right click anywhere in Java class you are currently working on and choose Debug option - Debugger will start automatically and MAF application will be loaded in iOS simulator.
It works with all defaults, you could go and double check the settings in Run/Debug section of MAF project - Mobile Run Configuration window:
Right click and choose debug, don't forget to set a breakpoint:
Type any value to search in the sample MAF application - Employees form. You should see breakpoint is activated in JDEV (as it calls applyFilter method):
Debugger displays value we are searching for:
After conversion from response String to array of objects happens, we could inspect the collection and check if conversion happened correctly:
Response from REST is successfully displayed in MAF UI:
Previous posts on the same topic:
- Oracle Mobile Suite Service Bus REST and ADF BC SOAP
- How To Add New Operation in Oracle Mobile Suite Service Bus REST Service
Here you can download sample application implemented for today post (contains ADF BC SOAP, Mobile Suite Service Bus and MAF client apps) - MobileServiceBusApp_v3.zip.
High level view of the implemented use case - there are three parts. Service Bus is acting as a proxy to transform ADF BC SOAP service to light REST consumed by mobile REST client (implemented in MAF):
I would not recommend to use auto generated Data Control for REST service - I didn't had positive experience using it. You should invoke REST service from Java, using MAF helper classes (read - here). There must be REST connection defined and tested, later it can be accessed and used directly from Java. REST connection endpoint must include REST service URL (in my case, it by default points to getEmployeesListAll operation):
It is enough to define REST connection, now we can start using it.
Sample application implements REST helper class. Here actual REST call is made through MAF RestServiceAdapter class - see invokeRestService method. Public method invokeFind(requestURI) is supposed to be used to initiate search request. Content type is set to be JSON. Search parameter is always passed as a part of requestURI, therefore we are passing empty post data value:
MAF application contains Java class - ServiceHelper, this class is used to implement Data Control. Each time when search parameter is set, applyFilter method is invoked and it makes REST request. Response is received and with the help of MAF utility (highlighted) is transformed from String to the array of objects:
ServiceHelper class includes a set of variables required to perform successful REST request. Data collection object - employees of type EmployeeBO[] is defined here and later exposed through Data Control:
As you can see from above example of applyFilter method - response String is transformed to the array of objects. I'm using EmployeesList class for conversion. This class contains array of objects to parse from REST response. It is very important to have exactly the same name for array variable as your REST response result set name. In my example, this name is employees:
Finally there is class to represent response object - EmployeeBO. This class is a POJO with attribute definitions:
ServiceHelper class is exposed to Data Control - defined methods will be accessible from MAF bindings layer:
This is all about REST client in MAF implementation - I would say quite straightforward, when you are on the right path.
Let's have a few words about debugger in MAF 2.1. I would say I was positively impressed with debugger improvements. There is no need to do any extra configuration steps anymore, simply right click anywhere in Java class you are currently working on and choose Debug option - Debugger will start automatically and MAF application will be loaded in iOS simulator.
It works with all defaults, you could go and double check the settings in Run/Debug section of MAF project - Mobile Run Configuration window:
Right click and choose debug, don't forget to set a breakpoint:
Type any value to search in the sample MAF application - Employees form. You should see breakpoint is activated in JDEV (as it calls applyFilter method):
Debugger displays value we are searching for:
After conversion from response String to array of objects happens, we could inspect the collection and check if conversion happened correctly:
Response from REST is successfully displayed in MAF UI: