1 16 17 package org.apache.coyote.tomcat3; 18 19 import java.io.IOException ; 20 21 import org.apache.coyote.ActionCode; 22 import org.apache.tomcat.util.buf.ByteChunk; 23 import org.apache.tomcat.util.buf.MessageBytes; 24 import org.apache.tomcat.core.BaseInterceptor; 25 26 33 public class Tomcat3Request extends org.apache.tomcat.core.Request { 34 35 org.apache.coyote.Request coyoteRequest=null; 36 BaseInterceptor connector = null; 37 38 42 ByteChunk readChunk = new ByteChunk(8096); 43 int pos=-1; 44 int end=-1; 45 byte [] readBuffer = null; 46 47 48 public Tomcat3Request() { 49 super(); 50 remoteAddrMB.recycle(); 51 remoteHostMB.recycle(); 52 } 53 54 public void recycle() { 55 super.recycle(); 56 if( coyoteRequest != null) coyoteRequest.recycle(); 57 58 remoteAddrMB.recycle(); 59 remoteHostMB.recycle(); 60 readChunk.recycle(); 61 62 readBuffer=null; 63 pos=-1; 64 end=-1; 65 } 66 67 public org.apache.coyote.Request getCoyoteRequest() { 68 return coyoteRequest; 69 } 70 71 75 public void setCoyoteRequest(org.apache.coyote.Request cReq) { 76 coyoteRequest=cReq; 77 78 schemeMB = coyoteRequest.scheme(); 82 methodMB = coyoteRequest.method(); 83 uriMB = coyoteRequest.requestURI(); 84 queryMB = coyoteRequest.query(); 85 protoMB = coyoteRequest.protocol(); 86 87 headers = coyoteRequest.getMimeHeaders(); 88 scookies.setHeaders(headers); 89 params.setHeaders(headers); 90 params.setQuery( queryMB ); 91 92 remoteAddrMB = coyoteRequest.remoteAddr(); 93 remoteHostMB = coyoteRequest.remoteHost(); 94 serverNameMB = coyoteRequest.serverName(); 95 } 96 97 100 void setConnector(BaseInterceptor conn) { 101 connector = conn; 102 } 103 104 107 BaseInterceptor getConnector() { 108 return connector; 109 } 110 111 113 public int doRead() throws IOException { 114 if( available == 0 ) 115 return -1; 116 if( available!= -1 ) 119 available--; 120 if(pos >= end) { 121 if(readBytes() < 0) 122 return -1; 123 } 124 return readBuffer[pos++] & 0xFF; 125 } 126 127 129 public int doRead(byte[] b, int off, int len) throws IOException { 130 if( available == 0 ) 131 return -1; 132 if(pos >= end) { 134 if(readBytes() <= 0) 135 return -1; 136 } 137 int rd = -1; 138 if((end - pos) > len) { 139 rd = len; 140 } else { 141 rd = end - pos; 142 } 143 144 System.arraycopy(readBuffer, pos, b, off, rd); 145 pos += rd; 146 if( available!= -1 ) 147 available -= rd; 148 149 return rd; 150 } 151 152 155 protected int readBytes() 156 throws IOException { 157 158 int result = coyoteRequest.doRead(readChunk); 159 if (result > 0) { 160 readBuffer = readChunk.getBytes(); 161 end = readChunk.getEnd(); 162 pos = readChunk.getStart(); 163 } else if( result < 0 ) { 164 throw new IOException ( "Read bytes failed " + result ); 165 } 166 return result; 167 168 } 169 170 172 public MessageBytes remoteAddr() { 173 if( remoteAddrMB.isNull() ) { 174 coyoteRequest.action( ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE, coyoteRequest ); 175 } 176 return remoteAddrMB; 177 } 178 179 public MessageBytes remoteHost() { 180 if( remoteHostMB.isNull() ) { 181 coyoteRequest.action( ActionCode.ACTION_REQ_HOST_ATTRIBUTE, coyoteRequest ); 182 } 183 return remoteHostMB; 184 } 185 186 public String getLocalHost() { 187 return localHost; 188 } 189 190 public MessageBytes serverName(){ 191 return coyoteRequest.serverName(); 194 } 195 196 public int getServerPort(){ 197 return coyoteRequest.getServerPort(); 198 } 199 200 public void setServerPort(int i ) { 201 coyoteRequest.setServerPort( i ); 202 } 203 204 205 public void setRemoteUser( String s ) { 206 super.setRemoteUser(s); 207 coyoteRequest.getRemoteUser().setString(s); 208 } 209 210 public String getRemoteUser() { 211 String s=coyoteRequest.getRemoteUser().toString(); 212 if( s == null ) 213 s=super.getRemoteUser(); 214 return s; 215 } 216 217 public String getAuthType() { 218 return coyoteRequest.getAuthType().toString(); 219 } 220 221 public void setAuthType(String s ) { 222 coyoteRequest.getAuthType().setString(s); 223 } 224 225 public String getJvmRoute() { 226 return coyoteRequest.instanceId().toString(); 227 } 228 229 public void setJvmRoute(String s ) { 230 coyoteRequest.instanceId().setString(s); 231 } 232 233 public boolean isSecure() { 234 return "https".equalsIgnoreCase( coyoteRequest.scheme().toString()); 235 } 236 } 237 | Popular Tags |