At the Demo Jam at the SAP TechEd in Berlin, we presented a NetWeaver-based logger that sent ESME messages in response to exceptions in the Java Stack. The code is available on our Google Code repository. Just like our ABAP-based integrations, we have a created a JAVA API class that wraps the REST-API. The wrapper class isn’t complete yet but it contains enough functionality to be able to send ESME messages via Java.
The method below is the “heart” of the ESME functionality and sends message via ESME.
public void handleEvent(MessageEvent event)
{
LogRecord rec = event.getLogRecord();
Message esmeMsg = new Message();
int msgLength = rec.getMessage().length();
String message = rec.getMessage().substring(0,(msgLength<255)?msgLength:255);
String[] lines = message.split(”\n”);
StringBuffer wrappedMsg = new StringBuffer(255);
for (int i=0; i<lines.length; i++)
{
wrappedMsg.append(wrap(lines[i], 55));
}
esmeMsg.setText(wrappedMsg.toString());
String[] tags = new String[4];
tags[0] = Severity.toString(rec.getSeverity());
tags[1] = rec.getApplication().replace(’.',’ ‘);
tags[2] = rec.getLocationName().replace(’.',’ ‘);
tags[3] = rec.getUser();
esmeMsg.setTags(tags);
esmeMsg.setVia(”NetWeaverLogger”);
esme.sendMsg(esmeMsg);
}
With this code, it should be relatively easy to integrate other message sources into ESME.
Thanks to Darren for contributing the code.