axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject cvs commit: ws-axis/java/src/org/apache/axis/utils TeeOutputStream.java
Date Mon, 26 Apr 2004 16:36:28 GMT
dims        2004/04/26 09:36:28

  Modified:    java/src/org/apache/axis/transport/http HTTPSender.java
  Added:       java/src/org/apache/axis/utils TeeOutputStream.java
  Log:
  Fix NPE if we switch on logging.
  
  Revision  Changes    Path
  1.115     +13 -8     ws-axis/java/src/org/apache/axis/transport/http/HTTPSender.java
  
  Index: HTTPSender.java
  ===================================================================
  RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/transport/http/HTTPSender.java,v
  retrieving revision 1.114
  retrieving revision 1.115
  diff -u -r1.114 -r1.115
  --- HTTPSender.java	8 Apr 2004 13:09:06 -0000	1.114
  +++ HTTPSender.java	26 Apr 2004 16:36:27 -0000	1.115
  @@ -29,6 +29,7 @@
   import org.apache.axis.soap.SOAP12Constants;
   import org.apache.axis.soap.SOAPConstants;
   import org.apache.axis.utils.Messages;
  +import org.apache.axis.utils.TeeOutputStream;
   import org.apache.commons.logging.Log;
   
   import javax.xml.soap.MimeHeader;
  @@ -429,10 +430,19 @@
                   throw fault;
               }
           }
  +        ByteArrayOutputStream baos = null;
  +        if (log.isDebugEnabled()) {
  +            log.debug(Messages.getMessage("xmlSent00"));
  +            log.debug("---------------------------------------------------");
  +            baos = new ByteArrayOutputStream();
  +        }
           if (httpChunkStream) {
               ChunkedOutputStream chunkedOutputStream = new ChunkedOutputStream(out);
               out = new BufferedOutputStream(chunkedOutputStream, Constants.HTTP_TXR_BUFFER_SIZE);
               try {
  +                if(baos != null) {
  +                    out = new TeeOutputStream(out, baos);
  +                }
                   reqMessage.writeTo(out);
               } catch (SOAPException e) {
                   log.error(Messages.getMessage("exception00"), e);
  @@ -446,6 +456,9 @@
                       out.write(header.toString()
                               .getBytes(HTTPConstants.HEADER_DEFAULT_CHAR_ENCODING));
                   }
  +                if(baos != null) {
  +                    out = new TeeOutputStream(out, baos);
  +                }
                   reqMessage.writeTo(out);
               } catch (SOAPException e) {
                   log.error(Messages.getMessage("exception00"), e);
  @@ -454,14 +467,6 @@
               out.flush();
           }
           if (log.isDebugEnabled()) {
  -            log.debug(Messages.getMessage("xmlSent00"));
  -            log.debug("---------------------------------------------------");
  -            ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -            try {
  -                reqMessage.writeTo(baos);
  -            } catch (SOAPException e) {
  -                log.error(Messages.getMessage("exception00"), e);
  -            }
               log.debug(header + new String(baos.toByteArray()));
           }
   
  
  
  
  1.1                  ws-axis/java/src/org/apache/axis/utils/TeeOutputStream.java
  
  Index: TeeOutputStream.java
  ===================================================================
  /*
   * Copyright 2001-2004 The Apache Software Foundation.
   * 
   * 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 org.apache.axis.utils;
  
  import java.io.OutputStream;
  import java.io.IOException;
  
  public class TeeOutputStream extends OutputStream {
      private OutputStream left;
      private OutputStream right;
  
      public TeeOutputStream(OutputStream left, OutputStream right) {
          this.left = left;
          this.right = right;
      }
  
      public void close() throws IOException {
          left.close();
          right.close();
      }
  
      public void flush() throws IOException {
          left.flush();
          right.flush();
      }
  
      public void write(byte[] b) throws IOException {
          left.write(b);
          right.write(b);
      }
  
      public void write(byte[] b, int off, int len) throws IOException {
          left.write(b, off, len);
          right.write(b, off, len);
      }
  
      public void write(int b) throws IOException {
          left.write(b);
          right.write(b);
      }
  }
  
  

Mime
View raw message