Monday, February 21, 2011

Logging in Java callouts in B2B


In this blog I will explain on how to log required information from Callout java class in B2B into the soa server log files, so as to help you in debugging issues related to Callout.
In some case while using the Callout classes, we will get B2B runtime errors but there will not be any definite pointers on where the error happened in the java callout classes. For developers who are writing Callout classes for first time would love to see the system out printlns to be printed in the log files.
There is a java class named DiagnosticService in oracle.tip.b2b.system package of b2b.jar. You can make use of the different log methods available in the class as we do for log4j or other logging frameworks, depending on the amount of information you have at the point of time.
Logging Methods available in Diagnostic service
public static void log(Level level, Throwable t)
public static void log(Throwable t)
public static void log(Level level, String msg)
public static void log(String msg)
public static void log(int component, int severity, String message)
public static void log(int component, String componentName, int severity, String message)
  
Severity levels
1.     DIAGNOSTICS_ALL = -6;
2.     DIAGNOSTICS_DEBUG = -5;
3.     DIAGNOSTICS_INFORMATION = -4;
4.     DIAGNOSTICS_WARNING = -3;
5.     DIAGNOSTICS_ERRORS = -2;
6.     DIAGNOSTICS_FATAL = -1;
7.     DIAGNOSTICS_NONE = 0;

Component Levels
1.     REPOSCOMPONENT = 0;
2.     IPCOMPONENT = 1;
3.     BLLCOMPONENT = 2;
4.     B2BCOMPONENT = 3;
5.     MVECOMPONENT = 4;
6.     RULECOMPONENT = 5;
7.     AFCOMPONENT = 6;
8.     TRANSFORMCOMPONENT = 7;
9.     TRANSLATECOMPONENT = 8;
10.  TSCOMPONENT = 9;
11.  RTCOMPONENT = 10;
12.  DEPLOYCOMPONENT = 11;
13.  CORRELATIONCOMPONENT = 12;
14.  DVMCOMPONENT = 13;
15.  REPORTCOMPONENT = 14;
16.  ADAPTERCOMPONENT = 15;
17.  UICOMPONENT = 16;
18.  PURGECOMPONENT = 17;


Sample Code Snippet
1.     Write a private method with the call to Diagnostic service log method (better practice for auditing)
private static void b2blog(Object message)  {
DiagnosticService.log(3, -2, (new StringBuilder()).append("").append(message).toString());
}

2.     Usage :-When you need to log an audit message
b2blog((new StringBuilder()).append("TestCallout execute() - Context parameters: = ").append(calloutContext.getAllProperties()).toString());
3.     Usage :-When you need to log an Exception
Catch(Exception ex){
DiagnosticService.log(ex);
}

That’s it for now.        

No comments: