Search in sources :

Example 1 with ExchangeData

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);
}
Also used : ExchangeData(org.apache.cxf.management.persistence.ExchangeData) Date(java.util.Date)

Example 2 with ExchangeData

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");
        }
    }
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) StringWriter(java.io.StringWriter) ExchangeData(org.apache.cxf.management.persistence.ExchangeData) OutputStream(java.io.OutputStream) CacheAndWriteOutputStream(org.apache.cxf.io.CacheAndWriteOutputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Service(org.apache.cxf.service.Service) Date(java.util.Date) CacheAndWriteOutputStream(org.apache.cxf.io.CacheAndWriteOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

Date (java.util.Date)2 ExchangeData (org.apache.cxf.management.persistence.ExchangeData)2 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 CacheAndWriteOutputStream (org.apache.cxf.io.CacheAndWriteOutputStream)1 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)1 Service (org.apache.cxf.service.Service)1 OperationInfo (org.apache.cxf.service.model.OperationInfo)1