JDeveloper 11.1.1.x and ADF does not provide much support for REST Services, but it does recognize JAX-RS annotations and help configure Jersey. Here are simple steps to create REST Service over ADF Business Components.

1. Create Application Structure
Create Generic Application. Delete generated Project. Add Model Project and Web Project (without Faces). Create Connection (hrdb) to HR Schema.

2. Generate Business Components and Prepare Service API
This is similar to what i did for SOAP Web Service Example.

3. Add dependency to Jersey & Jackson
Add Jersey and Jackson libraries to Web Project.
See my blog about Installing Jersey libraries for JDeveloper. Actually, i am just adding following jars to Project.
jackson-all-1.9.11.jar, asm-3.1.jar, jersey-bundle-1.17.1.jar

4. Create WebService POJO Class
Create POJO class with necessary API method(s). This example is not showing any exception handling, but you can throw Checked Exception to indicate Validation, Application or System type error situations to client.

5. Add annotations
5.1 Add @Path(“/hrservice”) annotation to HRWebService Java class. Import “javax.ws.rs.Path”, when prompted by JDeveloper.

5.2 JDeveloper will provide a hint for you to configure web.xml. You will see a Yellow icon in line gutter next to @Path. Accept the hint and JDeveloper will configure web.xml for Jersey servlet.

 

5.3 Add “com.sun.jersey.api.json.POJOMappingFeature” init param for Jersey servlet in web.xml, value of this init param should be true. This will cause Jersey to use Jackson for generating JSON response. Default implementation (JAXB) has some issues, for example, it will return Object instead of Array if only one item is being returned in List.

5.4 Add GET annotation to getCountryList() method.

6. Add weblogic-application.xml
ADF libraries are included by adding shared library in weblogic-application.xml. This is automatically done if you create Fustion application, otherwise you can add it manually.

7. Test Web Service
Right click Web Service in Application Navigator and select Run or Debug.

 

Chandresh Patel

I have been working with Java EE technologies since 2000. After implementing IBM WebSphere and custom framework solutions, my past 10 years have been focused on Oracle Fusion Middleware such as WebLogic, ADF, WebCenter and Coherence. I have been part of many automation projects in the past and have a passion for automation capabilities to help our customers deliver software faster and with higher quality. In my current role as a Principal Architect at Flexagon, I am driving the FlexDeploy product strategy and development to build DevOps/CI/CD features that help our customers.

More posts by Chandresh Patel
    

4 Comments

  • MarioK says:

    Very helpful post, thanks.
    I’ve got one question: is it possible to get a response that looks like this:
    {
    “countries” : [
    {
    “countryId” : “AR”, “countryName” : “Argentina”
    },
    {
    “countryId” : “AU”, “countryName” : “Australia”
    },

    ]
    }

  • Yes, that’s possible. You just need another POJO that includes list. For example,

    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement
    public class MyPOJO
    {
    private List mCountries = new ArrayList();

    public MyPOJO()
    {
    super();
    mCountries.add(new Country(“AR”, “Argentina”));
    mCountries.add(new Country(“AU”, “Australia”));
    }

    public void setCountries(List pCountries)
    {
    this.mCountries = pCountries;
    }

    public List getCountries()
    {
    return mCountries;
    }
    }

    This will generate json like this.

    {“countries”:[{“countryId”:”AR”,”countryName”:”Argentina”},{“countryId”:”AU”,”countryName”:”Australia”}]}

  • MarioK says:

    Do not understand how should a HRWebService.java class look like after this change? I’m just a begginer in web services, so many thanks for help.

  • HRWebService method will change to something like this. You can rename MyPOJO to be CountryListPOJO or something like that. We are just putting wrapper around the list here.

    public MyPOJO getCountryList()
    { ……

Leave a Reply

Your email address will not be published. Required fields are marked *