Adding a log to the BPEL Audit Trail

Throughout the recipes in this chapter we saw quite a few lines of auditing (addAuditTrailEntry). We did not explore them in any of the recipes, as this recipe is dedicated to exploring the possibilities of auditing in the Java Embedding activity.

How to do it…

Open the BPEL_and_Java_1_1 process and insert the Java Embedding activity (Auditing).

We insert the code into a snippet as follows:

  1. Initially, we read the content of the input data. Note that we added the auditing method that outputs the input variable content:
    Object input_obj= getVariableData("Input_Txt_Var");    
    addAuditTrailEntry("Input data", input_obj);
    
  2. In the try/catch block, we convert the content of the input variable to a double number. If the type of input variable content presents a number, we audit the converted number, otherwise we report the exception that occurred during the transformation:
    try {
      Double whatNumber = Double.parseDouble((String)input_obj);
      addAuditTrailEntry("Number is:", whatNumber);
    } catch (NumberFormatException nfe) {
      addAuditTrailEntry("Not a number ?");
      addAuditTrailEntry(nfe);
    }
    

How it works…

The Java Embedding activity offers three addAuditTrailEntry method signatures for auditing information:

  • void addAuditTrailEntry(String message)
  • void addAuditTrailEntry(String message, Object detail)
  • void addAuditTrailEntry(Throwable t)

We are able to audit a simple string message. If we want to output information about the objects, we can use the auditing method with two parameters: a string message and an object detail. In cases of handling exceptions, we utilize the auditing method that accepts the throwable parameter.

Let us now instantiate the BPEL process and enter a number as an input parameter. Inspect the Audit Trail to see the auditing information:

How it works…

Additionally, run another instance of the BPEL process and enter the content of the parameter that is not a number (for example, abc). Check the Audit Trail now and check the auditing information of the exception:

How it works…
..................Content has been hidden....................

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