Hi,
I've updated CXF-2641 with a new patch (which can be applied to the
2.2.x branch or to the trunk) so that maven dependencies don't need to
be changed.
Basically I've removed all the spring-orm/ibatis part and I've added a
simple implementation of ExchangeDAO which logs to text files.
Then if I need to log in a database I can use my ibatis implementation
by changing the spring configuration.
I'm not familiar at all with OSGI or JAX-RS, so I can't give you any
thought on this part yet :)
Regards,
Rémi.
Hi
Hi,
I have submitted the interceptor part as a patch in jira :
https://issues.apache.org/jira/browse/CXF-2641.
thanks. Personally, I'm not sure we can commit it just yet. The
existing response time management
feature is a light weight
component whose goal is to collect some operation statistics and
eventually expose it over
JMX. The idea of persisting exchanges and
ultimately showing them without JMX being involved seems to be
generally useful, but there
are quite a few depedencies/details in
the patch which would require users of the in/out persistence
interceptors to stick to specific
technologies like spring orm, etc,
but they may just want to save exchanges into a text file or push them
over a socket/http.
IMHO it would be useful to have persistence interceptors added to the
management feature but
it would be better to abstract away the
details of how a current exchange can be persisted. Example, I'd only
add say 2 interceptors
(in/out) plus, say, some simple
interface which can be used to save an exchange.
Next, we can have a demo showing one way (as shown in the patch) how
the exchanges can be
persisted.
I also have a question regarding the rt/management-web module : the
packaging is "jar"
in the pom.xml. Does it mean this is a
library that should be included by users in their own webapp or
should the packaging
be "war" instead ?
It will be a jar, but ultimately it will become a 'bundle' which is a
jar with its manifest
updated with few extra OSGI
instructions.
If this module is intended to be the management webapp, is it OK to
add spring-webmvc
dependency in it ?
The idea behind introducing this module is to let users do a number of
useful management-related
tasks over HTTP, by relying on the
existing CXF modules and technologies already available in JDK. Ex,
CXF JAXRS module can be
used to create various endpoints (one
will be used to let users subscribe to atom logging events, the other
one will actually let
users view the statisics amd possibly do
spme management operations, etc). I'd prefer to have a JAXRS endpoint
which could be used
to show the statistics and possibly the
exchanges persisted by various CXF 'working' endpoints.
Thoughts ?
thanks, Sergey
Index:
rt/management/src/main/java/org/apache/cxf/management/persistence/Exchange.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/persistence/Exchange.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/persistence/Exchange.java
(révision 0)
@@ -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 Exchange {
+
+ private String encoding;
+
+ private String exceptionType;
+
+ private Integer id;
+
+ private Date inDate;
+
+ private String operation;
+
+ private Date outDate;
+
+ private List<ExchangeProperty> 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<ExchangeProperty> 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<ExchangeProperty> 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;
+ }
+
+}
Index:
rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDAO.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDAO.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeDAO.java
(révision 0)
@@ -0,0 +1,39 @@
+/**
+ * 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.List;
+
+public interface ExchangeDAO {
+
+ void delete(Integer id) throws Exception;
+
+ List<Exchange> findAll() throws Exception;
+
+ List<Exchange> findByExample(Exchange example) throws Exception;
+
+ Exchange getById(Integer id) throws Exception;
+
+ Statistics getGeneralStatistics();
+
+ void removeAll() throws Exception;
+
+ void save(Exchange exchange) throws Exception;
+
+}
Index:
rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeProperty.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeProperty.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/persistence/ExchangeProperty.java
(révision 0)
@@ -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 ExchangeProperty {
+
+ private Integer id;
+
+ private String name;
+
+ private Exchange exchange;
+
+ private String value;
+
+ public Integer getId() {
+ return this.id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public Exchange getExchange() {
+ return this.exchange;
+ }
+
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setExchange(Exchange exchange) {
+ this.exchange = exchange;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+}
Index:
rt/management/src/main/java/org/apache/cxf/management/persistence/Statistics.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/persistence/Statistics.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/persistence/Statistics.java
(révision 0)
@@ -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 Statistics {
+
+ private Long errorAverageResponseTime;
+
+ private Long errorCount;
+
+ private Long successAverageResponseTime;
+
+ private Long successCount;
+
+ public Long getErrorAverageResponseTime() {
+ return this.errorAverageResponseTime;
+ }
+
+ public Long getErrorCount() {
+ return this.errorCount;
+ }
+
+ public Long getSuccessAverageResponseTime() {
+ return this.successAverageResponseTime;
+ }
+
+ public Long getSuccessCount() {
+ return this.successCount;
+ }
+
+ public void setErrorAverageResponseTime(Long errorAverageResponseTime) {
+ this.errorAverageResponseTime = errorAverageResponseTime;
+ }
+
+ public void setErrorCount(Long errorCount) {
+ this.errorCount = errorCount;
+ }
+
+ public void setSuccessAverageResponseTime(Long successAverageResponseTime)
{
+ this.successAverageResponseTime = successAverageResponseTime;
+ }
+
+ public void setSuccessCount(Long successCount) {
+ this.successCount = successCount;
+ }
+
+}
Index:
rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDAO.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDAO.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/persistence/FilesystemExchangeDAO.java
(révision 0)
@@ -0,0 +1,148 @@
+/**
+ * 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;
+import java.util.List;
+
+public class FilesystemExchangeDAO implements ExchangeDAO {
+
+ private String directory;
+
+ private String extension = "txt";
+
+
+ public void setDirectory(String directory) {
+ this.directory = directory;
+ }
+
+ public void delete(Integer id) throws Exception {
+ throw new UnsupportedOperationException();
+
+ }
+
+ public List<Exchange> findAll() throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<Exchange> findByExample(Exchange example) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ public Exchange getById(Integer id) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ public Statistics getGeneralStatistics() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeAll() throws Exception {
+ throw new UnsupportedOperationException();
+
+ }
+
+ public void save(Exchange 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 (ExchangeProperty 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();
+
+ }
+}
Index:
rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistInInterceptor.java
(révision 0)
@@ -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.Exchange;
+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, Exchange 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 {
+
+ Exchange soapExchange = new Exchange();
+ soapExchange.setInDate(new Date());
+
+ message.setContent(Exchange.class, soapExchange);
+
+ getSoapRequest(message, soapExchange);
+
+ }
+
+}
Index:
rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
===================================================================
---
rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
(révision 0)
+++
rt/management/src/main/java/org/apache/cxf/management/interceptor/PersistOutInterceptor.java
(révision 0)
@@ -0,0 +1,218 @@
+/**
+ * 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 javax.xml.namespace.QName;
+
+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.Exchange;
+import org.apache.cxf.management.persistence.ExchangeDAO;
+import org.apache.cxf.management.persistence.ExchangeProperty;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
+
+public class PersistOutInterceptor extends AbstractPhaseInterceptor<Message> {
+
+ public static final String CXF_CONSOLE_ADDITIONAL_PROPERTY_PREFIX =
+ "org.apache.cxf.management.interceptor.prefix";
+ private ExchangeDAO exchangeDAO;
+
+ public PersistOutInterceptor() {
+ super(Phase.PRE_STREAM);
+ }
+
+ class PersistOutInterceptorCallback implements CachedOutputStreamCallback {
+
+ private final Message message;
+ private final OutputStream origStream;
+ private final Exchange exchange;
+
+ public PersistOutInterceptorCallback(final Message msg, final
OutputStream os, final Exchange 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.exchangeDAO.save(this.exchange);
+ } catch (Throwable e) {
+
+ e.printStackTrace();
+ }
+ }
+
+ public void onFlush(CachedOutputStream cos) {
+
+ }
+ }
+
+ private static void addProperty(Exchange exchange, String key, String
value) {
+
+ ExchangeProperty exchangeProperty = new ExchangeProperty();
+ exchangeProperty.setExchange(exchange);
+ exchangeProperty.setName(key);
+ exchangeProperty.setValue(value);
+
+ if (exchange.getProperties() == null) {
+ exchange.setProperties(new ArrayList<ExchangeProperty>());
+ }
+ exchange.getProperties().add(exchangeProperty);
+ }
+
+ private void addPropertiesFrom(Exchange 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 {
+
+ Exchange exchange =
message.getExchange().getInMessage().getContent(Exchange.class);
+ if (exchange != null) {
+
+ final OutputStream os = message.getContent(OutputStream.class);
+ if (os == null) {
+ return;
+ }
+
+ try {
+
+ String operation = "unknown";
+ String serviceName = "unknown";
+ QName qName =
(QName)message.getExchange().getInMessage().get(Message.WSDL_OPERATION);
+
+ if (qName != null) {
+ operation = qName.toString();
+ }
+
+ qName =
(QName)message.getExchange().getInMessage().get(Message.WSDL_SERVICE);
+ if (qName != null) {
+ serviceName = qName.toString();
+ }
+
+ exchange.setServiceName(serviceName);
+ exchange.setOperation(operation);
+
+ // add all additional properties
+
+ addPropertiesFrom(exchange,
message.getExchange().getInMessage());
+ addPropertiesFrom(exchange, 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, exchange));
+
+ exchange.setOutDate(new Date());
+
+ if (message.getContent(Exception.class) != null) {
+ exchange.setStatus("ERROR");
+
+ Exception exception = message.getContent(Exception.class);
+ StringWriter stringWriter = new StringWriter();
+ if (exception.getCause() != null) {
+
exchange.setExceptionType(exception.getCause().getClass().getName());
+ exception.getCause().printStackTrace(new
PrintWriter(stringWriter));
+ } else {
+ exchange.setExceptionType(exception.getClass().getName());
+ exception.printStackTrace(new PrintWriter(stringWriter));
+ }
+ exchange.setStackTrace(stringWriter.toString());
+
+ } else {
+ exchange.setStatus("OK");
+ }
+
+ }
+ }
+
+ public void setExchangeDAO(ExchangeDAO exchangeDAO) {
+ this.exchangeDAO = exchangeDAO;
+ }
+
+}