Logging exceptions

This recipe explains how to log exceptions from the BPEL process to the logfiles. We will examine how to log exceptions from the Java Embedding activity and how to log faults to the logfiles.

Getting ready…

To complete this recipe, we need to create an empty composite. Also, we need an empty synchronous BPEL 2.0 process.

To log the exceptions, we will extend the logger we defined in the Creating a custom logger in a BPEL process recipe of Chapter 3, Advanced Tracing and Logging. In this recipe, we will also reuse the logging configuration created in that recipe. We extend the LogTheBpelExt class by adding an additional method called logException as shown in the following code:

public static final void logException(String msg, Exception e) {
  logger.logp(Level.SEVERE, "", "", msg, e);
}

This method enables the logging of exceptions on BPEL processes.

How to do it…

To handle exceptions occurring from code execution in a Java Embedding activity, perform the following steps:

  1. Open the BPEL process and put the Java Embedding activity (Java_Math) inside it
  2. The following is the code inside the Java_Math activity:
    try
    {
      int a= 7 / 0; 
    }catch (ArithmeticException ex) { 
      org.packt.log.LogTheBpelExt.logException("Java_Math: Error in calculations", ex); 
    }
  3. The execution of the preceding code obviously causes a divide by 0 exception, so we will be able to see something in the logfile.
  4. After deploying the BPEL process and running it, we see the following exception logged into the logfile (the whole stack is not shown because it is not relevant for the recipe):
    [2013-05-04T09:03:11.143+02:00] [AdminServer] [ERROR] [] [org.packt.log.Logger] [tid: 14] [userId: <anonymous>] [ecid: e84bae63a4864aa7:3c5d9698:13e6e331391:-8000-0000000000000c55,0:2] [WEBSERVICE_PORT.name: CustomLog_pt] [APP: soa-infra] [composite_name: CustomLogging] [component_name: CustomLog] [component_instance_id: 320002] [J2EE_MODULE.name: fabric] [WEBSERVICE.name: customlog_client_ep] [J2EE_APP.name: soa-infra] Error in calculations[[
    java.lang.ArithmeticException: / by zero
      at orabpel.customlog.ExecLetBxExe0.execute(ExecLetBxExe0.java:72)
      at com.collaxa.cube.engine.ext.bpel.common.wmp.BPELxExecWMP.__executeStatements(BPELxExecWMP.java:42)
  5. We see that the exception itself along with the stack trace is logged into the logfile.

Tip

The exception is logged into the logfile; however, the audit trail shows the successful completion of the Java Embedding activity.

There's more…

Another possibility for logging exceptions in BPEL is to log information from the faults that are caught. With this in mind, we will now amend the BPEL process so that it will cause a fault throw:

  1. First, we add an assign activity where we want to read data from the uninitialized variable as shown in the following code:
    <assign name="SimulateException">
      <copy>
        <from>$outputVariable.payload/client:result</from>
        <to>$nulString</to>
      </copy>
    </assign>
  2. This code will cause the selectionFailure system fault. Now we model the catch activity as shown in the following code:
    <catch faultName="bpel:selectionFailure">
      <sequence name="Sequence2">
        <extensionActivity>
          <bpelx:exec name="Java_Report_Exc" language="java">
            <![CDATA[org.packt.log.LogTheBpelExt.logException("bpel:selectionFailure", null);]]>
          </bpelx:exec>
        </extensionActivity>
      </sequence>
    </catch>
  3. We use the Java Embedding activity (Java_Report_Exc) in combination with the <catch> activity, and we put the code for the logging exception inside. The <catch> activity reacts to the business fault, and the code in Java_Report_Exc logs the exception. In the logfile, we can see the following code lines:
    [2013-05-05T11:41:56.110+02:00] [AdminServer] [ERROR] [] [org.packt.log.Logger] [tid: 21] [userId: <anonymous>] [ecid: e84bae63a4864aa7:40df49d2:13e701bae95:-8000-000000000000680f,0:2] [WEBSERVICE_PORT.name: CustomLog_pt] [APP: soa-infra] [composite_name: CustomLogging] [component_name: CustomLog] [component_instance_id: 330023] [J2EE_MODULE.name: fabric] [WEBSERVICE.name: customlog_client_ep] [J2EE_APP.name: soa-infra] bpel:selectionFailure

Note

The Oracle SOA Suite does not provide any convenient method to access business fault information from within a Java Embedding activity.

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

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