Creating custom web services from application module
April 29, 2014
We already discussed how easy it is to expose Business Components CRUD operations. This part is focused on showing how to implement a custom method as web service exposed from the application module of your ADF application.
Supported data types
Before creating the method, let’s see what are the supported data types.The service interface, in contrast to the client interface, supports a more narrow set of data types for custom method parameters and return values and is limited to:
<em>Java primitive types and their object wrapper types (for example int, Integer); java.lang.String;java.math.BigDecimal; java.math.BigInteger; java.sql.Date; java.sql.Time; java.sql.Timestamp; java.util.Date; oracle.jbo.AttributeList; oracle.jbo.domain.BlobDomain; oracle.jbo.domain.Char; oracle.jbo.domain.ClobDomain; oracle.jbo.domain.DBSequence; oracle.jbo.domain.Date; oracle.jbo.domain.NClobDomain; oracle.jbo.domain.Number; oracle.jbo.domain.Timestamp; oracle.jbo.domain.TimestampLTZ; oracle.jbo.domain.TimestampTZ; oracle.jbo.server.ViewRowImpl or any subtype; java.util.List<aType>, where aType is any of the service-interface supported data types, including Java primitive type.</em>
Note: The service interface specifically does not support Java Map collection. This means it is not possible to return a collection of objects that are of different types.
The difference between oracle.jbo.AttributeList and oracle.jbo.server.ViewRowImpl is as follows.
You can define a custom method that returns a type of AttributeList when you want to allow the client developer to work with the list of attributes and perform custom operations without the need to involve framework behavior before the custom method executes. As an alternative, when the client developer wants the framework to manage rows (create, find, and populate), define custom methods that return ViewRowImpl or List<ViewRowImpl> instead. In summary, if your method signature defines ViewRowImpl or List<ViewRowImpl> as the data type, then the application automatically:
Looks up the row in the corresponding view object instance by primary key and/or alternate key
If the row is not found, then creates a new row
Applies the attribute changes in the found or new row
Whereas, if your method signature defines the AttributeList data type, then no automatic behavior is provided, and the actions performed and data modified by the custom method will be limited to your custom method’s code.
Since the service interface does not support custom classes as parameters or return types, one way of passing or returning more complex types is to create a View Object with transient fields, which will store the data you want. Later that View Object can be used in our custom web service method.
Let’s see step by step how this is done. In this example, we have updatable view object called FlightBriefing it contains information about airplane flight such as the crew, passengers, departure date, arrival date, departure airport and arrival airport. We want to offer a web service method which will generate these briefings for many flights in the database based on a custom input, which provides all the needed information.
We create programmatic view object TicketWSInputVO with transient fields for passenger name, departure date, arrival date, departure airport and arrival airport. This is our custom input for web service. We will a java.util.List of this VO as input to our web method.
After the View Object is created add it to the Application Module.
Create the web service method in the ApplicationModuleImpl class.
Add the newly created method to the service interface -> custom methods in the application module. Select the correct view object class and type for the input parameter.
After this is done you can see the method in the WSDL for the application module services. Deploy and use the method.
If you have any questions or recommendations about the web services don’t hesitate to ask/recommend in the comment section bellow!