Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 package org.jboss.wsf.stack.metro.log;
 
 
com.sun.xml.ws.api.pipe.Pipe that dumps messages that pass through. Borrowed from the SUN-RI sources.

Author(s):
Kohsuke Kawaguchi
Heiko Braun
 
 public class DumpPipe extends AbstractFilterPipeImpl
 {
    private static Logger msgLog = Logger.getLogger("org.jboss.wsf.spi.MessageTrace");
 
    private final String name;
    private final PrintStream out;
    private final XMLOutputFactory staxOut;

   

Parameters:
name Specify the name that identifies this DumpPipe instance. This string will be printed when this pipe dumps messages, and allows people to distinguish which pipe instance is dumping a message when multiple DumpPipes print messages out.
out the output to send dumps to.
next the next com.sun.xml.ws.api.pipe.Pipe in the pipeline.
 
    public DumpPipe(String namePrintStream outPipe next)
    {
       super(next);
       this. = name;
       this. = out;
       this. = XMLOutputFactory.newInstance();
    }

   

Deprecated:
use DumpPipe(java.lang.String,java.io.PrintStream,com.sun.xml.ws.api.pipe.Pipe) instead
Parameters:
out the output to send dumps to.
next the next com.sun.xml.ws.api.pipe.Pipe in the pipeline.
 
    public DumpPipe(PrintStream outPipe next)
    {
       this("DumpPipe",out,next);
    }

   
Copy constructor.
 
    private DumpPipe(DumpPipe thatPipeCloner cloner)
    {
       super(that,cloner);
       this. = that.name;
       this. = that.out;
       this. = that.staxOut;
    }
 
    public Packet process(Packet packet)
    {
       dump("request",packet);
       Packet reply = .process(packet);
       dump("response",reply);
       return reply;
    }
 
    private void dump(String headerPacket packet)
   {
      if(!.isTraceEnabled())
         return;
      .trace("====[" +  + ":" + header + "]====");
      if(packet.getMessage() == null)
      {
         .trace("(none)");
      }
      else
      {
         ByteArrayOutputStream bout = new ByteArrayOutputStream();
         try
         {
            XMLStreamWriter writer = .createXMLStreamWriter(new PrintStream(bout)
            {
               public void close()
               {
                  // does nothing
               }
            });
            writer = createIndenter(writer);
            packet.getMessage().copy().writeTo(writer);
            writer.close();
         }
         catch (XMLStreamException e)
         {
            e.printStackTrace(new PrintStream(bout));
         }
         
         .trace(new String(bout.toByteArray()));
      }
      .trace("============");
   }

   
Wraps javax.xml.stream.XMLStreamWriter by an indentation engine if available.

We can do this only if we have stax-utils.jar on the classpath.

   @SuppressWarnings("unchecked")
   {
      try
      {
         Class clazz = getClass().getClassLoader().loadClass("javanet.staxutils.IndentingXMLStreamWriter");
         Constructor c = clazz.getConstructor(XMLStreamWriter.class);
         writer = (XMLStreamWriter)c.newInstance(writer);
      }
      catch (Exception e)
      {
         .warn("WARNING: put stax-utils.jar to the classpath to indent dumped output");
      }
      return writer;
   }
   public Pipe copy(PipeCloner cloner)
   {
      return new DumpPipe(thiscloner);
   }
   public void preDestroy()
   {
      // does nothing
   }
New to GrepCode? Check out our FAQ X