Skip to Content

PI/XI: target message logging with local AAE not possible ? not anymore…

As you all probably know while using local Advanced Adapter Engine (AAE) processing in SAP PI 7.1 the message is logged only once (during processing by sender adapter). This is great in terms of performance but what if we need to check the mapping output? Is there a way do do it somehow? It turns out that we don’t have such an option in standard yet. Is there any alternative then?

It turns out there is – a simplest adapter module there is…

Local AAE works in such a way that from the sender adapter it executes the receiver adapter so in the outbound message to PI processing you can see the adapter info logs of the receiver adapter and this is what we can use. The idea is to add an adapter module to the receiver adapter which will put the content of the message into the audit log of PI message processing. We can do it by writing a few lines of code:

 import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext; // Classes for Module development & Trace
import com.sap.aii.af.lib.mp.module.*;
import com.sap.engine.interfaces.messaging.api.*;
import com.sap.engine.interfaces.messaging.api.auditlog.*;

public class LogAdapterXMLBean implements SessionBean, Module {
 
 private SessionContext myContext;

 public void ejbRemove() {
 }

 public void ejbActivate() {
 }

 public void ejbPassivate() {
 }

 public void setSessionContext(SessionContext context) {
  myContext = context;
 }

 public void ejbCreate() throws CreateException {
 }

 public ModuleData process(ModuleContext moduleContext,
   ModuleData inputModuleData) throws ModuleException {

  AuditAccess audit = null;

  Object obj = null;
  Message msg = null;

  MessageKey key = null;
  try {
   obj = inputModuleData.getPrincipalData();
   msg = (Message) obj;
   key = new MessageKey(msg.getMessageId(), msg.getMessageDirection());
   audit = PublicAPIAccessFactory.getPublicAPIAccess()
     .getAuditAccess();
   audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,
     “Set this: Module called”);
   
   XMLPayload xmlpayload = msg.getDocument();
   
   audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,
   “Below the content of the message”);
   audit.addAuditLogEntry(key, AuditLogStatus.SUCCESS,
   xmlpayload.getText());
   
   
  } catch (Exception e) {
   ModuleException me = new ModuleException(e);
   throw me;
  }
 
  return inputModuleData;
 }

}

 

Then we just need to add the adapter module to our receiver communication channel which is using local AAE.

and Voilà – we should see the content of the target message in the audit section of the sender communication channel.

And the best part of that is that we can easily turn it ON and OFF whenever we like so it will not affect performance during life scenarios.

Please let me know if you like this idea 🙂

13 Comments
You must be Logged on to comment or reply to a post.