Invoking XML facade from BPEL processes

This recipe explains how to use XML facade inside BPEL processes. We can use XML façade to simplify access of XML content from Java code. When using XML façade, the XML content is exposed over Java code.

Getting ready

To complete the recipe, there are no special prerequisites. Remember that in the Packaging XML facade into JAR recipe, we defined the ANT task to copy XML facade to the BPEL process library directory. This task basically presents all the prerequisites for XML facade utilization.

How to do it...

Open a BPEL process (Derivative_Cashflow.bpel) in JDeveloper and insert the Java Embedding activity into it:

  1. We first insert a code snippet. The whole code snippet is enclosed by a try catch block:
    try {
  2. Read the input cashflow variable data:
    oracle.xml.parser.v2.XMLElement input_cf= (oracle.xml.parser.v2.XMLElement)getVariableData("inputVariable","payload","/client:Cashflows");
  3. Un-marshall the XML content through the XML facade:
      Object obj_cf = facade.Facade.createFacade("org.packt.cashflow.facade", input_cf);
  4. We must cast the serialized object to the XML facade class:
    javax.xml.bind.JAXBElement<org.packt.cashflow.facade.CashflowsType> cfs = (javax.xml.bind.JAXBElement<org.packt.cashflow.facade.CashflowsType>)obj_cf;
  5. Retrieve the Java class out of the JAXBElement content class:
    org.packt.cashflow.facade.CashflowsType cf= cfs.getValue();
  6. Finally, we close the try block and handle any exceptions that may occur during processing:
    } catch (Exception e) {
      e.printStackTrace();
      addAuditTrailEntry("Error in XML facade occurred: " + e.getMessage()); 
    }
  7. We close the Java Embedding activity dialog. Now, we are ready to deploy the BPEL process and test the XML facade.

Actually, the execution of the BPEL process will not produce any output, since we have no output lines defined. In case some exception occurs, we will receive information about the exception in the audit trail as well as the BPEL server console.

How it works...

We add the XML facade JAR file to the BPEL process library directory (<BPEL_process_home>SCA-INFlib). Before we are able to access the XML facade classes, we need to extract the XML content from the BPEL process. To create the Java representation classes, we transform the XML content through the JAXB context. As a result, we receive an un-marshalled Java class ready to be used further in Java code.

See also

To learn how to access various variables inside an un-marshalled Java class, refer to the following two recipes: Accessing simple types through XML facade and Accessing complex types through XML facade.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset