001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.systest.handlers;
019:
020: import java.io.PrintStream;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import javax.xml.namespace.QName;
025: import javax.xml.soap.SOAPMessage;
026: import javax.xml.ws.handler.MessageContext;
027: import javax.xml.ws.handler.soap.SOAPHandler;
028: import javax.xml.ws.handler.soap.SOAPMessageContext;
029:
030: /*
031: * This simple SOAPHandler will output the contents of incoming
032: * and outgoing messages.
033: */
034: public class LoggingHandler implements SOAPHandler<SOAPMessageContext> {
035:
036: private PrintStream out;
037:
038: public LoggingHandler() {
039: setLogStream(System.out);
040: }
041:
042: protected final void setLogStream(PrintStream ps) {
043: out = ps;
044: }
045:
046: public void init(Map c) {
047: }
048:
049: public Set<QName> getHeaders() {
050: return null;
051: }
052:
053: public boolean handleMessage(SOAPMessageContext smc) {
054: //System.out.println("LoggingHandler : handleMessage Called....");
055: logToSystemOut(smc);
056: return true;
057: }
058:
059: public boolean handleFault(SOAPMessageContext smc) {
060: //System.out.println("LoggingHandler : handleFault Called....");
061: logToSystemOut(smc);
062: return true;
063: }
064:
065: // nothing to clean up
066: public void close(MessageContext messageContext) {
067: //System.out.println("LoggingHandler : close() Called....");
068: }
069:
070: // nothing to clean up
071: public void destroy() {
072: //System.out.println("LoggingHandler : destroy() Called....");
073: }
074:
075: /*
076: * Check the MESSAGE_OUTBOUND_PROPERTY in the context
077: * to see if this is an outgoing or incoming message.
078: * Write a brief message to the print stream and
079: * output the message. The writeTo() method can throw
080: * SOAPException or IOException
081: */
082: protected void logToSystemOut(SOAPMessageContext smc) {
083: Boolean outboundProperty = (Boolean) smc
084: .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
085:
086: if (outboundProperty.booleanValue()) {
087: //out.println("\nOutbound message:");
088: } else {
089: //out.println("\nInbound message:");
090: }
091:
092: SOAPMessage message = smc.getMessage();
093: try {
094: message.writeTo(out);
095: //out.println();
096: } catch (Exception e) {
097: //out.println("Exception in handler: " + e);
098: e.printStackTrace();
099: }
100: }
101: }
|