REST/JSON in MAF by Waslley Souza

 

clip_image001REST/JSON has several advantages over SOAP/XML, so it is preferred for mobile web services. As REST/JSON is a smaller than SOAP/XML, you will be passing much less data over the network. For mobile devices, it is a very important point.

In this post we will create a CRUD of employees in Oracle MAF 2.0 using REST/JSON.
I will use this REST application (Expose ADF BC as RESTful Web Service).
Download the sample application: MAFRESTJSONApp.zip.

Initialize the REST Web Service.

Create a Mobile Application Framework Application, and name it as MAFRESTJSONApp.
In the maf-feature.xml file, create a new feature and call it as employees.
Click the Content tab, and then click green plus button near File field, to create the EmployeesTF Task Flow.

Create the REST Connection.
Go to Projects panel, right-click ViewController project and choose New > From Gallery.
In the New Gallery dialog, choose General > Connections > REST Connection.
If you click Test Connection button, you will receive an error.
It is intentional, because I want to use the same REST Connection for all operations. Read the complete article here.

WebLogic Partner Community

For regular information become a member in the WebLogic Partner Community please visit: http://www.oracle.com/partners/goto/wls-emea ( OPN account required). If you need support with your account please contact the Oracle Partner Business Center.

Blog Twitter LinkedIn Forum Wiki

2 comments

  1. lm new to MAF .l created two projects (1)RestServiceProject as back end server and another one for (2)Front End Side called MAFProject . On the remote service ie RestServiceProject , l have a Rest Service that update User detail with data obtain from Front end side .My class look like this :

    @Path(“UserCCD”)

    public class UserCCD extends OObject {

    @GET

    public javax.ws.rs.core.Response rootUriOk() {

    return javax.ws.rs.core.Response.ok().build();

    }

    @POST

    @Produces(“application/json, application/xml”)

    @Consumes(“application/json, application/xml”)

    public void CheckUser(Intec.Types.User user) {

    try {

    OUser oUser = new OUser();

    oUser.createUserUpdate(user);

    } catch (Exception ex) {

    this.CatchError(ex);

    }

    }

    in the method CheckUser(Intec.Types.User user) l want to pass the payload data in the form of JSON but the problem is that the data entered from the UI is not being passed to this method . Below is the piece of code that call rest service :

    User userInt = new User();

    userInt.setUSERID(this.userID);

    userInt.setFIRSTNAME(this.FirstName);

    userInt.setLASTNAME(this.LastName);

    RestServiceAdapter restServiceAdapter = Model.createRestServiceAdapter();

    restServiceAdapter.clearRequestProperties();

    restServiceAdapter.setConnectionName(“userTest”);

    restServiceAdapter.setRequestType(RestServiceAdapter.REQUEST_TYPE_POST);

    restServiceAdapter.setRetryLimit(0);

    restServiceAdapter.addRequestProperty(“Content-Type”, “application/json”);

    restServiceAdapter.addRequestProperty(“Accept”, “application/json; charset=UTF-8”);

    restServiceAdapter.setRequestURI(“/”);

    String postDataStr = “”;

    if (userInt != null) {

    JSONObject jsonObj = (JSONObject) JSONBeanSerializationHelper.toJSON(userInt);

    removeNullsAndTypeFromJSON(jsonObj);

    postDataStr = jsonObj.toString();

    }

    response = restServiceAdapter.send(postDataStr);

    How to receive data( data like userid , firstname , LastName) on the remote service .On the Remote Service the data is null values .

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.