cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r908065 - in /cxf/trunk/rt/management/src/main/java/org/apache/cxf/management: interceptor/ persistence/
Date Tue, 09 Feb 2010 15:09:19 GMT
Author: sergeyb
Date: Tue Feb  9 15:09:18 2010
New Revision: 908065

URL: http://svn.apache.org/viewvc?rev=908065&view=rev
Log:
CXF-2641 : applying a patch on behalf of RĂ©mi Flament, thanks

Added:
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
  (with props)
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
  (with props)
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
  (with props)
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
  (with props)
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
  (with props)
    cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
  (with props)

Added: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java?rev=908065&view=auto
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
(added)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
Tue Feb  9 15:09:18 2010
@@ -0,0 +1,82 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.interceptor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.management.persistence.ExchangeData;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class PersistInInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    public PersistInInterceptor() {
+        super(Phase.RECEIVE);
+    }
+
+    /**
+     * Copied from LoggingInInterceptor
+     * 
+     * @param soapMessage
+     */
+    private void getSoapRequest(Message soapMessage, ExchangeData exchange) {
+        InputStream is = soapMessage.getContent(InputStream.class);
+        if (is != null) {
+            CachedOutputStream bos = new CachedOutputStream();
+            try {
+                IOUtils.copy(is, bos);
+
+                bos.flush();
+                is.close();
+
+                soapMessage.setContent(InputStream.class, bos.getInputStream());
+
+                StringBuilder builder = new StringBuilder();
+                bos.writeCacheTo(builder, bos.size());
+
+                bos.close();
+
+                exchange.setRequest(builder.toString());
+                exchange.setRequestSize(bos.size());
+
+            } catch (IOException e) {
+                throw new Fault(e);
+            }
+        }
+
+    }
+
+    public void handleMessage(Message message) throws Fault {
+
+        ExchangeData soapExchange = new ExchangeData();
+        soapExchange.setInDate(new Date());
+
+        message.setContent(ExchangeData.class, soapExchange);
+
+        getSoapRequest(message, soapExchange);
+
+    }
+
+}

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java?rev=908065&view=auto
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
(added)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
Tue Feb  9 15:09:18 2010
@@ -0,0 +1,220 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.interceptor;
+
+import java.io.OutputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.LoggingMessage;
+import org.apache.cxf.io.CacheAndWriteOutputStream;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.io.CachedOutputStreamCallback;
+import org.apache.cxf.management.persistence.ExchangeData;
+import org.apache.cxf.management.persistence.ExchangeDataDAO;
+import org.apache.cxf.management.persistence.ExchangeDataProperty;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.OperationInfo;
+
+public class PersistOutInterceptor extends AbstractPhaseInterceptor<Message> {
+
+    public static final String CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX = 
+        "org.apache.cxf.management.interceptor.prefix";
+
+    private ExchangeDataDAO exchangeDataDAO;
+
+    public PersistOutInterceptor() {
+        super(Phase.PRE_STREAM);
+    }
+
+    class PersistOutInterceptorCallback implements CachedOutputStreamCallback {
+
+        private final Message message;
+        private final OutputStream origStream;
+        private final ExchangeData exchange;
+
+        public PersistOutInterceptorCallback(final Message msg, final OutputStream os, 
+                                             final ExchangeData ex) {
+            this.message = msg;
+            this.origStream = os;
+            this.exchange = ex;
+        }
+
+        public void onClose(CachedOutputStream cos) {
+            String id = (String)this.message.getExchange().get(LoggingMessage.ID_KEY);
+            if (id == null) {
+                id = LoggingMessage.nextId();
+                this.message.getExchange().put(LoggingMessage.ID_KEY, id);
+            }
+            try {
+                StringBuilder buffer = new StringBuilder();
+                cos.writeCacheTo(buffer, cos.size());
+                this.exchange.setResponseSize(cos.size());
+                this.exchange.setResponse(buffer.toString());
+            } catch (Exception ex) {
+                // ignore
+            }
+
+            try {
+                // empty out the cache
+                cos.lockOutputStream();
+                cos.resetOut(null, false);
+            } catch (Exception ex) {
+                // ignore
+            }
+            this.message.setContent(OutputStream.class, this.origStream);
+
+            try {
+                PersistOutInterceptor.this.exchangeDataDAO.save(this.exchange);
+            } catch (Throwable e) {
+
+                e.printStackTrace();
+            }
+        }
+
+        public void onFlush(CachedOutputStream cos) {
+
+        }
+    }
+
+    private static void addProperty(ExchangeData exchange, String key, String value) {
+
+        ExchangeDataProperty exchangeProperty = new ExchangeDataProperty();
+        exchangeProperty.setExchangeData(exchange);
+        exchangeProperty.setName(key);
+        exchangeProperty.setValue(value);
+
+        if (exchange.getProperties() == null) {
+            exchange.setProperties(new ArrayList<ExchangeDataProperty>());
+        }
+        exchange.getProperties().add(exchangeProperty);
+    }
+
+    private void addPropertiesFrom(ExchangeData exchange, Message message) {
+        for (Map.Entry<String, Object> entry : message.entrySet()) {
+            if (entry.getKey().equals(org.apache.cxf.message.Message.ENCODING)) {
+                exchange.setEncoding((String)entry.getValue());
+            } else if (entry.getKey().equals(org.apache.cxf.message.Message.REQUEST_URI))
{
+                exchange.setUri((String)entry.getValue());
+            } else if (entry.getKey().equals(org.apache.cxf.message.Message.PROTOCOL_HEADERS))
{
+
+                if (entry.getValue() instanceof Map) {
+                    List userAgents = (List)((Map)entry.getValue()).get("user-agent");
+                    if (userAgents != null && !userAgents.isEmpty()) {
+                        exchange.setUserAgent(userAgents.get(0).toString());
+                    }
+                }
+                if (entry.getValue() != null) {
+                    addProperty(exchange, entry.getKey(), entry.getValue().toString());
+                }
+
+            } else if (entry.getKey().startsWith("org.apache.cxf.message.Message.")
+                       && (entry.getValue() instanceof String || entry.getValue()
instanceof Integer || entry
+                           .getValue() instanceof Boolean)) {
+                addProperty(exchange, entry.getKey(), entry.getValue().toString());
+
+            } else if (entry.getKey().startsWith(CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX))
{
+                addProperty(exchange, entry.getKey().substring(
+                                                               CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX
+                                                                   .length()), entry.getValue().toString());
+
+            }
+        }
+    }
+
+    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");
+            }
+
+        }
+    }
+
+    public void setExchangeDataDAO(ExchangeDataDAO exchangeDataDAO) {
+        this.exchangeDataDAO = exchangeDataDAO;
+    }
+
+}

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java?rev=908065&view=auto
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
(added)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
Tue Feb  9 15:09:18 2010
@@ -0,0 +1,186 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.persistence;
+
+import java.util.Date;
+import java.util.List;
+
+public class ExchangeData {
+
+    private String encoding;
+
+    private String exceptionType;
+
+    private Integer id;
+
+    private Date inDate;
+
+    private String operation;
+
+    private Date outDate;
+
+    private List<ExchangeDataProperty> properties;
+
+    private String request;
+
+    private Integer requestSize;
+
+    private String response;
+
+    private Integer responseSize;
+
+    private String serviceName;
+
+    private String stackTrace;
+
+    private String status;
+
+    private String uri;
+
+    private String userAgent;
+
+    public String getEncoding() {
+        return this.encoding;
+    }
+
+    public String getExceptionType() {
+        return this.exceptionType;
+    }
+
+    public Integer getId() {
+        return this.id;
+    }
+
+    public Date getInDate() {
+        return this.inDate;
+    }
+
+    public String getOperation() {
+        return this.operation;
+    }
+
+    public Date getOutDate() {
+        return this.outDate;
+    }
+
+    public List<ExchangeDataProperty> getProperties() {
+        return this.properties;
+    }
+
+    public String getRequest() {
+        return this.request;
+    }
+
+    public Integer getRequestSize() {
+        return this.requestSize;
+    }
+
+    public String getResponse() {
+        return this.response;
+    }
+
+    public Integer getResponseSize() {
+        return this.responseSize;
+    }
+
+    public String getServiceName() {
+        return this.serviceName;
+    }
+
+    public String getStackTrace() {
+        return this.stackTrace;
+    }
+
+    public String getStatus() {
+        return this.status;
+    }
+
+    public String getUri() {
+        return this.uri;
+    }
+
+    public String getUserAgent() {
+        return this.userAgent;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public void setExceptionType(String exceptionType) {
+        this.exceptionType = exceptionType;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public void setInDate(Date inDate) {
+        this.inDate = inDate;
+    }
+
+    public void setOperation(String operation) {
+        this.operation = operation;
+    }
+
+    public void setOutDate(Date outDate) {
+        this.outDate = outDate;
+    }
+
+    public void setProperties(List<ExchangeDataProperty> properties) {
+        this.properties = properties;
+    }
+
+    public void setRequest(String request) {
+        this.request = request;
+    }
+
+    public void setRequestSize(Integer requestSize) {
+        this.requestSize = requestSize;
+    }
+
+    public void setResponse(String response) {
+        this.response = response;
+    }
+
+    public void setResponseSize(Integer responseSize) {
+        this.responseSize = responseSize;
+    }
+
+    public void setServiceName(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    public void setStackTrace(String stackTrace) {
+        this.stackTrace = stackTrace;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public void setUri(String uri) {
+        this.uri = uri;
+    }
+
+    public void setUserAgent(String userAgent) {
+        this.userAgent = userAgent;
+    }
+
+}

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeData.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java?rev=908065&view=auto
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
(added)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
Tue Feb  9 15:09:18 2010
@@ -0,0 +1,26 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.persistence;
+
+
+public interface ExchangeDataDAO {
+
+    void save(ExchangeData exchangeData) throws Exception;
+
+}

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataDAO.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java?rev=908065&view=auto
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
(added)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
Tue Feb  9 15:09:18 2010
@@ -0,0 +1,63 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.persistence;
+
+public class ExchangeDataProperty {
+
+    private Integer id;
+
+    private String name;
+
+    private ExchangeData exchangeData;
+
+    private String value;
+
+    public Integer getId() {
+        return this.id;
+    }
+
+    public String getName() {
+        return this.name;
+    }
+
+    public ExchangeData getExchangeData() {
+        return this.exchangeData;
+    }
+
+    public String getValue() {
+        return this.value;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public void setExchangeData(ExchangeData exchangeData) {
+        this.exchangeData = exchangeData;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+
+}

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDataProperty.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java?rev=908065&view=auto
==============================================================================
--- cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
(added)
+++ cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
Tue Feb  9 15:09:18 2010
@@ -0,0 +1,121 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.management.persistence;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.StringWriter;
+
+public class FilesystemExchangeDataDAO implements ExchangeDataDAO {
+
+    private String directory;
+
+    private String extension = "txt";
+    
+
+    public void setDirectory(String directory) {
+        this.directory = directory;
+    }
+
+    public void save(ExchangeData exchange) throws Exception {
+        File file = null;
+
+        if (directory == null) {
+            file = File.createTempFile("cxf-management-", "." + extension);
+        } else {
+            file = File.createTempFile("cxf-management-", "." + extension, new File(directory));
+        }
+
+        StringWriter stringWriter = new StringWriter();
+
+        stringWriter.append("Service : ");
+        stringWriter.append(exchange.getServiceName());
+        stringWriter.append("\n");
+
+        stringWriter.append("Operation : ");
+        stringWriter.append(exchange.getOperation());
+        stringWriter.append("\n");
+
+        stringWriter.append("Status : ");
+        stringWriter.append(exchange.getStatus());
+        stringWriter.append("\n");
+
+        stringWriter.append("URI : ");
+        stringWriter.append(exchange.getUri());
+        stringWriter.append("\n");
+
+        stringWriter.append("User agent : ");
+        stringWriter.append(exchange.getUserAgent());
+        stringWriter.append("\n");
+
+        stringWriter.append("Encoding : ");
+        stringWriter.append(exchange.getEncoding());
+        stringWriter.append("\n");
+
+        stringWriter.append("Date in : ");
+        stringWriter.append(exchange.getInDate().toString());
+        stringWriter.append("\n");
+
+        stringWriter.append("Date out : ");
+        stringWriter.append(exchange.getOutDate().toString());
+        stringWriter.append("\n");
+
+        stringWriter.append("Request size : ");
+        stringWriter.append(String.valueOf(exchange.getRequestSize()));
+        stringWriter.append("\n");
+
+        stringWriter.append("Response size : ");
+        stringWriter.append(String.valueOf(exchange.getResponseSize()));
+        stringWriter.append("\n");
+
+        stringWriter.append("\n\n\nRequest : \n\n\n");
+        stringWriter.append(exchange.getRequest());
+        stringWriter.append("\n\n\n\n");
+
+        stringWriter.append("\n\n\nResponse : \n\n\n");
+        stringWriter.append(exchange.getResponse());
+        stringWriter.append("\n\n\n\n");
+
+        if ("ERROR".equals(exchange.getStatus())) {
+            stringWriter.append("\n\n\nExcepttion : ");
+            stringWriter.append(exchange.getExceptionType());
+            stringWriter.append("\nStackTrace : ");
+            stringWriter.append(exchange.getStackTrace());
+            stringWriter.append("\n\n\n\n");
+        }
+
+        stringWriter.append("\n\nProperties : \n");
+
+        if (exchange.getProperties() != null) {
+            for (ExchangeDataProperty exchangeProperty : exchange.getProperties()) {
+                stringWriter.append(exchangeProperty.getName());
+                stringWriter.append(" : ");
+                stringWriter.append(exchangeProperty.getValue());
+                stringWriter.append("\n");
+            }
+        }
+
+        FileOutputStream fileOutputStream = new FileOutputStream(file);
+
+        fileOutputStream.write(stringWriter.getBuffer().toString().getBytes());
+
+        fileOutputStream.close();
+
+    }
+}

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDataDAO.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message