Sunday, August 4, 2013

Create SOAP WebServices using BC4J

ADF Application Module can be enabled as Service Interface (SDO), but i take a different approach to this as shown below.

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
2.1 Generate ADF Business Components using JDevelolper Wizard. Create Application Module later, otherwise initial wizard adds many entries to Application Module's Data Model.
2.2 Create simple POJO for Country object.


2.3 Create service method to return all Country objects. Expose it to Client Interface.


Using Application module XML Editor, add this service method to Client Interface (Java tab).


3. Create Web Service 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.

Alternatively, you can also start by creating WSDL file to represent your Web Service.


4. Generate SOAP Web Service from POJO
Generate Web Service using JDeveloper wizard. This generates SOAP Web Service only with JDeveloper 11.1.1.x, hopefully future versions of JDeveloper will allow generation of REST Services.






Note annotations added by Wizard.


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


Why this approach?
1. This approach allows for flexibility in exception handling, as you can control types of exception thrown to client. Service Generation approach from Application Module throws Runtime Exceptions which is seen as SOAP Fault by client and it does not have any useful information.
2. You may want to control WSDL and / or Schema to confirm to your Enterprise Standards, which is possible only when using this approach.
3. This approach is little bit clean, as Web Service and BC4J code is organized in separate projects.

And, It is not at all difficult to generate Web Service from POJO with available Wizards.