01: /*
02: * $Id: DumpFilter.java,v 1.4 2007/01/08 09:28:54 ashutoshshahi Exp $
03: */
04:
05: /*
06: * The contents of this file are subject to the terms
07: * of the Common Development and Distribution License
08: * (the License). You may not use this file except in
09: * compliance with the License.
10: *
11: * You can obtain a copy of the license at
12: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
13: * See the License for the specific language governing
14: * permissions and limitations under the License.
15: *
16: * When distributing Covered Code, include this CDDL
17: * Header Notice in each file and include the License file
18: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
19: * If applicable, add the following below the CDDL Header,
20: * with the fields enclosed by brackets [] replaced by
21: * you own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
25: */
26: package com.sun.xml.wss.impl.filter;
27:
28: import com.sun.xml.wss.logging.LogDomainConstants;
29: import java.io.ByteArrayOutputStream;
30: import java.io.OutputStream;
31: import java.util.logging.Level;
32:
33: import com.sun.xml.wss.ProcessingContext;
34: import com.sun.xml.wss.XWSSecurityException;
35: import java.util.logging.Logger;
36:
37: /**
38: * Dump a SOAP message for debugging.
39: *
40: */
41: public class DumpFilter {
42:
43: private static Level DEFAULT_LOG_LEVEL = Level.INFO;
44:
45: private static final String lineSeparator = System
46: .getProperty("line.separator");
47:
48: private static Logger log = Logger.getLogger(
49: LogDomainConstants.IMPL_FILTER_DOMAIN,
50: LogDomainConstants.IMPL_FILTER_DOMAIN_BUNDLE);
51:
52: public static void process(ProcessingContext context)
53: throws XWSSecurityException {
54:
55: OutputStream dest;
56: ByteArrayOutputStream baos = null;
57: // Collect output in a byte[]
58: baos = new ByteArrayOutputStream();
59: dest = baos;
60:
61: String label = "Sending Message";
62:
63: if (context.isInboundMessage()) {
64: label = "Received Message";
65: }
66:
67: String msg1 = "==== " + label + " Start ====" + lineSeparator;
68:
69: try {
70: TeeFilter teeFilter;
71: teeFilter = new TeeFilter(dest, true);
72: teeFilter.process(context.getSOAPMessage());
73: } catch (Exception e) {
74: log.log(Level.SEVERE, "WSS1411.unableto.dump.soapmessage",
75: new Object[] { e.getMessage() });
76: throw new XWSSecurityException("Unable to dump SOAPMessage");
77: }
78:
79: String msg2 = "==== " + label + " End ====" + lineSeparator;
80:
81: byte[] bytes = baos.toByteArray();
82: String logMsg = msg1 + new String(bytes) + msg2;
83: log.log(DEFAULT_LOG_LEVEL, logMsg);
84: }
85:
86: }
|