Coverage Report - org.mule.transport.servlet.CachedHttpServletRequest
 
Classes in this File Line Coverage Branch Coverage Complexity
CachedHttpServletRequest
0%
0/8
0%
0/2
0
CachedHttpServletRequest$CachedServletInputStream
0%
0/19
N/A
0
 
 1  
 /*
 2  
  * $Id$
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.transport.servlet;
 11  
 
 12  
 import java.io.ByteArrayInputStream;
 13  
 import java.io.IOException;
 14  
 
 15  
 import javax.servlet.ServletInputStream;
 16  
 import javax.servlet.http.HttpServletRequest;
 17  
 import javax.servlet.http.HttpServletRequestWrapper;
 18  
 
 19  
 import org.apache.log4j.lf5.util.StreamUtils;
 20  
 
 21  
 public class CachedHttpServletRequest extends HttpServletRequestWrapper
 22  
 {
 23  
 
 24  
     private CachedServletInputStream cachedServletInputStream;
 25  
 
 26  
     public CachedHttpServletRequest(HttpServletRequest request)
 27  
     {
 28  0
         super(request);
 29  
         try
 30  
         {
 31  0
             this.cachedServletInputStream = new CachedServletInputStream(request.getInputStream());
 32  
         }
 33  0
         catch (IOException e)
 34  
         {
 35  0
         }
 36  0
     }
 37  
 
 38  
     @Override
 39  
     public ServletInputStream getInputStream() throws IOException
 40  
     {
 41  0
         if (this.cachedServletInputStream != null)
 42  
         {
 43  0
             return this.cachedServletInputStream;
 44  
         }
 45  
         else
 46  
         {
 47  0
             return super.getInputStream();
 48  
         }
 49  
     }
 50  
 
 51  
     private static class CachedServletInputStream extends ServletInputStream
 52  
     {
 53  
 
 54  
         private ByteArrayInputStream cachedStream;
 55  
 
 56  
         public CachedServletInputStream(ServletInputStream servletInputStream)
 57  0
         {
 58  
             try
 59  
             {
 60  0
                 byte[] bytes = StreamUtils.getBytes(servletInputStream);
 61  0
                 this.cachedStream = new ByteArrayInputStream(bytes);
 62  
             }
 63  0
             catch (IOException e)
 64  
             {
 65  0
             }
 66  0
         }
 67  
 
 68  
         @Override
 69  
         public int available() throws IOException
 70  
         {
 71  0
             return this.cachedStream.available();
 72  
         }
 73  
 
 74  
         @Override
 75  
         public void close() throws IOException
 76  
         {
 77  0
             this.cachedStream.close();
 78  0
         }
 79  
 
 80  
         @Override
 81  
         protected void finalize() throws Throwable
 82  
         {
 83  0
         }
 84  
 
 85  
         @Override
 86  
         public synchronized void mark(int readlimit)
 87  
         {
 88  0
             this.cachedStream.mark(readlimit);
 89  0
         }
 90  
 
 91  
         @Override
 92  
         public boolean markSupported()
 93  
         {
 94  0
             return true;
 95  
         }
 96  
 
 97  
         @Override
 98  
         public int read() throws IOException
 99  
         {
 100  0
             return this.cachedStream.read();
 101  
         }
 102  
 
 103  
         @Override
 104  
         public int read(byte[] b, int off, int len) throws IOException
 105  
         {
 106  0
             return this.cachedStream.read(b, off, len);
 107  
         }
 108  
 
 109  
         @Override
 110  
         public int read(byte[] b) throws IOException
 111  
         {
 112  0
             return this.cachedStream.read(b);
 113  
         }
 114  
 
 115  
         @Override
 116  
         public synchronized void reset() throws IOException
 117  
         {
 118  0
             this.cachedStream.reset();
 119  0
         }
 120  
 
 121  
         @Override
 122  
         public long skip(long n) throws IOException
 123  
         {
 124  0
             return this.cachedStream.skip(n);
 125  
         }
 126  
     }
 127  
 }