Clover coverage report - Cactus 1.4 for J2EE API 12
Coverage timestamp: Sun Aug 25 2002 18:00:03 BST
file stats: LOC: 448   Methods: 44
NCLOC: 194   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
AutoReadHttpURLConnection.java 62.5% 45.2% 22.7% 39.8%
 1   
 /*   Generated by AspectJ version 1.0.5 */
 2   
 package org.apache.cactus.client;
 3   
 import org.apache.commons.logging.Log;
 4   
 import org.apache.commons.logging.LogFactory;
 5   
 import java.io.BufferedReader;
 6   
 import java.io.ByteArrayInputStream;
 7   
 import java.io.ByteArrayOutputStream;
 8   
 import java.io.IOException;
 9   
 import java.io.InputStream;
 10   
 import java.io.InputStreamReader;
 11   
 import java.io.OutputStream;
 12   
 import java.net.HttpURLConnection;
 13   
 import java.net.ProtocolException;
 14   
 import java.net.URL;
 15   
 import java.security.Permission;
 16   
 
 17   
 /** 
 18   
  * Wrapper class for the real <code>HttpURLConnection</code> to the test servlet 
 19   
  * that reads the complete input stream into an internal buffer on 
 20   
  * the first call to getInputStream(). This is to ensure that the test servlet 
 21   
  * is not blocked on i/o when the test caller asks for the results. 
 22   
  * <p> 
 23   
  * The wrapper returns the buffered input stream from getInputStream and 
 24   
  * delegates the rest of the calls. 
 25   
  * <p> 
 26   
  * This class is final so we don't have to provide access to protected instance 
 27   
  * variables and methods of the wrapped connection. 
 28   
  * 
 29   
  * @author <a href="mailto:Bob.Davison@reuters.com">Bob Davison</a> 
 30   
  * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 31   
  * 
 32   
  * @version $Id: AutoReadHttpURLConnection.java,v 1.4 2002/07/22 12:26:04 vmassol Exp $ 
 33   
  */
 34   
 final class AutoReadHttpURLConnection extends HttpURLConnection {
 35   
   /** 
 36   
        * The logger 
 37   
        */
 38   
   private static Log LOGGER;
 39   
   /** 
 40   
        * Default size of array for copying data. 
 41   
        */
 42   
   private static final int DEFAULT_CHUNK_SIZE = 16384;
 43   
   /** 
 44   
        * The wrapped connection. 
 45   
        */
 46   
   private HttpURLConnection delegate;
 47   
   /** 
 48   
        * The read input stream. 
 49   
        */
 50   
   private InputStream streamBuffer;
 51   
   /** 
 52   
        * Constructs a an <code>AutoReadHttpURLConnection</code> object from an 
 53   
        * <code>HttpURLConnection</code>. 
 54   
        * 
 55   
        * @param theConnection the original connection to wrap 
 56   
        */
 57  177
   AutoReadHttpURLConnection(HttpURLConnection theConnection) {
 58  177
     super(null);
 59   
     ;
 60  177
     this.delegate = theConnection;
 61   
   } 
 62   
   /** 
 63   
        * Returns an input stream containing the fully read contents of 
 64   
        * the wrapped connection's input stream 
 65   
        * 
 66   
        * @return the input stream 
 67   
        * @exception IOException if an error occurs when reading the input stream 
 68   
        */
 69  387
   public synchronized InputStream getInputStream() throws IOException {
 70  387
     try {
 71  387
       if (this.streamBuffer == null) {
 72  177
         AutoReadHttpURLConnection.LOGGER.debug("Original connection = " + this.delegate);
 73  177
         InputStream is = this.delegate.getInputStream();
 74  177
         this.streamBuffer = this.getBufferedInputStream(is);
 75   
       } 
 76   
     } catch (IOException e) {
 77  0
       this.logErrorStream(this.delegate.getErrorStream());
 78  0
       throw e;
 79   
     } 
 80  387
     return this.streamBuffer;
 81   
   } 
 82   
 
 83   
   /** 
 84   
        * Logs the HTTP error stream (used to get more information when we fail 
 85   
        * to read from the HTTP URL connection). 
 86   
        * 
 87   
        * @param theErrorStream the error stream containing the error description 
 88   
        * @exception IOException if an error occurs when reading the input stream 
 89   
        */
 90  0
   private void logErrorStream(InputStream theErrorStream) throws IOException {
 91  0
     if (theErrorStream != null) {
 92  0
       BufferedReader errorStream = new BufferedReader(new InputStreamReader(theErrorStream));
 93  0
       String buffer;
 94  0
       while ((buffer = errorStream.readLine()) != null){
 95  0
         AutoReadHttpURLConnection.LOGGER.debug("ErrorStream [" + buffer + "]");
 96   
       } 
 97   
     } 
 98   
   } 
 99   
 
 100   
   /** 
 101   
        * Fully read the HTTP Connection response stream until there is no 
 102   
        * more bytes to read. 
 103   
        * 
 104   
        * @param theInputStream the input stream to fully read 
 105   
        * @return the data read as a buffered input stream 
 106   
        * @exception IOException if an error occurs when reading the input stream 
 107   
        */
 108  177
   private InputStream getBufferedInputStream(InputStream theInputStream) throws IOException {
 109  177
     ByteArrayOutputStream os = new ByteArrayOutputStream(16384);
 110  177
     this.copy(theInputStream, os);
 111  177
     ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray());
 112  177
     return bais;
 113   
   } 
 114   
 
 115   
   /** 
 116   
        * Copies the input stream passed as parameter to the output stream also 
 117   
        * passed as parameter. The full stream is read until there is no more 
 118   
        * bytes to read. 
 119   
        * 
 120   
        * @param theInputStream the input stream to read from 
 121   
        * @param theOutputStream the output stream to write to 
 122   
        * @exception IOException if an error occurs when reading the input stream 
 123   
        */
 124  177
   private void copy(InputStream theInputStream, OutputStream theOutputStream) throws IOException {
 125  177
     AutoReadHttpURLConnection.LOGGER.debug("Content-Length : [" + this.delegate.getContentLength() 
 126   
         + "]");
 127  177
     if (this.delegate.getContentLength() != 0) {
 128  135
       byte[] buf = new byte[16384];
 129  135
       int count;
 130  ?
       while (-1 != (count = theInputStream.read(buf))){
 131  78
         this.printReadLogs(count, buf);
 132  78
         theOutputStream.write(buf, 0, count);
 133   
       } 
 134   
     } 
 135   
   } 
 136   
 
 137   
   /** 
 138   
        * Format log data read from socket for pretty printing (replaces 
 139   
        * asc char 10 by "\r", asc char 13 by "\n"). 
 140   
        * 
 141   
        * @param theCount the number of bytes read in the buffer 
 142   
        * @param theBuffer the buffer containing the data to print 
 143   
        */
 144  78
   private void printReadLogs(int theCount, byte[] theBuffer) {
 145  78
     StringBuffer prefix = new StringBuffer();
 146  78
     for (int i = 0; i < theCount; i++) {
 147  466898
       if (theBuffer[i] == 10) {
 148  15198
         prefix.append("\\r");
 149  451700
       } else if (theBuffer[i] == 13) {
 150  10195
         prefix.append("\\n");
 151   
       } else {
 152  441505
         prefix.append((char)theBuffer[i]);
 153   
       } 
 154   
     } 
 155  78
     AutoReadHttpURLConnection.LOGGER.debug("Read [" + theCount + "]: [" + prefix + "]");
 156   
   } 
 157   
 
 158   
   /** 
 159   
        * @see java.net.HttpURLConnection#connect() 
 160   
        */
 161  0
   public void connect() throws IOException {
 162  0
     this.delegate.connect();
 163   
   } 
 164   
 
 165   
   /** 
 166   
        * @see java.net.HttpURLConnection#getAllowUserInteraction() 
 167   
        */
 168  0
   public boolean getAllowUserInteraction() {
 169  0
     return this.delegate.getAllowUserInteraction();
 170   
   } 
 171   
 
 172   
   /** 
 173   
        * @see java.net.HttpURLConnection#getContent() 
 174   
        */
 175  0
   public Object getContent() throws IOException {
 176  0
     return this.delegate.getContent();
 177   
   } 
 178   
 
 179   
   /** 
 180   
        * @see java.net.HttpURLConnection#getContentEncoding() 
 181   
        */
 182  0
   public String getContentEncoding() {
 183  0
     return this.delegate.getContentEncoding();
 184   
   } 
 185   
 
 186   
   /** 
 187   
        * @see java.net.HttpURLConnection#getContentLength() 
 188   
        */
 189  0
   public int getContentLength() {
 190  0
     return this.delegate.getContentLength();
 191   
   } 
 192   
 
 193   
   /** 
 194   
        * @see java.net.HttpURLConnection#getContentType() 
 195   
        */
 196  0
   public String getContentType() {
 197  0
     return this.delegate.getContentType();
 198   
   } 
 199   
 
 200   
   /** 
 201   
        * @see java.net.HttpURLConnection#getDate() 
 202   
        */
 203  0
   public long getDate() {
 204  0
     return this.delegate.getDate();
 205   
   } 
 206   
 
 207   
   /** 
 208   
        * @see java.net.HttpURLConnection#getDefaultUseCaches() 
 209   
        */
 210  0
   public boolean getDefaultUseCaches() {
 211  0
     return this.delegate.getDefaultUseCaches();
 212   
   } 
 213   
 
 214   
   /** 
 215   
        * @see java.net.HttpURLConnection#getDoInput() 
 216   
        */
 217  0
   public boolean getDoInput() {
 218  0
     return this.delegate.getDoInput();
 219   
   } 
 220   
 
 221   
   /** 
 222   
        * @see java.net.HttpURLConnection#getDoOutput() 
 223   
        */
 224  0
   public boolean getDoOutput() {
 225  0
     return this.delegate.getDoOutput();
 226   
   } 
 227   
 
 228   
   /** 
 229   
        * @see java.net.HttpURLConnection#getExpiration() 
 230   
        */
 231  0
   public long getExpiration() {
 232  0
     return this.delegate.getExpiration();
 233   
   } 
 234   
 
 235   
   /** 
 236   
        * @see java.net.HttpURLConnection#getHeaderField(int) 
 237   
        */
 238  15
   public String getHeaderField(int thePosition) {
 239  15
     return this.delegate.getHeaderField(thePosition);
 240   
   } 
 241   
 
 242   
   /** 
 243   
        * @see java.net.HttpURLConnection#getHeaderField(String) 
 244   
        */
 245  6
   public String getHeaderField(String theName) {
 246  6
     return this.delegate.getHeaderField(theName);
 247   
   } 
 248   
 
 249   
   /** 
 250   
        * @see java.net.HttpURLConnection#getHeaderFieldDate(String, long) 
 251   
        */
 252  0
   public long getHeaderFieldDate(String theName, long theDefaultValue) {
 253  0
     return this.delegate.getHeaderFieldDate(theName, theDefaultValue);
 254   
   } 
 255   
 
 256   
   /** 
 257   
        * @see java.net.HttpURLConnection#getHeaderFieldInt(String, int) 
 258   
        */
 259  0
   public int getHeaderFieldInt(String theName, int theDefaultValue) {
 260  0
     return this.delegate.getHeaderFieldInt(theName, theDefaultValue);
 261   
   } 
 262   
 
 263   
   /** 
 264   
        * @see java.net.HttpURLConnection#getHeaderFieldKey(int) 
 265   
        */
 266  15
   public String getHeaderFieldKey(int thePosition) {
 267  15
     return this.delegate.getHeaderFieldKey(thePosition);
 268   
   } 
 269   
 
 270   
   /** 
 271   
        * @see java.net.HttpURLConnection#getIfModifiedSince() 
 272   
        */
 273  0
   public long getIfModifiedSince() {
 274  0
     return this.delegate.getIfModifiedSince();
 275   
   } 
 276   
 
 277   
   /** 
 278   
        * @see java.net.HttpURLConnection#getLastModified() 
 279   
        */
 280  0
   public long getLastModified() {
 281  0
     return this.delegate.getLastModified();
 282   
   } 
 283   
 
 284   
   /** 
 285   
        * @see java.net.HttpURLConnection#getOutputStream() 
 286   
        */
 287  0
   public OutputStream getOutputStream() throws IOException {
 288  0
     return this.delegate.getOutputStream();
 289   
   } 
 290   
 
 291   
   /** 
 292   
        * @see java.net.HttpURLConnection#getPermission() 
 293   
        */
 294  0
   public Permission getPermission() throws IOException {
 295  0
     return this.delegate.getPermission();
 296   
   } 
 297   
 
 298   
   /** 
 299   
        * @see java.net.HttpURLConnection#getRequestProperty(String) 
 300   
        */
 301  0
   public String getRequestProperty(String theKey) {
 302  0
     return this.delegate.getRequestProperty(theKey);
 303   
   } 
 304   
 
 305   
   /** 
 306   
        * @see java.net.HttpURLConnection#getURL() 
 307   
        */
 308  12
   public URL getURL() {
 309  12
     return this.delegate.getURL();
 310   
   } 
 311   
 
 312   
   /** 
 313   
        * @see java.net.HttpURLConnection#getUseCaches() 
 314   
        */
 315  0
   public boolean getUseCaches() {
 316  0
     return this.delegate.getUseCaches();
 317   
   } 
 318   
 
 319   
   /** 
 320   
        * @see java.net.HttpURLConnection#setAllowUserInteraction(boolean) 
 321   
        */
 322  0
   public void setAllowUserInteraction(boolean hasInteraction) {
 323  0
     this.delegate.setAllowUserInteraction(hasInteraction);
 324   
   } 
 325   
 
 326   
   /** 
 327   
        * @see java.net.HttpURLConnection#setDefaultUseCaches(boolean) 
 328   
        */
 329  0
   public void setDefaultUseCaches(boolean isUsingDefaultCache) {
 330  0
     this.delegate.setDefaultUseCaches(isUsingDefaultCache);
 331   
   } 
 332   
 
 333   
   /** 
 334   
        * @see java.net.HttpURLConnection#setDoInput(boolean) 
 335   
        */
 336  0
   public void setDoInput(boolean isInput) {
 337  0
     this.delegate.setDoInput(isInput);
 338   
   } 
 339   
 
 340   
   /** 
 341   
        * @see java.net.HttpURLConnection#setDoOutput(boolean) 
 342   
        */
 343  0
   public void setDoOutput(boolean isOutput) {
 344  0
     this.delegate.setDoOutput(isOutput);
 345   
   } 
 346   
 
 347   
   /** 
 348   
        * @see java.net.HttpURLConnection#setIfModifiedSince(long) 
 349   
        */
 350  0
   public void setIfModifiedSince(long isModifiedSince) {
 351  0
     this.delegate.setIfModifiedSince(isModifiedSince);
 352   
   } 
 353   
 
 354   
   /** 
 355   
        * @see java.net.HttpURLConnection#setRequestProperty(String, String) 
 356   
        */
 357  0
   public void setRequestProperty(String theKey, String theValue) {
 358  0
     this.delegate.setRequestProperty(theKey, theValue);
 359   
   } 
 360   
 
 361   
   /** 
 362   
        * @see java.net.HttpURLConnection#setUseCaches(boolean) 
 363   
        */
 364  0
   public void setUseCaches(boolean isUsingCaches) {
 365  0
     this.delegate.setUseCaches(isUsingCaches);
 366   
   } 
 367   
 
 368   
   /** 
 369   
        * @see java.net.HttpURLConnection#toString() 
 370   
        */
 371  0
   public String toString() {
 372  0
     return this.delegate.toString();
 373   
   } 
 374   
 
 375   
   /** 
 376   
        * @see java.net.HttpURLConnection#disconnect() 
 377   
        */
 378  0
   public void disconnect() {
 379  0
     this.delegate.disconnect();
 380   
   } 
 381   
 
 382   
   /** 
 383   
        * @see java.net.HttpURLConnection#getErrorStream() 
 384   
        */
 385  0
   public InputStream getErrorStream() {
 386  0
     return this.delegate.getErrorStream();
 387   
   } 
 388   
 
 389   
   /** 
 390   
        * @see java.net.HttpURLConnection#getRequestMethod() 
 391   
        */
 392  0
   public String getRequestMethod() {
 393  0
     return this.delegate.getRequestMethod();
 394   
   } 
 395   
 
 396   
   /** 
 397   
        * @see java.net.HttpURLConnection#getResponseCode() 
 398   
        */
 399  6
   public int getResponseCode() throws IOException {
 400  6
     return this.delegate.getResponseCode();
 401   
   } 
 402   
 
 403   
   /** 
 404   
        * @see java.net.HttpURLConnection#getResponseMessage() 
 405   
        */
 406  0
   public String getResponseMessage() throws IOException {
 407  0
     return this.delegate.getResponseMessage();
 408   
   } 
 409   
 
 410   
   /** 
 411   
        * @see java.net.HttpURLConnection#setRequestMethod(String) 
 412   
        */
 413  0
   public void setRequestMethod(String theMethod) throws ProtocolException {
 414  0
     this.delegate.setRequestMethod(theMethod);
 415   
   } 
 416   
 
 417   
   /** 
 418   
        * @see java.net.HttpURLConnection#usingProxy() 
 419   
        */
 420  0
   public boolean usingProxy() {
 421  0
     return this.delegate.usingProxy();
 422   
   } 
 423   
 
 424   
   /** 
 425   
    * Wrapper class for the real <code>HttpURLConnection</code> to the test servlet 
 426   
    * that reads the complete input stream into an internal buffer on 
 427   
    * the first call to getInputStream(). This is to ensure that the test servlet 
 428   
    * is not blocked on i/o when the test caller asks for the results. 
 429   
    * <p> 
 430   
    * The wrapper returns the buffered input stream from getInputStream and 
 431   
    * delegates the rest of the calls. 
 432   
    * <p> 
 433   
    * This class is final so we don't have to provide access to protected instance 
 434   
    * variables and methods of the wrapped connection. 
 435   
    * 
 436   
    * @author <a href="mailto:Bob.Davison@reuters.com">Bob Davison</a> 
 437   
    * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a> 
 438   
    * 
 439   
    * @version $Id: AutoReadHttpURLConnection.java,v 1.4 2002/07/22 12:26:04 vmassol Exp $ 
 440   
    */
 441   
   static {
 442   
     /** 
 443   
          * The logger 
 444   
          */
 445  6
     AutoReadHttpURLConnection.LOGGER = LogFactory.getLog(AutoReadHttpURLConnection.class);
 446   
   } 
 447   
 
 448   
 }