35 Initiate a SOA Composite from a PL/SQL Stored Procedure

This chapter describes what a PL/SQL stored procedure needs to do to initiate a SOA composite application.

When to implement: When a PL/SQL stored procedure needs to initiate a SOA composite application.

Design Pattern Summary: A PL/SQL stored procedure raises an event through the Event Delivery Network within the database. A mediator in the SOA composite application subscribes to the event and routes it as appropriate.

Involved components:

  • PL/SQL stored procedures

  • Event Delivery Network database

  • SOA composite application that includes Oracle Mediator and other components as needed.

35.1 Introduction to the Recommended Design Pattern

Oracle Fusion applications may contain stored procedures that need to invoke a component within a SOA composite application, such as a BPEL process service component. A stored procedure can use the Event Delivery Network database API to publish an event whose payload is xmltype. An Oracle Mediator service component subscribes to the event by event name or by using a XPath expression on the event payload. The.edl file (event definition file) for the event can be supplied in the composite or deployed separately in a MAR (metadata archive). When the stored procedure publishes the event, the subscribed Oracle Mediator service component forwards the payload to the BPEL process service component.

This chapter explains how to implement the recommended approach.

35.2 Example

The sample code for this use case can be downloaded from Oracle SOA Suite samples.

35.3 How to Invoke a SOA Composite Application Component Using PL/SQL

To invoke a SOA composite application component from a stored procedure, you must first create the event within the SOA composite application. The stored procedure must then raise the event and pass any required data via the EDN database API.

To invoke a SOA composite application component using PL/SQL:

  1. Create a SOA composite application with an Oracle Mediator component.
  2. Configure Oracle Mediator to subscribe to a new event (with a name of your choosing).

    The event filter can be by event name or using an XPath expression on the event payload and the EDL for the event can either be supplied in the composite.xml or deployed separately in a MAR.

  3. Create the SOA composite application component that will be invoked (for example, a BPEL process service component), and create a wire between the Oracle Mediator component reference and the component service.
  4. From a PL/SQL stored procedure, call the EDN-DB API method publish_event with the event namespace and the event payload as a CLOB type. An example is shown in Example 35-1.

Example 35-1 Calling the publish_event Method

DECLARE
  NAMESPACE VARCHAR2(200);
  LOCAL_NAME VARCHAR2(200);
  PAYLOAD CLOB;
BEGIN
  NAMESPACE := 'http://xmlns.oracle.com/SubEventMediator/EventDefinition1';
  LOCAL_NAME := 'CustomerEvent';
  PAYLOAD := to_clob('<eb:business-event xmlns:eb=
   "http://oracle.com/fabric/businessEvent"
   xmlns:ob="http://xmlns.oracle.com/SubEventMediator/EventDefinition1">
   <eb:name>ob:CustomerEvent</eb:name><eb:content><CU:CustomerData
   xmlns:CU="http://xmlns.oracle.com/Esb/CustomerData"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <CustomerId>A22-9AXC2</CustomerId><CustomerName>
   Deserae International</CustomerName><Type>Gold</Type><Description>Accounting
   Outsourcing Partner</Description><Address>3228 Massilon Blvd</Address>
   <City>Juniper</City><State>Massachusetts</State><Zip>01854</Zip><Country>US
   </Country><Phone>877-555-9876</Phone><Status>Active</Status>
   <CreditRating>5</CreditRating><Discount>0</Discount><Terms>30n4</Terms>
   <EnrollDate>01/1/01</EnrollDate><LastOrderDate>05/05/05/</LastOrderDate>
   <Currency>USD</Currency><ContactName>Jan Forester</ContactName><ContactTitle>VP
   Finance</ContactTitle><ContactPhone>877-555-9000</ContactPhone><AccountRep>
   Geoff Seattle</AccountRep><CampaignRating>2</CampaignRating>
   <ReferedBy>Houston America Taxco</ReferedBy>
   </CU:CustomerData></eb:content></eb:business-event>');
 
  EDN_PUBLISH_EVENT( NAMESPACE => NAMESPACE, LOCAL_NAME => LOCAL_NAME, PAYLOAD => PAYLOAD);
END;

35.4 Securing the Design Pattern

Secure Oracle Mediator by configuring the property runAsRoles=$publisher.

When the database connection is established from the middle tier so as to invoke the PL/SQL stored procedure, a session is established with the appropriate identity. This identity is propagated through EDN back to the middle tier for the subscription. The subscription runs as the identity of the publisher.

Related Links

The following documents provide additional information related to subjects discussed in this section:

35.5 Verify the Deployment

Verifying the deployment involves the following:

35.5.1 Test and Deploy the Use Case

Testing and deploying the use case involves the following main steps:

  1. Test your Oracle ADF application.
  2. Deploy the SOA composite application to the standalone WLS where the SOA infrastructure has been installed. Because you created a published event from the SOA composite application to the ADF Business Components service, the ADF Business Components service need not to also be deployed to the SOA infrastructure.
  3. Test the deployed SOA composite service using Oracle Enterprise Manager Fusion Middleware Control Console. Every deployed service has its own test page, so you can quickly test that the service functions as you expect.

35.5.2 Verifying the SOA Composite Deployment Using Oracle Enterprise Manager Fusion Middleware Control Console

You can use Oracle Enterprise Manager Fusion Middleware Control Console to verify that the SOA composite was successfully deployed. In Oracle Enterprise Manager Fusion Middleware Control Console, you can select the SOA composite instance and display the result of the event.

Using Oracle Enterprise Manager Fusion Middleware Control Console, you can:

  • Verify the deployment of the SOA composite.

  • Test the SOA composite.

  • Verify the SOA composite test results.

To verify that the SOA composite was successfully deployed and the event was received:

  1. Using a web browser, access the Oracle Enterprise Manager Fusion Middleware Control Console using a URL such as the following:
    http://<host name>:<port number>/em
    
  2. From the list of applications, expand the PLSQLEvent composite.
  3. In the Last 5 Instances pane, click the most recent instance as shown in Figure 35-1.

    Figure 35-1 Finding the Latest PLSQLEvent Composite Instance

    Explained in the surrounding text.
  4. In the Flow Trace window that displays, click the Oracle Mediator component, as shown in Figure 35-2.

    Figure 35-2 The Flow Trace Window

    Explained in the surrounding text.

    A window displays, showing the event results, as shown in Figure 35-3.

    Figure 35-3 Displaying the Event

    Explained in the surrounding text.

35.5.3 Check the Output Log File to Verify that the Event was Received

You can check the output log file to verify that the Mediator received the event.

To verify that the event was received using the output log file:

  1. Navigate to the /tmp/output directory.
  2. Open the p_n.xml file, where n is a sequential number indicating the application instance. For example, running the application twice results in two files under the /tmp/output directory: p_1.xml and p_2.xml.
  3. Examine the file in order to verify that the event was received.

    For example, the payload log file in Example 35-2 indicates that the event was received (as shown in the bold text):

Example 35-2 Example p_n.xml file

2007-07-25 13:16:02.062 NOTIFICATION Immediate case {WriteCustomer.Write} will be executed
2007-07-25 13:16:02.070 NOTIFICATION No Condition defined
2007-07-25 13:16:02.112 NOTIFICATION Routing rule invoked for operation
 "{http://xmlns.oracle.com/SubEventMediator/EventDefinition1}CustomerEvent".
2007-07-25 13:16:02.131 NOTIFICATION Transforming the source message to target
2007-07-25 13:16:02.132 NOTIFICATION Source message properties
 :{tracking.compositeInstanceId=151,
 tracking.ecid=140.87.4.171:75256:1185394211665:0:1774489684,
 id=d76fe830-cbdf-4338-8a1a-4687ff4c3a1a}
2007-07-25 13:16:02.142 NOTIFICATION Transformation Cache miss....!!!!!!!!!!!!
2007-07-25 13:16:02.167 NOTIFICATION Getting part {payload} from message:in
2007-07-25 13:16:02.169 NOTIFICATION New document created
2007-07-25 13:16:02.171 NOTIFICATION Calling the real transfomer
2007-07-25 13:16:02.174 NOTIFICATION setting out payload to part :CustomerData
2007-07-25 13:16:02.181 NOTIFICATION Source payload =
<CU:CustomerData xmlns:CU="http://xmlns.oracle.com/Esb/CustomerData"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><CustomerId xmlns="">
...
2007-07-25 13:16:02.184 NOTIFICATION Transformed payload =
<cust:CustomerData xmlns:cust="http://xmlns.oracle.com/Esb/CustomerData">
...
2007-07-25 13:16:02.185 NOTIFICATION getPayload:normal payload
2007-07-25 13:16:02.249 NOTIFICATION getPayload:normal payload
2007-07-25 13:16:02.252 NOTIFICATION
 DEBUG: Mediator sending a request to reference WriteCustomer to its operation =
 Write
2007-07-25 13:16:04.424 NOTIFICATION Audit Trail for case
{DD5F2D003AEB11DC8F1987F2DB38D28C :
<case_trail>
   <event type="case" id="DD5F2D003AEB11DC8F1987F2DB38D28C"
 parentId="DC6A1EA03AEB11DC8F1987F2DB38D28C" caseName="WriteCustomer.Write"
 date="1185394562060" auditId="DCEFA2503AEB11DC8F1987F2DB38D28C">
      <message>Case "WriteCustomer.Write" processing started</message>
   </event>
   <event type="transform" status="Completed"
 parentId="DD5F2D003AEB11DC8F1987F2DB38D28C" date="1185394562248"
 auditId="DD7B8EA03AEB11DC8F1987F2DB38D28C">
      <message>Transformed message part "CustomerData" using "xsl/CustomerEvent
_To_CustomerData.xsl"</message>
   </event>
   <event type="publish" status="Completed"
 parentId="DD5F2D003AEB11DC8F1987F2DB38D28C" date="1185394564317"
 auditId="DD7B8EA03AEB11DC8F1987F2DB38D28C">
      <message>Invoked 1-way operation "Write" on target service
 "WriteCustomer"</message>
   </event>
</case_trail>

35.5.4 Related Links

The following documents provide additional information related to subjects discussed in this section:

  • For more information about testing and debugging your Oracle ADF application, see the chapter "Testing and Debugging ADF Components" of the Developing Fusion Web Applications with Oracle Application Development Framework.

  • For information about testing the ADF Business Components service, see the chapter "Integrating Web Services Into a Fusion Web Application" in the Developing Fusion Web Applications with Oracle Application Development Framework.

  • For more information about using the Fusion Middleware Control Console to test deployed SOA composite applications, see the chapter "Automating Testing of SOA Composite Applications" in the Developing SOA Applications with Oracle SOA Suite.

35.6 Troubleshooting the Use Case

Following are tips that may help resolve common issues that arise when developing or running this use case.

  • Enable logging for Oracle Mediator using logging.xml.

  • For the events functionality, use the Event Delivery Network database log page at http://host:port/soa-infra/events/edn-db-log. The EDN schema name is FUSION_EDN.

Related Links

See the troubleshooting section in the chapter "Deploying SOA Composite Applications" of the Oracle SOA Suite Developer's Guide for more information.

35.7 What You May Need to Know About Initiating a SOA Composite from a PL/SQL Stored Procedure

Before you implement these design patterns, be aware of the following:

  • Run the sample provided before implementing your own version of this use case. Running the sample ensures that the EDN database queue works as expected.

35.8 Known Issues and Workarounds

Following are known issues:

  • Event publishing is an asynchronous action, there is no support for synchronous event publishing.