You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@hyperreal.org on 1999/11/01 23:24:34 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/service/http HttpRequestAdapter.java HttpResponseAdapter.java HttpConnectionHandler.java HttpResponse.java HttpServletIS.java HttpServletOS.java
costin 99/11/01 14:24:33
Modified: src/share/org/apache/tomcat/server HttpResponseAdapter.java
src/share/org/apache/tomcat/service
Ajp11ConnectionHandler.java
src/share/org/apache/tomcat/service/connector
Ajp12ConnectionHandler.java
src/share/org/apache/tomcat/service/http
HttpConnectionHandler.java
Added: src/share/org/apache/tomcat/service/http
HttpRequestAdapter.java HttpResponseAdapter.java
Removed: src/share/org/apache/tomcat/service/http HttpResponse.java
HttpServletIS.java HttpServletOS.java
Log:
-Ajp11 and Ajp12 converted to ResponseAdapter
-HttpResponse/Request adapter moved to tomcat.service.http ( the new
Http adapter )
-Removed old HttpResponse/Request and Input/Output stream ( now the Http
adapter uses only adapter interfaces )
Revision Changes Path
1.2 +4 -4 jakarta-tomcat/src/share/org/apache/tomcat/server/HttpResponseAdapter.java
Index: HttpResponseAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/server/HttpResponseAdapter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- HttpResponseAdapter.java 1999/11/01 03:44:17 1.1
+++ HttpResponseAdapter.java 1999/11/01 22:24:12 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/server/HttpResponseAdapter.java,v 1.1 1999/11/01 03:44:17 costin Exp $
- * $Revision: 1.1 $
- * $Date: 1999/11/01 03:44:17 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/server/HttpResponseAdapter.java,v 1.2 1999/11/01 22:24:12 costin Exp $
+ * $Revision: 1.2 $
+ * $Date: 1999/11/01 22:24:12 $
*
* ====================================================================
*
@@ -111,7 +111,7 @@
statusSB.setLength(0);
}
- void setOutputStream(OutputStream os) {
+ public void setOutputStream(OutputStream os) {
sout = os;
}
1.9 +18 -10 jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java
Index: Ajp11ConnectionHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- Ajp11ConnectionHandler.java 1999/10/30 00:29:28 1.8
+++ Ajp11ConnectionHandler.java 1999/11/01 22:24:14 1.9
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java,v 1.8 1999/10/30 00:29:28 costin Exp $
- * $Revision: 1.8 $
- * $Date: 1999/10/30 00:29:28 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/Ajp11ConnectionHandler.java,v 1.9 1999/11/01 22:24:14 costin Exp $
+ * $Revision: 1.9 $
+ * $Date: 1999/11/01 22:24:14 $
*
* ====================================================================
*
@@ -48,8 +48,7 @@
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
@@ -75,6 +74,8 @@
import org.apache.tomcat.util.*;
import org.apache.tomcat.server.*;
import org.apache.tomcat.service.http.*;
+import org.apache.tomcat.service.http.HttpResponseAdapter;
+import org.apache.tomcat.service.http.HttpRequestAdapter;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -113,8 +114,10 @@
AJPRequestAdapter reqA = new AJPRequestAdapter(socket); // todo: clean ConnectionHandler, make it abstract
request.setRequestAdapter( reqA );
- AJPResponse response = new AJPResponse();
- response.setOutputStream(socket.getOutputStream());
+ Ajp11ResponseAdapter resA=new Ajp11ResponseAdapter();
+ Response response = new Response();
+ resA.setOutputStream(socket.getOutputStream());
+ response.setResponseAdapter(resA );
int count = 1;
request.setResponse(response);
@@ -302,8 +305,13 @@
}
// Ajp use Status: instead of Status
-class AJPResponse extends HttpResponse {
- public void appendStatus( StringBuffer buf ) {
- buf.append("Status: " ).append( status ).append("\r\n");
+class Ajp11ResponseAdapter extends HttpResponseAdapter {
+ /** Override setStatus
+ */
+ public void setStatus( int status, String message) throws IOException {
+ statusSB.setLength(0);
+ statusSB.append("Status: " ).append( status ).append("\r\n");
+ sout.write(statusSB.toString().getBytes());
}
}
+
1.2 +17 -6 jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java
Index: Ajp12ConnectionHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/connector/Ajp12ConnectionHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Ajp12ConnectionHandler.java 1999/10/31 19:32:40 1.1
+++ Ajp12ConnectionHandler.java 1999/11/01 22:24:15 1.2
@@ -72,6 +72,8 @@
import org.apache.tomcat.util.*;
import org.apache.tomcat.server.*;
import org.apache.tomcat.service.http.*;
+import org.apache.tomcat.service.http.HttpResponseAdapter;
+import org.apache.tomcat.service.http.HttpRequestAdapter;
import org.apache.tomcat.service.*;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -108,9 +110,15 @@
Request request = new Request();
AJP12RequestAdapter reqA = new AJP12RequestAdapter(socket);
- Response response = new AJP12Response();
+ Response response=new Response();
+ AJP12ResponseAdapter resA=new AJP12ResponseAdapter();
+
+ InputStream in=socket.getInputStream();
+ OutputStream out=socket.getOutputStream();
+
request.setRequestAdapter(reqA);
- ((HttpResponse) response).setOutputStream(socket.getOutputStream());
+ response.setResponseAdapter( resA );
+ resA.setOutputStream(socket.getOutputStream());
request.setResponse(response);
response.setRequest(request);
@@ -289,10 +297,13 @@
// Ajp use Status: instead of Status
-class AJP12Response extends HttpResponse {
-
- public void appendStatus( StringBuffer buf ) {
- buf.append("Status: " ).append( status ).append("\r\n");
+class AJP12ResponseAdapter extends HttpResponseAdapter {
+ /** Override setStatus
+ */
+ public void setStatus( int status, String message) throws IOException {
+ statusSB.setLength(0);
+ statusSB.append("Status: " ).append( status ).append("\r\n");
+ sout.write(statusSB.toString().getBytes());
}
}
1.6 +8 -7 jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java
Index: HttpConnectionHandler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpConnectionHandler.java 1999/10/30 00:46:49 1.5
+++ HttpConnectionHandler.java 1999/11/01 22:24:17 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v 1.5 1999/10/30 00:46:49 costin Exp $
- * $Revision: 1.5 $
- * $Date: 1999/10/30 00:46:49 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpConnectionHandler.java,v 1.6 1999/11/01 22:24:17 costin Exp $
+ * $Revision: 1.6 $
+ * $Date: 1999/11/01 22:24:17 $
*
* ====================================================================
*
@@ -70,7 +70,6 @@
import java.util.*;
import org.apache.tomcat.core.*;
import org.apache.tomcat.util.*;
-import org.apache.tomcat.server.HttpRequestAdapter;
import javax.servlet.*;
import javax.servlet.http.*;
@@ -110,14 +109,16 @@
OutputStream out=socket.getOutputStream();
Request request=new Request();
HttpRequestAdapter reqA=new HttpRequestAdapter();
- HttpResponse response=new HttpResponse();
+ Response response=new Response();
+ HttpResponseAdapter resA=new HttpResponseAdapter();
+
response.setRequest(request);
request.setResponse( response );
request.setRequestAdapter( reqA );
+ response.setResponseAdapter( resA );
reqA.setSocket( socket );
-
- response.setOutputStream( out );
+ resA.setOutputStream( out );
reqA.readNextRequest(response );
1.1 jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java
Index: HttpRequestAdapter.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpRequestAdapter.java,v 1.1 1999/11/01 22:24:19 costin Exp $
* $Revision: 1.1 $
* $Date: 1999/11/01 22:24:19 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.service.http;
import org.apache.tomcat.core.*;
import org.apache.tomcat.util.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HttpRequestAdapter extends RequestAdapterImpl {
private Socket socket;
private boolean moreRequests = false;
InputStream sin;
public HttpRequestAdapter() {
super();
}
public void setSocket(Socket socket) throws IOException {
sin = socket.getInputStream();
in = new BufferedServletInputStream(this);
this.socket = socket;
moreRequests = true;
}
public Socket getSocket() {
return this.socket;
}
public boolean hasMoreRequests() {
return moreRequests;
}
public int doRead() throws IOException {
return sin.read();
}
public int doRead(byte[] b, int off, int len) throws IOException {
return sin.read(b, off, len);
}
public void readNextRequest(Response response) throws IOException {
String line="";
// cut&paste from BufferedInputStream.
// XXX reuse buff, avoid creating strings
byte[] buf = new byte[1024];
int count = in.readLine(buf, 0, buf.length);
if (count >= 0) {
line=new String(buf, 0, count);
}
processRequestLine(response,line);
// XXX
// return if an error was detected in processing the
// request line
if (response.getStatus() >=
HttpServletResponse.SC_BAD_REQUEST) {
return;
}
// for 0.9, we don't have headers!
if(protocol!=null)
headers.read(in);
// processCookies(); // called later
// contentLength = headers.getIntHeader("content-length");
// contentType = headers.getHeader("content-type");
// charEncoding = getCharsetFromContentType(contentType);
// XXX
// detect for real whether or not we have more requests
// coming
moreRequests = false;
}
public int getServerPort() {
return socket.getLocalPort();
}
public String getRemoteAddr() {
return socket.getInetAddress().getHostAddress();
}
public String getRemoteHost() {
return socket.getInetAddress().getHostName();
}
public void processRequestLine(Response response, String line) {
String buffer = line.trim();
int firstDelim = buffer.indexOf(' ');
int lastDelim = buffer.lastIndexOf(' ');
// default - set it to HTTP/0.9 or null if we can parse the request
//protocol = "HTTP/1.0";
if (firstDelim == -1 && lastDelim == -1) {
if (buffer.trim().length() > 0) {
firstDelim = buffer.trim().length();
lastDelim = buffer.trim().length();
}
}
if (firstDelim != lastDelim) {
String s = buffer.substring(firstDelim, lastDelim);
if (s.trim().length() == 0) {
firstDelim = lastDelim;
}
}
String requestString=null;
if (firstDelim != lastDelim) {
method = buffer.substring(0, firstDelim).trim();
protocol = buffer.substring(lastDelim + 1).trim();
requestString = buffer.substring(firstDelim + 1, lastDelim).trim();
} else if (firstDelim != -1 && lastDelim != -1) {
method = buffer.substring(0, firstDelim).trim();
protocol = null;
if (lastDelim < buffer.length()) {
requestString = buffer.substring(lastDelim + 1).trim();
}
}
if (protocol != null &&
! protocol.toLowerCase().startsWith("http/")) {
requestString += " " + protocol;
protocol = null;
}
int requestErrorCode = 0;
// see if request looks right
try {
int len = line.length();
if (len < 2) {
requestErrorCode = HttpServletResponse.SC_BAD_REQUEST;
} else if (/* line.charAt(len - 2) != '\r' || Correct, but will break C clients */
line.charAt(len - 1) != '\n') {
requestErrorCode =
HttpServletResponse.SC_REQUEST_URI_TOO_LONG;
// XXX
// For simplicity we assume there's an HTTP/1.0 on the end
// We should check to be sure.
protocol = "HTTP/1.0";
}
} catch (StringIndexOutOfBoundsException siobe) {
}
// see if uri is well formed
if (requestErrorCode == 0 &&
(requestString == null || requestString.indexOf(' ') > -1 ||
requestString.indexOf('/') != 0)) {
requestErrorCode = HttpServletResponse.SC_BAD_REQUEST;
}
if (requestErrorCode != 0) {
try {
response.sendError(requestErrorCode);
} catch (IOException ioe) {
}
return;
}
int indexQ=requestString.indexOf("?");
int rLen=requestString.length();
if ( (indexQ >-1) && ( indexQ < rLen) ) {
queryString = requestString.substring(indexQ + 1, requestString.length());
requestURI = requestString.substring(0, indexQ);
} else {
requestURI= requestString;
}
}
}
1.1 jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java
Index: HttpResponseAdapter.java
===================================================================
/*
* $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/service/http/HttpResponseAdapter.java,v 1.1 1999/11/01 22:24:23 costin Exp $
* $Revision: 1.1 $
* $Date: 1999/11/01 22:24:23 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/
package org.apache.tomcat.service.http;
import org.apache.tomcat.core.*;
import org.apache.tomcat.util.*;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
// no "buffering" - we send the status and headers as soon as
// the method is called.
// this method is _not_ thread-safe. ( if 2 threads call ServletOutputStream.out
/**
*/
public class HttpResponseAdapter implements ResponseAdapter {
protected OutputStream sout;
// no need to create new objects/request,
// avoid extra String creation
protected StringBuffer statusSB;
protected StringBuffer headersSB;
public HttpResponseAdapter() {
super();
statusSB=new StringBuffer();
headersSB=new StringBuffer();
}
public void recycle() {
sout=null;
statusSB.setLength(0);
headersSB.setLength(0);
}
public void setStatus( int status, String message ) throws IOException {
// statusSB.reset();
statusSB.append("HTTP/1.0 ").append(status);
if(message!=null) statusSB.append(" ").append(message);
statusSB.append("\r\n");
sout.write(statusSB.toString().getBytes());
statusSB.setLength(0);
}
public void setOutputStream(OutputStream os) {
sout = os;
}
public void addHeader(String name, String value) throws IOException{
headersSB.setLength(0);
headersSB.append(name).append(": ").append(value).append("\r\n");
sout.write( headersSB.toString().getBytes() );
}
public void addMimeHeaders(MimeHeaders headers) throws IOException {
headersSB.setLength(0);
int size = headers.size();
for (int i = 0; i < size; i++) {
MimeHeaderField h = headers.getField(i);
headersSB.append(h).append("\r\n");
}
sout.write( headersSB.toString().getBytes() );
}
static final byte CRLF[]= { (byte)'\r', (byte)'\n' };
public void endHeaders() throws IOException {
sout.write( CRLF, 0, 2 );
}
public void endResponse() throws IOException {
sout.flush();
}
public ServletOutputStream getServletOutputStream() throws IOException {
return null; // use default
}
public void doWrite( byte buffer[], int pos, int count) throws IOException {
sout.write( buffer, pos, count);
}
}