在用Eclipse开发的时候引用下面三个包
- com.sap.aii.af.ms.ifc_api.jar
- com.sap.xi.mapping.tool.lib_api.jar
- com.sap.xpi.ib.mapping.lib.jar
按照下面的代码就可以写Audit Log了
import com.sap.aii.mapping.api.*;
import java.util.*;
import java.io.*;
import com.sap.engine.interfaces.messaging.api.MessageDirection;
import com.sap.engine.interfaces.messaging.api.MessageKey;
import com.sap.engine.interfaces.messaging.api.PublicAPIAccessFactory;
import com.sap.engine.interfaces.messaging.api.auditlog.*;
import com.sap.engine.interfaces.messaging.api.exception.MessagingException;
public class <JavaMapName> extends AbstractTransformation {
private Map map = null;
public void setParameter(Map param) {
map = param;
if (map == null) {
this.map = new HashMap();
}
}
@Override
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
//Get message ID and change the format
String msgID = arg0.getInputHeader().getMessageId();
final String DASH = "-";
String uuidTimeLow = msgID.substring(0, 8);
String uuidTimeMid = msgID.substring(8, 12);
String uuidTimeHighAndVersion = msgID.substring(12, 16);
String uuidClockSeqAndReserved = msgID.substring(16, 18);
String uuidClockSeqLow = msgID.substring(18, 20);
String uuidNode = msgID.substring(20, 32);
String msgUUID = uuidTimeLow + DASH + uuidTimeMid + DASH + uuidTimeHighAndVersion + DASH
+ uuidClockSeqAndReserved + uuidClockSeqLow + DASH + uuidNode;
MessageKey msgKey = new MessageKey(msgUUID, MessageDirection.OUTBOUND);
//Get the audit object
AuditAccess audit = PublicAPIAccessFactory.getPublicAPIAccess().getAuditAccess();
audit.addAuditLogEntry(msgKey, AuditLogStatus.SUCCESS, "Java map started");
//main processing logic
audit.addAuditLogEntry(msgKey, AuditLogStatus.SUCCESS, "Java map completed");
}