Create REST WebServices using BC4J

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 “”, 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.


4 thoughts on “Create REST WebServices using BC4J”

  1. 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”


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

    import javax.xml.bind.annotation.XmlRootElement;

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

    public MyPOJO()
    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.


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

  4. 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 Comment

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

Scroll to Top