summaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/util/LoggingHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/util/LoggingHandler.java')
-rw-r--r--src/main/java/at/gv/util/LoggingHandler.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/main/java/at/gv/util/LoggingHandler.java b/src/main/java/at/gv/util/LoggingHandler.java
new file mode 100644
index 0000000..f5c63c5
--- /dev/null
+++ b/src/main/java/at/gv/util/LoggingHandler.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * Licensed 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 at.gv.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStreamWriter;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Handler to log JAX-WS messages to slf4j logging framework. Does currently not
+ * distinguish between incomig and outgoing messages.
+ *
+ * @author <a href="mailto:Arne.Tauber@egiz.gv.at">Arne Tauber</a>
+ *
+ */
+public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {
+
+ Logger log = LoggerFactory.getLogger(LoggingHandler.class);
+
+ public boolean handleMessage(SOAPMessageContext context) {
+ SOAPMessage msg = context.getMessage();
+ boolean request = ((Boolean) context
+ .get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+
+ try {
+ if (request) {
+ msg.writeTo(bos);
+ } else { // This is the response message
+ msg.writeTo(bos);
+ }
+
+ OutputStreamWriter writer = new OutputStreamWriter(bos);
+ String encoding = writer.getEncoding();
+
+
+
+ log.trace(bos.toString());
+ log.trace(new String(bos.toByteArray()));
+
+ } catch (Exception e) {
+ log.trace(e.getMessage(), e);
+ }
+ return true;
+ }
+
+ public boolean handleFault(SOAPMessageContext context) {
+ return handleMessage(context);
+ }
+
+ public void close(MessageContext context) {
+ }
+
+ public Set<QName> getHeaders() {
+ return null;
+ }
+
+}