(For more resources on BPEL, SOA and Oracle see here.)
To log into Oracle Service Bus Console, we have to open a web browser and access the following URL: http://host_name:port/sbconsole, where host_name is the name of the host on which OSB is installed and port is a number that is set during the installation process. We log in as user weblogic. The Oracle Service Bus Console opens, as shown in the following screenshot:
The Dashboard page is opened by default, displaying information about alerts. We will show how to defne and monitor alerts later in this article. In the upper-left corner, we can see the Change Center.
Change Center is key to making confguration changes in OSB. Before making any changes, we have to create a new session by clicking the Create button. Then, we are able to make different changes without disrupting existing services. When fnished, we activate all changes by clicking Activate. If we want to roll back the changes, we can click the Discard button. We can also view all changes before activating them and write a comment.
Creating a project and importing resources from OSR
First, we have to create a new session, by clicking the Create button in the Change Center. Next, we will create a new project. OSB uses projects to allow logical grouping of resources and to better organize related parts of large development projects. We click on the Project Explorer link in the main menu. In the Projects page, we enter the name of the project (TravelApproval) and click Add Project. The new project is now shown in the projects list on the left side in the Project Explorer. We click on the project.
Next, we add folders to the project, as we want to group resources by type. To create a folder, we enter the folder name in the Enter New Folder Name field and click Add folder. We add six folders: BusinessServices, ProxyServices, WSDL, XSD, XSLT, and AlertDestinations.
Next, we have to create resources. We will show how to import service and all related resources from the UDDI registry. Before creating a connection to the UDDI registry, we will activate the current session. First, we review all changes. We click the View Changes link in the Change Center. We can see the list of all changes in the current session. We can also undo changes by clicking the undo link in the last column.
Now, we activate the session by clicking on the Activate button. The Activate Session page opens. We can add a description to the session and click Submit.
Now, all changes made are activated.
Creating connection to Oracle Service Registry
First, we start a new session in the Change Center. Then we click on the System Administration link in the main menu. We click on the UDDI Registries and then Add registry on the right side of the page. We enter connection parameters and click Save.
Now, the registry is listed in the UDDI Registries list, as shown next:
We can optionally activate a current session. In that case, we have to create a new session before importing resources from UDDI.
Importing resources from Oracle Service Registry
We click on the Import from UDDI link on the left-hand side. As there is only one connection to the registry, this connection is selected by default. First, we have to select the Business Entity. We select Packt Publishing. Then we click on the Search button to display all services of the selected business entity. In the next screenshot, we can see that currently there is only one service published. We select the service and click Next.
In the second step, we select the project and folder, where we want to save the resources. We select the TravelApproval project and the folder BusinessServices and click Next.
On the fnal screen, we just click the Import button. Now we can see that a business service, a WSDL, and three XSD resources have been created.
All resources have been created automatically, as we imported a service from the UDDI registry. If we create resources by hand, we frst have to create an XML Schema in WSDL resources, and then the Business service.
As all resources have been saved to the BusinessServices folder, we have to move them to appropriate folders based on their type. We go back to the Project Explorer and click on the BusinessServices folder in the TravelApproval project. We can see all imported resources in the Resources list at the bottom of the page.
We can move resources by clicking on the Move Resource icon and then selecting the target folder. We move the WSDL resource to the WSDL folder and the XML Schemas to the XSD folder.
Configuring a business service
If we want to monitor service metrics, such as average response time, number of messages, and number of errors, we have to enable monitoring of the business service. We will also show how to improve performances by enabling service result caching, which is a new feature in OSB 11g PS2.
Enabling service result caching
OSB supports service result caching through the use of Oracle Coherence, which is an in-memory data grid solution. In this way, we can dramatically improve performances if the response of the business service is relatively static. To enable the use of service result caching globally, we have to open the Operations | Global Settings and set Enable Result Caching to true..
In the Project Explorer, we click on our Business service. On the Confguration Details tab, we will enable service result caching. We scroll-down and edit the Message Handling Confguration. Then we expand the Advanced Settings. We select the Result Caching checkbox. Next, we have to specify the cache token, which uniquely identifes a single cache result. This is usually an ID field. In our simplifed example, we do not have an ID field; therefore, we will use the employee last name for testing purposes. We enter the following cache token expression: $body/emp:employee/LastName. Then we set the expiration time to 20 minutes.
Then, we click Next and Save.
Now, if the business service locates cached results through a cache key, it returns those cached results to the client instead of invoking the external service. If the result is not cached, the business service invokes the external service, returns the result to the client, and stores the result in cache.
Service result caching works only when the business service is invoked from a proxy service.
Enabling service monitoring
Again, we click on our Business service and then click on the Operational Settings tab. We select the Enabled checkbox next to the Monitoring and set the Aggregation Interval to 20 minutes. The aggregation interval is the sliding window of time over which metrics are computed. We can also defne SLA alerts which are based on these metrics.
We click Update to save the changes. Then, we activate the changes by clicking on the Activate button in the Change Center.
Testing a business service
After activating the changes, we can test the business service using the Test Console. To open the console, we select the BusinessServices folder and then click on the bug icon next to the Business service.
The Test Console opens. We set the XML payload and click the Execute button.
After executing the Business service, we can see the response message as shown in the next screenshot:
Creating an Alert destination
Before creating a proxy service, we will create an Alert Destination resource, which will be later used for sending e-mail alerts to the administrator. Remember, that we have already created the AlertDestinations folder.
To be able to send e-mail alerts, we have to frst confgure the SMTP server on the System Administration page.
To create an Alert destination, we navigate to the AlertDestinations folder and then select the Alert Destination from the Create Resource drop-down. We set the name to Administrator and add an e-mail recipient by clicking the Add button. We enter the recipient e-mail address (we can add more recipients) and select the SMTP server.
Then we click Save twice.
Creating a proxy service
Although at the frst sight it might seem redundant, using a proxy service instead of calling the original business service directly has several advantages. If we add a proxy service between the service consumer and the original service, we gain transparency. Through OSB, we can monitor and supervise the service and control the inbound and outbound messages. This becomes important when changes happen. For example, when a service interface or the payload changes, the proxy service can mask the changes to all service consumers that have not yet been upgraded to use the new version. This is, however, not the only beneft. A proxy service can enable authentication and authorization when accessing a service. It can provide a means to monitor service SLAs, and much more. Therefore, it often makes sense to consider using proxy services.
We will show an example to demonstrate the capabilities of proxy services. We will create a proxy service, which will contain the message processing logic and will be used to decouple service clients from the service provider. Our proxy service will validate the request against the corresponding XML schema. It will also perform error handling and alert the service administrator of any problems with the service execution.
First, we start a new session (if there is no active session) by clicking the Create button in the Change Center. Then we navigate to the ProxyServices folder in the Project Explorer. We click on the Create Resources drop-down and select Proxy Service.
The General Confguration page opens. We set the name of the proxy service to EmployeeTravelStatusServiceProxy. We also have to defne the interface of the service. We select the Business service, as we want the proxy service to use the same interface as the business service. We click the Browse button and select the EmployeeTravelStatusService business service.
Then we click Next. On the Transport Configuration screen, we can change the transport Protocol and Endpoint URI.
We use the defaults values and click Next. The HTTP Transport Confguration screen opens. We click Next on the remaining confguration screens. On the Summary page, we click the Save button at the bottom of the page.
(For more resources on BPEL, SOA and Oracle see here.)
Configuring Message Flow
We select the new proxy service. We then click on the Edit Message Flow icon in the Resources list to open the Message Flow editor.
In the Message Flow editor, we can see that a route node for the EmployeeTravelStatusService business service already exists.
Now, we will modify the message fow by adding a pipeline pair. Then, we will edit the request pipeline and add a stage for validating the request against an XML Schema. Finally, we will add an error handler to the message fow and defne a stage for sending an e-mail alert to an administrator every time the error occurs. We click on the EmployeeTravelStatusServiceProxy envelope and select Add Pipeline Pair. A pipeline pair node is added to the message flow.
Now, we will edit the request pipeline. Remember that a pipeline contains a sequence of stages. We click on the Request Pipeline node and select Add Stage.
We click on the new stage and select Edit Name and Comments. We rename the stage to Validate. Next, we click on the stage and select Edit Stage. The Edit Stage Configuration screen appears. We click on Add an Action and select Message Processing | Validate.
We specify that we want to validate ./emp:employee in the variable body against the EmployeeType defned in the XMLSchema_1488776269 XML Schema, as shown in the following screenshot:
Then we click Save to save the changes and return to the Message Flow editor.Now, we click on the envelope and select Add Service Error Handler. Then, we click on the Error Handler node and select Add Stage.
We rename the new stage to Send Alert. Next, we click on the stage and select Edit Stage. We add an Alert action as shown in the following screenshot:
We confgure the alert as shown in the following screenshot and click Save All.
Then we activate the current session in Change Center.
Testing a proxy service
After activating the session, we can test the proxy service by selecting it and clicking on the bug icon in the Resources list. The Test Console window opens. We enter the XML payload and click Execute. We can see the service response and the invocation trace.
Now, we shut down the EmployeeTravelStatus service using the Oracle Enterprise Manager Console to test the service result caching and the error hander. Then, we initiate the proxy service using the same input payload as before. We can see that the proxy service returns the same response although the EmployeeTravelStatus service is not running. This means that the service result caching works. Next, we initiate the proxy service using a different input payload. This time the invocation fails, as the response for this input is not cached.
If we click on the Operations link on the left-hand side and then select the Pipeline Alerts tab, we can see the pipeline alerts history and the details of alerts. As the proxy service execution failed, the error handler triggered an alert, as can be seen in the following screenshot:
If we click on the Service Health tab, we can monitor metrics, such as average response time, number of messages, and number of errors for the current aggregation interval.
If we check an e-mail specifed when confguring the Alert destination, we can make sure that an e-mail with the alert has been automatically sent. As we can see in the next screenshot, the alert contains data about the service, error severity, alert timestamp, and so on.
Now we can start up the EmployeeTravelStatus service again.
Publishing a proxy service to the Oracle Service Registry
In a similar way as we imported the EmployeeTravelStatus service from the Oracle Service Registry, we can also publish our EmployeeTravelStatusServiceProxy proxy service in the opposite direction. This service will then be used from service consumers.
We click on the System Administration link in the main menu and then select Publish to UDDI. The Publish to UDDI screen appears, where we select the service we want to publish (EmployeeTravelStatusServiceProxy) and the Business entity (Packt Publishing).
We publish the service by clicking on the Publish button.
Re-wiring an SOA composite application
Now we will re-wire the TravelApproval composite application to remove the direct connection to the service and replace it with the connection to the proxy service. We open our TravelApproval SOA composite application in JDeveloper again, and double-click the composite.xml to open the SOA Composite Editor. We will modify the EmployeeTravelStatus reference binding component, as we want to remove the direct connection to the service. Instead, we will use the proxy service we just created. We will fnd the Proxy service by browsing the Oracle Service Registry, therefore, we have to create a connection to the OSR on the Resource Palette frst. To ensure even greater fexibility, we will enable dynamic endpoint lookup, so that the actual address of the proxy service will be retrieved from the OSR at runtime.
We double-click the EmployeeTravelStatus reference binding component. Then we click on the Find existing WSDLs icon next to the WSDL URL input field. The SOA Resource Browser dialog opens. We select Resource Palette as a source. Then we expand our UDDI connection and navigate to the EmployeeTravelStatusServiceProxy service, as shown in the following screenshot:
We click OK. The UDDI Deployment Options dialog opens.
We select both checkboxes and click OK. Then we click OK again to close the Update Reference dialog and return to the SOA composite editor. We save the project by clicking Save All.
Notice that we were able to simply replace the EmployeeTravelStatus service with the proxy service, as the proxy service uses the same interface. If that was not the case, we would have to modify our TravelApproval BPEL process..
Now, we can re-deploy and test our composite application.
(For more resources on BPEL, SOA and Oracle see here.)
Oracle Service Bus use case
By decoupling the service provider from service consumers, we have achieved high fexibility. Now, let's have a look at what happens if we deploy a new version of EmployeeTravelStatus service which has a slightly different interface and different endpoint address. If we did not use mediation, we would have to modify and re-deploy all service consumers. In our case, there is no need to do that. Instead, we can simply modify the Proxy message fow and service consumers do not need to be aware of the change.
Now, we will demonstrate this scenario. Let's say that the new version of service uses the same namespace, but different input. The old version of service accepts the employee of the following type:
<xsd:element name="FirstName" type="xsd:string" minOccurs="0"/>
<xsd:element name="LastName" type="xsd:string" minOccurs="0"/>
<xsd:element name="Department" type="xsd:string" minOccurs="0"/>
The new service version uses an extended version of the EmployeeType complex type.
<xsd:element name="Name" type="xsd:string" minOccurs="0"/>
<xsd:element name="Surname" type="xsd:string" minOccurs="0"/>
<xsd:element name="Department" type="xsd:string"minOccurs="0"/>
<xsd:element name="Position" type="xsd:string" minOccurs="0"/>
<xsd:element name="Age" type="xsd:int" minOccurs="0"/>
The output of the service remains the same. After deploying the new version, we publish it to the Oracle Service Registry. We also have to create an XSLT transformation, which will be used to transform the request message to the new type.
Modifying the Proxy message fow
We log into the Oracle Service Bus Console again and start a new session. Then we import the new version of the EmployeeTravelStatus service (EmployeeTravelStatus-v2) from the Oracle Service Registry, as we did before. We also have to import the XSLT transformation and save it to the XSLT folder. Next, we have to edit the proxy service message fow. First, we will modify the route node, so that it will use the new version of the service. We click on the route node and select Edit Route. Then we click on the EmployeeTravelStatusService link. We select the new version of the service.
We click Submit and then Save. Then we click on the Request Pipeline and select Add Stage. We rename the stage to TransformEmployee. Then we edit the stage. We add a replace action.
We specify that we want to replace ./emp:employee in the variable body.
Now we have to select the XSLT transformation. We click on the Expression link. Then we click on XSLT Resources and select the XSLT transformation we want to use. In the Input document field we enter $body/emp:employee.
We click Save. The Edit Stage Configuration page now looks like this:
We click Save. Finally, we modify the Validate stage and specify that the input has to be validated against the new version of the XML Schema. We click Save to return to the message fow editor.
The following screenshot shows the modifed Proxy message fow:
Testing an SOA composite application
We open the Oracle Enterprise Manager Console. First, we shut down the old version of the EmployeeTravelStatus service. Then, we initiate a new instance of the TravelApproval composite application to test if the deployed composite application still works and uses the new version of the service. If we open the instance fow trace, we can make sure that the new version of the EmployeeTravelStatus service has been successfully invoked.
As we can see, when using Oracle Service Bus as an intermediate layer between service providers and consumers, there is no need to modify and redeploy our existing applications when changes occur. This gives us the much-needed fexibility, so that we are able to quickly adopt to business changes.
In the above article we have covered:
- Creating a project and importing resources from OSR
- Configuring a business service
- Testing a business service
- Creating an Alert destination
- Creating a proxy service
- Testing a proxy service
- Publishing a proxy service to the Oracle Service Registry
- Re-wiring an SOA composite application
- Oracle Service Bus use case
- Introduction to Oracle Service Bus & Oracle Service Registry [Article]
- BPEL4People [Article]
- Bussiness Processes in BPEL [Article]
- Human Interactions in BPEL [Article]
- Web Services, SOA, and WS-BPEL Technologies [Article]
- SOA—Service Oriented Architecture [Article]
- Oracle Web Services Manager: Authentication and Authorization [Article]