Since my first steps with an early beta version of the Oracle SOA Suite 11g I was missing this simplicity to just implement a Java POJO service on the SCA Container from Oracle. Since Oracle SOA Suite 11g Patch Set 2 it is possible to have Spring Beans as part of the Spring Framework on the Oracle SCA Container as first-class citizen. Therefore Oracle adds the possibility to have Java POJO services in terms of Spring Beans.
Let’s follow the simple Calculator example from the Apache Tuscany “Getting Started” web page and see how to implement the Calculator application on the Oracle SCA Container. I have chosen this Calculator example because it’s separated on smaller function blocks (SCA Components) demonstrating the flexibility and modularization of SCA Services. Smaller components can be easily wired to more complex components.
In case of the Calculator example, the application can be divided into five functional blocks: Add Service Component, Subtract Service Component, Multiply Service Component, Divide Service Component and a main block that takes a request and routes it to the right operation. This main block is called the Calculator Service Component.
The Calculator application is implemented with SCA Components which are placed on a SCA Composite. All the Components are implemented with Spring Beans connected (“wired”) with other Spring Beans.
The following describes the Spring Bean creation in a step-by-step approach. I assume that you have installed the “Oracle SOA Composite Editor” and “Spring & Oracle WebLogic SCA” extension on Oracle JDeveloper.
1. Create a JDeveloper Application with a meaningful name (e.g. OracleSCASamples)
2. Name the project “Calculator” and add SOA as project technology
3. Take the “Empty Composite” as project template
Afterwards you have an JDeveloper SOA project with an empty SCA Composite. On JDeveloper we have a one to one relationship between projects and composites.
Each Calculator operation on the Tuscany example is implemented as own SCA Component. So let’s create SCA Components for the AddService, SubtractService, MultiplyService and DivideService. The next steps are showing the creation of the AddService. The AddService Component will provide a service that adds two numbers together. The CalculatorService Component uses the AddService Component whenever it is asked to perform additions.
Later we do the same implementation steps for the other needed Calculator services.
4. Create a Java Class starting from the JDeveloper Technology Gallery
5. Name the class “AddServiceImpl” on the “calculator” package
6. Choose the “Calculator\src” folder as destination
7. Develop the “add” operation of the AddServiceImpl class. As you see, we just implement the AddService as Plain Old Java Object (POJO).
8. “Refactor” the Add Service Interface
9. Name the interface “IAddService” on the “calculator” package
Result: IAddService interface
Note: We also could first implement the interface and afterwards the implementation of this interface, but this way is a shortcut on this example.
10. Create a Spring Bean Configuration starting from the JDeveloper Technology Gallery
11. Name the Spring Bean Definition file “AddServiceBeanDef.xml”
12. Add a “bean” element by selecting “bean (Spring 2.5 Core)” from the Component Palette (place the cursor behind the comment)
13. Add the name attribute “AddServiceBean” and class attribute “calculator.AddServiceImpl” on the bean element
14. Add a “Service” element by selecting “Service (WebLogic SCA)” from the Component Palette. On the upcoming pop-up window add “AddService” as name, “AddServiceBean” as target and “calculator.IAddService” as type. The target name has to match the bean name.
Note: You may have to compile the Java classes. Take care that the SCA Service target attribute is matching the Bean name attribute.
15. Drag and Drop the “Spring Context” from the Component Palette on the Composite Component section
16. Name the Component “AddServiceComponent” and select the “Use Existing Context” option and start the SOA Resource Brower with the magnifying glass icon
17. Select “AddServiceBeanDef.xml” on the SOA Resource Browser (starts with the magnifying glass icon on step 16)
18. Accept the “src/META-INF/AddServiceBeanDef.xml” Spring Bean Context path on the “Use Existing Context” field
Afterwards the AddServiceComponent is placed on the SCA Composite
Additionally a <Spring Bean Component Name>.componentType file is created automatically on the SOA Content folder. This file keeps the exposed interface information (and the references on other services when the component is wired to other SCA Components).
19. Repeat step 4 to 19 for the SubtractService, MultiplyService and DivideService!
20. Let’s take a look at the Calculator Service Component. This component will call the other arithmetic Service Components. Create a Java class “CalculatorServiceImpl” on the “calculator” Package
21. Add private service variables (use the interface classes for the declaration), create the setter methods and create service methods for the basic arithmetic operations by using the existing arithmetic services.
Note: Like the shown add method you have to implement the subtract, multify and divide methods by using the right service.
22. “Refactor” the Calculator Service Interface and name the interface “ICalculatorService”. Select the basic arithmetic operations as class members to extract.
23. Create a Spring Bean Definition “CalculatorServiceBeanDef”
24. Set the bean name “CalculatorServiceBean” attribute and class “calculator.CalculatorServiceImpl” attribute
25. Add the Calculator Spring Context on the Composite Component section
26. Next step is to “wire” the existing Spring Bean Components. Drag and Drop a wire from the CalculatorServiceComponent to the other Spring Bean Components.
Afterwards all the arithmetic SCA Components are wired to the CalculatorServiceComponent. This graphical wiring will add appropriate <sca:reference> elements on the Calculator Bean context definition file.
The new services references have to be injected on the Calculator Bean (“setter DI”). Therefore you have to add standard Spring property elements on the bean declaration within the Spring Bean context definition. These property elements causing a call on the setter operations on the CalculatorServiceImpl class. The bean property ref names have to match the right reference name.
Note: When you missed the <sca:service> tags before you create the Spring Bean Components and you try to wire the beans you will see this error …
This error occurs because the automatic created <Spring Bean Component Name>.componentType files are missing the interface service information. So you have to add the missing service elements manually or you have to delete and re-create the SCA Components (don’t delete the Bean Definition File, the wizard is asking for it!).
Another common error is the missing property declaration on the bean which should use other services (“missing setter DI”). This result in a nice NullPointerException during the first test (java.lang.Exception: oracle.sysman.emSDK.webservices.wsdlapi.SoapTestException: oracle.fabric.common.FabricException: Invocation failed: java.lang.NullPointerException).
27. Next step is to give the Calculator Service Component an exposed service interface. Therefore you have to give the Calculator service a callable interface declaration. You only have to declare an SCA service interface on the Calculator Service Bean definition.
Afterwards you have to add the new service interface also on the CalculatorServiceComponent.componentType file. This declaration makes the Calculator Service Component connectable as public (callable from the SCA outside world) or private (callable from other SCA Components) service.
Note: The service interface configuration gives the components the “green handle”. Only with this handle you are able to connect this component.
28. Now the Calculator service can be exposed as public service. Drag and Drop a wire from the Calculator Service Component to the Exposed Service section.
A pop-up window is asking you what kind of interface you want to create for the service. Because we want to create a Web Service interface and not an EJB interface we press the Web Service button. Btw. you could also have both interface in parallel – Web Service and EJB.
The wizard is creating the necessary mapping between the Java classes and the XML representations. An ICalculatorService.wsdl file is created which offers the basic arithmetic operations of the Calculator Service Component.
The Calculator Service is ready for deployment. Each component has a well-defined interface, using Java interfaces in the case of the calculator example. Notice that these are just plain Java services configured as Spring Beans with business logic and nothing else inside the Java classes (no extend on pre-specified classes, no implement on pre-specified interfaces, no pre-specified annotations, etc.).
This screenshot looks very similar to the diagram on the Tuscany guidelines.
29. A quick test could happen with the Test Web Service Client of the Oracle Enterprise Manager. But first you have to create the deployment unit (one JAR file) and deploy the SCA Composite on the SOA Server. My personal favorite Web Service Test Client is the Open Source soapUI tool. Therefore you have to copy the WSDL URL from the Test Web Service client.
Start soapUI and create a new soapUI project. Paste the WSDL on the new project.
Start your tests …
That's it.