use of org.apache.cxf.management.persistence.ExchangeData in project cxf by apache.
the class PersistInInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
ExchangeData soapExchange = new ExchangeData();
soapExchange.setInDate(new Date());
message.setContent(ExchangeData.class, soapExchange);
getSoapRequest(message, soapExchange);
}
use of org.apache.cxf.management.persistence.ExchangeData in project cxf by apache.
the class PersistOutInterceptor method handleMessage.
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().getService();
String serviceName = String.valueOf(service.getName());
OperationInfo opInfo = message.getExchange().getBindingOperationInfo().getOperationInfo();
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");
}
}
}
Aggregations