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...@locus.apache.org on 2000/03/21 02:27:10 UTC
cvs commit: jakarta-tomcat/src/share/org/apache/tomcat/service/connector Ajp12ConnectionHandler.java
costin 00/03/20 17:27:10
Modified: src/share/org/apache/tomcat/core ContextManager.java
HttpServletResponseFacade.java
src/share/org/apache/tomcat/request SessionInterceptor.java
SimpleMapper.java
src/share/org/apache/tomcat/service/connector
Ajp12ConnectionHandler.java
Log:
Fixed session support via URL rewriting with Apache.
Tested for Apache+tomcat, no test for load balancing.
Fixed few minor bugs in Ajp12 adapter.
Revision Changes Path
1.62 +4 -1 jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java
Index: ContextManager.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/ContextManager.java,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -r1.61 -r1.62
--- ContextManager.java 2000/03/18 03:57:47 1.61
+++ ContextManager.java 2000/03/21 01:27:08 1.62
@@ -745,11 +745,14 @@
}
public void setDebug( int level ) {
-
if( level != 0 ) System.out.println( "Setting level to " + level);
debug=level;
}
+ public int getDebug() {
+ return debug;
+ }
+
public final void log(String msg) {
if( msg.startsWith( "<l:" ))
doLog( msg );
1.6 +6 -5 jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java
Index: HttpServletResponseFacade.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HttpServletResponseFacade.java 2000/03/21 00:32:39 1.5
+++ HttpServletResponseFacade.java 2000/03/21 01:27:08 1.6
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java,v 1.5 2000/03/21 00:32:39 costin Exp $
- * $Revision: 1.5 $
- * $Date: 2000/03/21 00:32:39 $
+ * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/HttpServletResponseFacade.java,v 1.6 2000/03/21 01:27:08 costin Exp $
+ * $Revision: 1.6 $
+ * $Date: 2000/03/21 01:27:08 $
*
* ====================================================================
*
@@ -121,7 +121,8 @@
public String encodeURL(String url) {
Request request=response.getRequest();
// if I have a session
- // System.out.println("XXX " + request.isRequestedSessionIdValid() +" " + request.isRequestedSessionIdFromCookie());
+ // System.out.println("XXX " + request.isRequestedSessionIdValid() +" " + request.isRequestedSessionIdFromCookie() +
+ // " " + request.getRequestedSessionId();
if (request.isRequestedSessionIdValid()){
// if first time or cookie not returned
@@ -138,7 +139,7 @@
sb.append(";jsessionid=").append(request.getRequestedSessionId());
if( qry != null )
sb.append("?").append( qry);
- // System.out.println("RW " + url + " " + sb.toString());
+ // System.out.println("RW " + url + " " + sb.toString());
return sb.toString();
}
}
1.15 +51 -34 jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java
Index: SessionInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SessionInterceptor.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- SessionInterceptor.java 2000/03/21 00:32:40 1.14
+++ SessionInterceptor.java 2000/03/21 01:27:08 1.15
@@ -80,13 +80,24 @@
// GS, separates the session id from the jvm route
static final char SESSIONID_ROUTE_SEP = '.';
-
+ int debug=0;
+ ContextManager cm;
+
public SessionInterceptor() {
}
+ public void setDebug( int i ) {
+ System.out.println("Set debug to " + i);
+ debug=i;
+ }
+
+ public void setContextManager( ContextManager cm ) {
+ this.cm=cm;
+ }
+
public int requestMap(Request request ) {
String sessionId = null;
-
+
Cookie cookies[]=request.getCookies(); // assert !=null
for( int i=0; i<cookies.length; i++ ) {
@@ -103,6 +114,7 @@
String sig=";jsessionid=";
int foundAt=-1;
+ if( debug>0 ) cm.log(" XXX RURI=" + request.getRequestURI());
if ((foundAt=request.getRequestURI().indexOf(sig))!=-1){
sessionId=request.getRequestURI().substring(foundAt+sig.length());
// rewrite URL, do I need to do anything more?
@@ -123,38 +135,43 @@
* @return sessionId, or null if not valid
*/
private String validateSessionId(Request request, String sessionId){
- // GS, We piggyback the JVM id on top of the session cookie
- // Separate them ...
- if (null != sessionId) {
- int idex = sessionId.lastIndexOf(SESSIONID_ROUTE_SEP);
- if(idex > 0) {
- sessionId = sessionId.substring(0, idex);
- }
- }
+ // GS, We piggyback the JVM id on top of the session cookie
+ // Separate them ...
+
+ if( debug>0 ) cm.log(" Orig sessionId " + sessionId );
+ if (null != sessionId) {
+ int idex = sessionId.lastIndexOf(SESSIONID_ROUTE_SEP);
+ if(idex > 0) {
+ sessionId = sessionId.substring(0, idex);
+ }
+ }
- if (sessionId != null && sessionId.length()!=0) {
- // GS, We are in a problem here, we may actually get
- // multiple Session cookies (one for the root
- // context and one for the real context... or old session
- // cookie. We must check for validity in the current context.
- Context ctx=request.getContext();
- SessionManager sM = ctx.getSessionManager();
- if(null != sM.findSession(ctx, sessionId)) {
- sM.accessed(ctx, request, sessionId );
- request.setRequestedSessionId(sessionId);
- return sessionId;
- }
- }
- return null;
+ if (sessionId != null && sessionId.length()!=0) {
+ // GS, We are in a problem here, we may actually get
+ // multiple Session cookies (one for the root
+ // context and one for the real context... or old session
+ // cookie. We must check for validity in the current context.
+ Context ctx=request.getContext();
+ SessionManager sM = ctx.getSessionManager();
+ if(null != sM.findSession(ctx, sessionId)) {
+ sM.accessed(ctx, request, sessionId );
+ request.setRequestedSessionId(sessionId);
+ if( debug>0 ) cm.log(" Final session id " + sessionId );
+ return sessionId;
+ }
+ }
+ return null;
}
public int beforeBody( Request rrequest, Response response ) {
String reqSessionId = response.getSessionId();
- if( reqSessionId==null)
- return 0;
+ if( debug>0 ) cm.log("Before Body " + reqSessionId );
+ if( reqSessionId==null)
+ return 0;
+
// GS, set the path attribute to the cookie. This way
// multiple session cookies can be used, one for each
// context.
@@ -171,18 +188,18 @@
}
}
- Cookie cookie = new Cookie("JSESSIONID",
- reqSessionId);
+ Cookie cookie = new Cookie("JSESSIONID",
+ reqSessionId);
cookie.setMaxAge(-1);
cookie.setPath(sessionPath);
cookie.setVersion(1);
-
- response.addHeader( CookieTools.getCookieHeaderName(cookie),
- CookieTools.getCookieHeaderValue(cookie));
+
+ response.addHeader( CookieTools.getCookieHeaderName(cookie),
+ CookieTools.getCookieHeaderValue(cookie));
cookie.setVersion(0);
- response.addHeader( CookieTools.getCookieHeaderName(cookie),
- CookieTools.getCookieHeaderValue(cookie));
-
+ response.addHeader( CookieTools.getCookieHeaderName(cookie),
+ CookieTools.getCookieHeaderValue(cookie));
+
return 0;
}
1.16 +7 -2 jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java
Index: SimpleMapper.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/request/SimpleMapper.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- SimpleMapper.java 2000/03/21 00:32:40 1.15
+++ SimpleMapper.java 2000/03/21 01:27:09 1.16
@@ -131,7 +131,8 @@
// resolve the server that we are for
String path = rrequest.getRequestURI();
-
+
+ // System.out.println("XXX CM: " + path );
// strip session URL rewrite part which interferes processing
// XXX works only if ;jsessionid= is path param for the last component
// of the path!
@@ -140,8 +141,10 @@
if ((foundAt=path.indexOf(sig))!=-1){
path=path.substring(0, foundAt);
}
-
+
+ // System.out.println("XXX CM: " + path );
Context ctx= this.getContextByPath(path);
+ // System.out.println("XXX CM: " + ctx);
rrequest.setContext(ctx);
// final fix on response & request
@@ -149,12 +152,14 @@
String ctxPath = ctx.getPath();
String lookupPath=rrequest.getLookupPath();
+ // System.out.println("YYY " + lookupPath );
// do not set it if it is already set or we have no
// URI - the case of a sub-request generated internally
if( path!=null && lookupPath==null )
lookupPath= path.substring(ctxPath.length(),
path.length());
+ // System.out.println("YYY " + lookupPath );
// check for ? string on lookuppath
int qindex = lookupPath.indexOf("?");
1.17 +174 -161 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.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- Ajp12ConnectionHandler.java 2000/02/17 15:08:44 1.16
+++ Ajp12ConnectionHandler.java 2000/03/21 01:27:09 1.17
@@ -164,6 +164,7 @@
Ajpv12InputStream ajpin;
ContextManager contextM;
boolean shutdown=false;
+ boolean doLog;
public int doRead() throws IOException {
return ajpin.read();
@@ -173,12 +174,17 @@
return ajpin.read(b,off,len);
}
+ void log( String s ) {
+ contextM.log( s );
+ }
+
public AJP12RequestAdapter(ContextManager cm, Socket s) throws IOException {
this.socket = s;
this.contextM=cm;
sin = s.getInputStream();
in = new BufferedServletInputStream( this );
ajpin = new Ajpv12InputStream(sin);
+ doLog=contextM.getDebug() > 10;
}
protected void readNextRequest() throws IOException {
@@ -187,180 +193,187 @@
int signal;
try {
- while (true) {
- marker = ajpin.read();
- switch (marker) {
- case 0: //NOP marker useful for testing if stream is OK
- break;
-
- case 1: //beginning of request
- method = ajpin.readString(null); //Method
-
- contextPath = ajpin.readString(null); //Zone
- // GS, the following commented line causes the Apache + Jserv + Tomcat
- // combination to hang with a 404!!!
- // if("ROOT".equals( contextPath ) ) contextPath="";
- if("ROOT".equalsIgnoreCase( contextPath ) ) contextPath=null;
- // System.out.println("AJP: CP=" + contextPath);
-
- if( contextPath!= null )
- context=contextM.getContext( contextPath );
- // System.out.println("AJP: context=" + context );
-
- servletName = ajpin.readString(null); //Servlet
- // System.out.println("AJP: servlet=" + servletName );
-
- serverName = ajpin.readString(null); //Server hostname
- // System.out.println("AJP: serverName=" + serverName );
-
- dummy = ajpin.readString(null); //Apache document root
-
- pathInfo = ajpin.readString(null); //Apache parsed path-info
- // System.out.println("AJP: PI=" + pathInfo );
-
- // XXX Bug in mod_jserv !!!!!
- pathTranslated = ajpin.readString(null); //Apache parsed path-translated
- // System.out.println("AJP: PT=" + pathTranslated );
-
- queryString = ajpin.readString(null); //query string
- // System.out.println("AJP: QS=" + queryString );
-
- remoteAddr = ajpin.readString(""); //remote address
- // System.out.println("AJP: RA=" + remoteAddr );
-
- remoteHost = ajpin.readString(""); //remote host
- // System.out.println("AJP: RH=" + remoteHost );
-
- remoteUser = ajpin.readString(null); //remote user
- // System.out.println("AJP: RU=" + remoteUser);
-
- authType = ajpin.readString(null); //auth type
- // System.out.println("AJP: AT=" + authType);
-
- dummy = ajpin.readString(null); //remote port
-
- method = ajpin.readString(null); //request method
- // System.out.println("AJP: Meth=" + method );
-
- requestURI = ajpin.readString(""); //request uri
- // System.out.println("AJP: URI: " + requestURI + " CP:" + contextPath + " LP: " + lookupPath);
-
- if(contextPath!=null && contextPath.length() >0 )
- lookupPath=requestURI.substring( contextPath.length() + 1 );
- // System.out.println("AJP: URI: " + requestURI + " CP:" + contextPath + " LP: " + lookupPath);
-
- dummy = ajpin.readString(null); //script filename
- // System.out.println("AJP: Script filen=" + dummy);
-
- dummy = ajpin.readString(null); //script name
- // System.out.println("AJP: Script name=" + dummy);
-
- serverName = ajpin.readString(""); //server name
- // System.out.println("AJP: serverName=" + serverName );
- try {
- serverPort = Integer.parseInt(ajpin.readString("80")); //server port
- } catch (Exception any) {
- serverPort = 80;
- }
-
- dummy = ajpin.readString(""); //server protocol
- // System.out.println("AJP: Server proto=" + dummy);
- dummy = ajpin.readString(""); //server signature
- // System.out.println("AJP: Server sign=" + dummy);
- dummy = ajpin.readString(""); //server software
- // System.out.println("AJP: Server softw=" + dummy);
- jvmRoute = ajpin.readString(""); //JSERV ROUTE
- if(jvmRoute.length() == 0) {
- jvmRoute = null;
- }
- // System.out.println("AJP: Server jvmRoute=" + jvmRoute);
-
-
- /**
- * The two following lines are commented out because we don't
- * want to depend on unreleased versions of the jserv module.
- * - costin
- */
- // dummy = ajpin.readString(""); //SSL_CLIENT_DN
- // dummy = ajpin.readString(""); //SSL_CLIENT_IDN
- // XXX all dummy fields will be used after core is changed to make use
- // of them!
-
- break;
-
- case 3: // Header
- token1 = ajpin.readString(null);
- token2 = ajpin.readString("");
- headers.putHeader(token1.toLowerCase(), token2);
- break;
-
- case 254: // Signal
- signal = ajpin.read();
-
- if (signal == 0) { // PING implemented as signal
+ boolean more=true;
+ while (more) {
+ marker = ajpin.read();
+ switch (marker) {
+ case 0: //NOP marker useful for testing if stream is OK
+ break;
+
+ case 1: //beginning of request
+ method = ajpin.readString(null); //Method
+
+ contextPath = ajpin.readString(null); //Zone
+ // GS, the following commented line causes the Apache + Jserv + Tomcat
+ // combination to hang with a 404!!!
+ // if("ROOT".equals( contextPath ) ) contextPath="";
+ if("ROOT".equalsIgnoreCase( contextPath ) ) contextPath=null;
+ if( doLog ) log("AJP: CP=" + contextPath);
+
+ if( contextPath!= null )
+ context=contextM.getContext( contextPath );
+ if( doLog ) log("AJP: context=" + context );
+
+ servletName = ajpin.readString(null); //Servlet
+ if( doLog ) log("AJP: servlet=" + servletName );
+
+ serverName = ajpin.readString(null); //Server hostname
+ if( doLog ) log("AJP: serverName=" + serverName );
+
+ dummy = ajpin.readString(null); //Apache document root
+
+ pathInfo = ajpin.readString(null); //Apache parsed path-info
+ if( doLog ) log("AJP: PI=" + pathInfo );
+
+ // XXX Bug in mod_jserv !!!!!
+ pathTranslated = ajpin.readString(null); //Apache parsed path-translated
+ if( doLog ) log("AJP: PT=" + pathTranslated );
+
+ queryString = ajpin.readString(null); //query string
+ if( doLog ) log("AJP: QS=" + queryString );
+
+ remoteAddr = ajpin.readString(""); //remote address
+ if( doLog ) log("AJP: RA=" + remoteAddr );
+
+ remoteHost = ajpin.readString(""); //remote host
+ if( doLog ) log("AJP: RH=" + remoteHost );
+
+ remoteUser = ajpin.readString(null); //remote user
+ if( doLog ) log("AJP: RU=" + remoteUser);
+
+ authType = ajpin.readString(null); //auth type
+ if( doLog ) log("AJP: AT=" + authType);
+
+ dummy = ajpin.readString(null); //remote port
+
+ method = ajpin.readString(null); //request method
+ if( doLog ) log("AJP: Meth=" + method );
+
+ requestURI = ajpin.readString(""); //request uri
+ if( doLog ) log("AJP: URI: " + requestURI + " CP:" + contextPath + " LP: " + lookupPath);
+
+ // XXX don't set lookup path - problems with URL rewriting.
+ // need to be fixed.
+ // if(contextPath!=null && contextPath.length() >0 )
+ // lookupPath=requestURI.substring( contextPath.length() + 1 );
+ if( doLog ) log("AJP: URI: " + requestURI + " CP:" + contextPath + " LP: " + lookupPath);
+
+ dummy = ajpin.readString(null); //script filename
+ // System.out.println("AJP: Script filen=" + dummy);
+
+ dummy = ajpin.readString(null); //script name
+ // System.out.println("AJP: Script name=" + dummy);
+
+ serverName = ajpin.readString(""); //server name
+ if( doLog ) log("AJP: serverName=" + serverName );
try {
- // close the socket connection after we send reply
- socket.getOutputStream().write(0); // PING reply
- sin.close();
- } catch (IOException ignored) {
- System.err.println(ignored);
+ serverPort = Integer.parseInt(ajpin.readString("80")); //server port
+ } catch (Exception any) {
+ serverPort = 80;
}
- } else {
- try {
- // close the socket connection before handling any signal
- sin.close();
- if ( signal== 15 ) {
- // Shutdown - probably apache was stoped with apachectl stop
- contextM.stop();
- // same behavior as in past, because it seems that
- // stopping everything doesn't work - need to figure
- // out what happens with the threads ( XXX )
- System.exit(0);
-
- shutdown=true;
- return;
+
+ dummy = ajpin.readString(""); //server protocol
+ // System.out.println("AJP: Server proto=" + dummy);
+ dummy = ajpin.readString(""); //server signature
+ // System.out.println("AJP: Server sign=" + dummy);
+ dummy = ajpin.readString(""); //server software
+ // System.out.println("AJP: Server softw=" + dummy);
+ jvmRoute = ajpin.readString(""); //JSERV ROUTE
+ if(jvmRoute.length() == 0) {
+ jvmRoute = null;
+ }
+ if( doLog ) log("AJP: Server jvmRoute=" + jvmRoute);
+
+
+ /**
+ * The two following lines are commented out because we don't
+ * want to depend on unreleased versions of the jserv module.
+ * - costin
+ */
+ // dummy = ajpin.readString(""); //SSL_CLIENT_DN
+ // dummy = ajpin.readString(""); //SSL_CLIENT_IDN
+ // XXX all dummy fields will be used after core is changed to make use
+ // of them!
+
+ break;
+
+ case 3: // Header
+ token1 = ajpin.readString(null);
+ token2 = ajpin.readString("");
+ headers.putHeader(token1.toLowerCase(), token2);
+ break;
+
+ case 254: // Signal
+ signal = ajpin.read();
+
+ if (signal == 0) { // PING implemented as signal
+ try {
+ // close the socket connection after we send reply
+ socket.getOutputStream().write(0); // PING reply
+ sin.close();
+ } catch (IOException ignored) {
+ System.err.println(ignored);
+ }
+ } else {
+ try {
+ // close the socket connection before handling any signal
+ sin.close();
+ if ( signal== 15 ) {
+ // Shutdown - probably apache was stoped with apachectl stop
+ contextM.stop();
+ // same behavior as in past, because it seems that
+ // stopping everything doesn't work - need to figure
+ // out what happens with the threads ( XXX )
+ System.exit(0);
+
+ shutdown=true;
+ return;
+ }
+ } catch (Exception ignored) {
+ System.err.println(ignored);
}
- } catch (Exception ignored) {
- System.err.println(ignored);
+ System.err.println("Signal ignored: " + signal);
}
- System.err.println("Signal ignored: " + signal);
- }
- return;
-
- case 4:
- case 255:
- return;
-
- case -1:
- throw new java.io.IOException("Stream closed prematurely");
-
-
- default:
- throw new java.io.IOException("Stream broken");
-
-
- } // while
- } // switch
+ return;
+
+ case 4:
+ case 255:
+ more=false;
+ break;
+
+ case -1:
+ throw new java.io.IOException("Stream closed prematurely");
+
+
+ default:
+ throw new java.io.IOException("Stream broken");
+
+
+ } // switch
+ } // while
} catch (IOException ioe) {
throw ioe;
} catch (Exception e) {
System.err.println("Uncaught exception" + e);
e.printStackTrace();
}
-
+
// REQUEST_URI includes query string
- int idQ= requestURI.indexOf("?");
- if ( idQ > -1) {
- requestURI = requestURI.substring(0, idQ);
- }
-
-
- // System.out.println("Request: " + requestURI );
- // System.out.println("Query: " + queryString );
- // System.out.println("ENV: " + env_vars );
+ int indexQ=requestURI.indexOf("?");
+ int rLen=requestURI.length();
+ if ( (indexQ >-1) && ( indexQ < rLen) ) {
+ if(doLog) log("Orig QS " + queryString );
+ queryString = requestURI.substring(indexQ + 1, requestURI.length());
+ if(doLog) log("New QS " + queryString );
+ requestURI = requestURI.substring(0, indexQ);
+ }
+
+ if( doLog ) log("Request: " + requestURI );
+ if( doLog ) log ("Query: " + queryString );
+ // System.out.println("ENV: " + env_vars );
// System.out.println("HEADERS: " + headers_in );
// System.out.println("PARAMETERS: " + parameters );
-
+
//processCookies();