mbecke      2004/06/24 14:39:53

  Modified:    httpclient/src/java/org/apache/commons/httpclient Wire.java
                        ConnectMethod.java WireLogInputStream.java
                        WireLogOutputStream.java HttpMethodBase.java
                        HttpConnection.java
  Log:
  Split wire log into header and body parts.
  
  PR: 29549
  Submitted by: Michael Becke
  Reviewed by: Oleg Kalnichevski
  
  Revision  Changes    Path
  1.9       +28 -24    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Wire.java
  
  Index: Wire.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Wire.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Wire.java 18 Apr 2004 23:51:35 -0000      1.8
  +++ Wire.java 24 Jun 2004 21:39:52 -0000      1.9
  @@ -44,10 +44,18 @@
    */
   class Wire {
   
  +    public static Wire HEADER_WIRE = new 
Wire(LogFactory.getLog("httpclient.wire.header"));
  +    
  +    public static Wire CONTENT_WIRE = new 
Wire(LogFactory.getLog("httpclient.wire.content"));
  +    
       /** Log for any wire messages. */
  -    private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire");
  -
  -    private static void wire(String header, InputStream instream)
  +    private Log log;
  +    
  +    private Wire(Log log) {
  +        this.log = log;
  +    }
  +    
  +    private void wire(String header, InputStream instream)
         throws IOException {
           StringBuffer buffer = new StringBuffer();
           int ch;
  @@ -58,7 +66,7 @@
                       buffer.append("[\\n]\"");
                       buffer.insert(0, "\"");
                       buffer.insert(0, header);
  -                    WIRE_LOG.debug(buffer.toString());
  +                    log.debug(buffer.toString());
                       buffer.setLength(0);
               } else if ((ch < 32) || (ch > 127)) {
                   buffer.append("[0x");
  @@ -72,20 +80,16 @@
               buffer.append("\"");
               buffer.insert(0, "\"");
               buffer.insert(0, header);
  -            WIRE_LOG.debug(buffer.toString());
  +            log.debug(buffer.toString());
           }
       }
   
   
  -    public static final boolean enabled() {
  -        return WIRE_LOG.isDebugEnabled();
  -    }    
  -    
  -    public static final boolean traceEnabled() {
  -        return WIRE_LOG.isTraceEnabled();
  +    public boolean enabled() {
  +        return log.isDebugEnabled();
       }    
       
  -    public static final void output(InputStream outstream)
  +    public void output(InputStream outstream)
         throws IOException {
           if (outstream == null) {
               throw new IllegalArgumentException("Output may not be null"); 
  @@ -93,7 +97,7 @@
           wire(">> ", outstream);
       }
   
  -    public static final void input(InputStream instream)
  +    public void input(InputStream instream)
         throws IOException {
           if (instream == null) {
               throw new IllegalArgumentException("Input may not be null"); 
  @@ -101,7 +105,7 @@
           wire("<< ", instream);
       }
   
  -    public static final void output(byte[] b, int off, int len)
  +    public void output(byte[] b, int off, int len)
         throws IOException {
           if (b == null) {
               throw new IllegalArgumentException("Output may not be null"); 
  @@ -109,7 +113,7 @@
           wire(">> ", new ByteArrayInputStream(b, off, len));
       }
   
  -    public static final void input(byte[] b, int off, int len)
  +    public void input(byte[] b, int off, int len)
         throws IOException {
           if (b == null) {
               throw new IllegalArgumentException("Input may not be null"); 
  @@ -117,7 +121,7 @@
           wire("<< ", new ByteArrayInputStream(b, off, len));
       }
   
  -    public static final void output(byte[] b)
  +    public void output(byte[] b)
         throws IOException {
           if (b == null) {
               throw new IllegalArgumentException("Output may not be null"); 
  @@ -125,7 +129,7 @@
           wire(">> ", new ByteArrayInputStream(b));
       }
   
  -    public static final void input(byte[] b)
  +    public void input(byte[] b)
         throws IOException {
           if (b == null) {
               throw new IllegalArgumentException("Input may not be null"); 
  @@ -133,17 +137,17 @@
           wire("<< ", new ByteArrayInputStream(b));
       }
   
  -    public static final void output(int b)
  +    public void output(int b)
         throws IOException {
           output(new byte[] {(byte) b});
       }
   
  -    public static final void input(int b)
  +    public void input(int b)
         throws IOException {
           input(new byte[] {(byte) b});
       }
   
  -    public static final void output(final String s)
  +    public void output(final String s)
         throws IOException {
           if (s == null) {
               throw new IllegalArgumentException("Output may not be null"); 
  @@ -151,7 +155,7 @@
           output(s.getBytes());
       }
   
  -    public static final void input(final String s)
  +    public void input(final String s)
         throws IOException {
           if (s == null) {
               throw new IllegalArgumentException("Input may not be null"); 
  
  
  
  1.29      +6 -6      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java
  
  Index: ConnectMethod.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- ConnectMethod.java        13 May 2004 04:03:25 -0000      1.28
  +++ ConnectMethod.java        24 Jun 2004 21:39:52 -0000      1.29
  @@ -173,8 +173,8 @@
           buffer.append(" HTTP/1.1"); 
           String line = buffer.toString();
           conn.printLine(line, getParams().getHttpElementCharset());
  -        if (Wire.enabled()) {
  -            Wire.output(line);
  +        if (Wire.HEADER_WIRE.enabled()) {
  +            Wire.HEADER_WIRE.output(line);
           }
       }
   
  
  
  
  1.15      +14 -9     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java
  
  Index: WireLogInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogInputStream.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- WireLogInputStream.java   18 Apr 2004 23:51:35 -0000      1.14
  +++ WireLogInputStream.java   24 Jun 2004 21:39:52 -0000      1.15
  @@ -36,7 +36,7 @@
   /**
    * Logs all data read to the wire LOG.
    *
  - * @author Ortwin Gl�ck
  + * @author Ortwin Gl�ck
    * @author <a href="mailto:[EMAIL PROTECTED]">Mike Bowler</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Oleg Kalnichevski</a>
    * 
  @@ -45,15 +45,20 @@
   class WireLogInputStream extends FilterInputStream {
        
       /** Original input stream. */
  -    private InputStream in;    
  +    private InputStream in;
   
  +    /** The wire log to use for writing. */
  +    private Wire wire;
  +    
       /**
        * Create an instance that wraps the specified input stream.
        * @param in The input stream.
  +     * @param wire The wire log to use.
        */
  -    public WireLogInputStream(InputStream in) {
  +    public WireLogInputStream(InputStream in, Wire wire) {
           super(in);
           this.in = in;
  +        this.wire = wire;
       }
       /**
        * 
  @@ -62,7 +67,7 @@
       public int read(byte[] b, int off, int len) throws IOException {
           int l = this.in.read(b,  off,  len);
           if (l > 0) {
  -            Wire.input(b, off, l);
  +            wire.input(b, off, l);
           }
           return l;
       }
  @@ -74,7 +79,7 @@
       public int read() throws IOException {
           int l = this.in.read();
           if (l > 0) { 
  -            Wire.input(l);
  +            wire.input(l);
           }
           return l;
       }
  @@ -86,7 +91,7 @@
       public int read(byte[] b) throws IOException {
           int l = this.in.read(b);
           if (l > 0) {
  -            Wire.input(b, 0, l);
  +            wire.input(b, 0, l);
           }
           return l;
       }
  
  
  
  1.7       +13 -8     
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogOutputStream.java
  
  Index: WireLogOutputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/WireLogOutputStream.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- WireLogOutputStream.java  18 Apr 2004 23:51:35 -0000      1.6
  +++ WireLogOutputStream.java  24 Jun 2004 21:39:52 -0000      1.7
  @@ -43,15 +43,20 @@
   class WireLogOutputStream extends FilterOutputStream {
   
       /** Original input stream. */
  -    private OutputStream out;    
  +    private OutputStream out;
  +    
  +    /** The wire log to use. */
  +    private Wire wire;
   
       /**
        * Create an instance that wraps the specified output stream.
        * @param out The output stream.
  +     * @param wire The Wire log to use.
        */
  -    public WireLogOutputStream(OutputStream out) {
  +    public WireLogOutputStream(OutputStream out, Wire wire) {
           super(out);
           this.out = out;
  +        this.wire = wire;
       }
       
       /**
  @@ -60,7 +65,7 @@
        */
       public void write(byte[] b, int off, int len) throws IOException {
           this.out.write(b,  off,  len);
  -        Wire.output(b, off, len);
  +        wire.output(b, off, len);
       }
   
       /**
  @@ -69,7 +74,7 @@
        */
       public void write(int b) throws IOException {
           this.out.write(b);
  -        Wire.output(b);
  +        wire.output(b);
       }
   
       /**
  @@ -78,6 +83,6 @@
        */
       public void write(byte[] b) throws IOException {
           this.out.write(b);
  -        Wire.output(b);
  +        wire.output(b);
       }
   }
  
  
  
  1.209     +16 -16    
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java
  
  Index: HttpMethodBase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
  retrieving revision 1.208
  retrieving revision 1.209
  diff -u -r1.208 -r1.209
  --- HttpMethodBase.java       13 Jun 2004 20:22:19 -0000      1.208
  +++ HttpMethodBase.java       24 Jun 2004 21:39:52 -0000      1.209
  @@ -1628,8 +1628,8 @@
   
           responseBody = null; // is this desired?
           InputStream is = conn.getResponseInputStream();
  -        if (Wire.traceEnabled()) {
  -            is = new WireLogInputStream(is);
  +        if (Wire.CONTENT_WIRE.enabled()) {
  +            is = new WireLogInputStream(is, Wire.CONTENT_WIRE);
           }
           InputStream result = null;
           Header transferEncodingHeader = 
responseHeaders.getFirstHeader("Transfer-Encoding");
  @@ -1742,9 +1742,9 @@
           
           Header[] headers = HttpParser.parseHeaders(
               conn.getResponseInputStream(), getParams().getHttpElementCharset());
  -        if (Wire.enabled()) {
  +        if (Wire.HEADER_WIRE.enabled()) {
               for (int i = 0; i < headers.length; i++) {
  -                Wire.input(headers[i].toExternalForm());
  +                Wire.HEADER_WIRE.input(headers[i].toExternalForm());
               }
           }
           getResponseHeaderGroup().setHeaders(headers);
  @@ -1783,8 +1783,8 @@
           String s;
           do {
               s = conn.readLine(getParams().getHttpElementCharset());
  -            if (Wire.enabled()) {
  -                Wire.input(s + "\r\n");
  +            if (Wire.HEADER_WIRE.enabled()) {
  +                Wire.HEADER_WIRE.input(s + "\r\n");
               }
               if (s != null && StatusLine.startsWithHTTP(s)) {
                   // Got one
  @@ -1869,8 +1869,8 @@
           conn.writeLine(); // close head
           // make sure the status line and headers have been sent
           conn.flushRequestOutputStream();
  -        if (Wire.enabled()) {
  -            Wire.output("\r\n");
  +        if (Wire.HEADER_WIRE.enabled()) {
  +            Wire.HEADER_WIRE.output("\r\n");
           }
   
           HttpVersion ver = getParams().getVersion();
  @@ -1984,8 +1984,8 @@
           Header[] headers = getRequestHeaders();
           for (int i = 0; i < headers.length; i++) {
               String s = headers[i].toExternalForm();
  -            if (Wire.enabled()) {
  -                Wire.output(s);
  +            if (Wire.HEADER_WIRE.enabled()) {
  +                Wire.HEADER_WIRE.output(s);
               }
               conn.print(s, charset);
           }
  @@ -2015,8 +2015,8 @@
           LOG.trace(
               "enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection)");
           String requestLine = getRequestLine(conn);
  -        if (Wire.enabled()) {
  -            Wire.output(requestLine);
  +        if (Wire.HEADER_WIRE.enabled()) {
  +            Wire.HEADER_WIRE.output(requestLine);
           }
           conn.print(requestLine, getParams().getHttpElementCharset());
       }
  
  
  
  1.94      +6 -6      
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java
  
  Index: HttpConnection.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- HttpConnection.java       14 Jun 2004 21:21:43 -0000      1.93
  +++ HttpConnection.java       24 Jun 2004 21:39:52 -0000      1.94
  @@ -773,8 +773,8 @@
           LOG.trace("enter HttpConnection.getRequestOutputStream()");
           assertOpen();
           OutputStream out = this.outputStream;
  -        if (Wire.traceEnabled()) {
  -            out = new WireLogOutputStream(out);
  +        if (Wire.CONTENT_WIRE.enabled()) {
  +            out = new WireLogOutputStream(out, Wire.CONTENT_WIRE);
           }
           return out;
       }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to