}
}
public void handleMessage(Message message) throws Fault {
ExchangeData exchangeData = message.getExchange().getInMessage().getContent(ExchangeData.class);
if (exchangeData != null) {
final OutputStream os = message.getContent(OutputStream.class);
if (os == null) {
return;
}
try {
Service service = message.getExchange().get(Service.class);
String serviceName = String.valueOf(service.getName());
OperationInfo opInfo = message.getExchange().get(OperationInfo.class);
String operationName = opInfo == null ? null : opInfo.getName().getLocalPart();
if (operationName == null) {
Object nameProperty = message.getExchange().get("org.apache.cxf.resource.operation.name");
if (nameProperty != null) {
operationName = "\"" + nameProperty.toString() + "\"";
}
}
exchangeData.setServiceName(serviceName);
exchangeData.setOperation(operationName);
// add all additional properties
addPropertiesFrom(exchangeData, message.getExchange().getInMessage());
addPropertiesFrom(exchangeData, message);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
// Write the output while caching it for the log message
final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(os);
message.setContent(OutputStream.class, newOut);
newOut.registerCallback(new PersistOutInterceptorCallback(message, os, exchangeData));
exchangeData.setOutDate(new Date());
if (message.getContent(Exception.class) != null) {
exchangeData.setStatus("ERROR");
Exception exception = message.getContent(Exception.class);
StringWriter stringWriter = new StringWriter();
if (exception.getCause() != null) {
exchangeData.setExceptionType(exception.getCause().getClass().getName());
exception.getCause().printStackTrace(new PrintWriter(stringWriter));
} else {
exchangeData.setExceptionType(exception.getClass().getName());
exception.printStackTrace(new PrintWriter(stringWriter));
}
exchangeData.setStackTrace(stringWriter.toString());
} else {
exchangeData.setStatus("OK");
}
}
}