1 23 24 package org.apache.slide.webdav.logger; 25 26 import java.io.BufferedReader ; 27 import java.io.IOException ; 28 import java.io.InputStreamReader ; 29 30 import javax.servlet.ServletInputStream ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletRequestWrapper ; 33 34 import org.apache.slide.common.Domain; 35 36 49 public class XHttpServletRequestFacade extends HttpServletRequestWrapper { 50 51 52 public static final String DEFAULT_CHAR_ENCODING = "8859_1"; 53 54 59 private XServletInputStreamFacade inStreamFacade = null; 60 61 66 private BufferedReader reader = null; 67 68 71 private boolean usingReader = false; 72 73 76 private boolean usingStream = false; 77 78 79 90 public XHttpServletRequestFacade (HttpServletRequest request) { 91 super(request); 92 Domain.debug("Create XHttpServletRequestFacade"); 93 } 94 95 102 public ServletInputStream getInputStream() throws IOException { 103 Domain.debug("ENTER: XHttpServletRequestFacade:getInputStream()"); 104 if (usingReader) { 105 throw new IllegalStateException ("getReader() method has been called on this request"); 106 } 107 usingStream = true; 108 109 if ( inStreamFacade == null ) { 110 inStreamFacade = new XServletInputStreamFacade( super.getInputStream()); 111 } 112 113 Domain.debug("LEAVE: XHttpServletRequestFacade:getInputStream()"); 114 return ( inStreamFacade ); 115 } 116 117 118 125 public int doRead() throws IOException { 126 return inStreamFacade.read(); 127 } 128 129 138 public int doRead( byte b[], int off, int len ) throws IOException { 139 return inStreamFacade.read( b, off, len ); 140 } 141 142 143 150 public BufferedReader getReader() throws IOException { 151 Domain.debug("ENTER: XHttpServletRequestFacade:getReader()"); 152 if (usingStream) { 153 throw new IllegalStateException ("getInputStream() method has been called on this request"); 154 } 155 usingReader = true; 156 157 if ( inStreamFacade == null ) { 158 inStreamFacade = new XServletInputStreamFacade( super.getInputStream()); 159 } 160 161 if( reader != null ) { 162 Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - reader != null"); 163 return reader; } 165 166 String encoding = super.getCharacterEncoding(); 167 if (encoding == null) { 168 encoding = DEFAULT_CHAR_ENCODING; 169 } 170 171 InputStreamReader r = new InputStreamReader (inStreamFacade, encoding); 172 reader= new BufferedReader (r); 173 Domain.debug("LEAVE: XHttpServletRequestFacade:getReader() - new BufferedReader"); 174 return reader; 175 } 176 177 182 public String getRequestBody() throws IOException { 183 if ( usingStream ){ 184 Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingStream"); 185 return inStreamFacade.getBufferContent(); 186 } else if ( usingReader ) { 187 Domain.debug("XHttpServletRequestFacade:getRequestBody() - usingReader"); 188 return reader.toString(); 189 } else { 190 Domain.debug("XHttpServletRequestFacade:getRequestBody() - nor Reader nor Stream - do nothing"); 191 return ""; 192 } 193 } 194 } 195 | Popular Tags |