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.
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.
To handle exceptions occurring from code execution in a Java Embedding activity, perform the following steps:
Java_Math
) inside itJava_Math
activity:try { int a= 7 / 0; }catch (ArithmeticException ex) { org.packt.log.LogTheBpelExt.logException("Java_Math: Error in calculations", ex); }
divide by 0
exception, so we will be able to see something in the logfile.[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)
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:
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>
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>
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