You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Paul Frieden <pf...@dchain.com> on 2000/04/05 18:20:50 UTC

requestMap, InvokerServer, and mod_jserv (Was: Hello!)

Hello,

Ironically I had been working on S2 yesterday afternoon.  My goal was to
allow mapping a particular context straight into an Apache virtual host
so I could use http://host/servlet/servletname.  I started to apply your
changes, but it does a few things that don't look to be correct.  I
assume that getRequestURI should return the actual requested URI, but
with these changes, the requested URI will be changed.  That leaves us
with a problem of finding the right context to use.  It also appends the
query string, which according to the javadoc isn't supposed to be
included in the request URI.

I was looking at the problem, and a new RequestInterceptor seemed the
easiest way besides modifying SimpleMapper.  I've got this almost
working, and it works fine with servlets and JSP pages except for
getPathInfo().  In InvokerServlet.service(), the path info is modified
based on the request URI even though we already have the correct path
info.  This is fine if the request URI is prefixed by the context path. 
However, if it is not it will wind up mangling path info.

    newPathInfo = requestPath.substring(
	context.getPath().length() +
	newServletPath.length(),
	requestPath.length());

I looked at both Ajp23 and Http, and neither of them are configuring
path info even though they extend RequestImpl.  That forces the
InvokerServlet and other code to try to decipher these based on the
request URI. 

Shouldn't connectors that extend RequestImpl determine their own
pathInfo?  If they don't have it explicitly passed, they could determine
it from the request URI.  That would allow those that are connected to a
web server to simply pass in the information.  If people are interested
I could work on the code in my spare time.

Paul Frieden



Jun Inamori wrote:
...
> S2. The solution for P2 above:
> While the JServ module sends the appropriate request to Tomcat server,
> 'Ajp12ConnectionHandler' tries to parse the original request uri to find
> the context and the servlet wrapper. For example, when the original
> request to the Apache http server is
> 'http://myhost.com/myexample/myservlet' and the path '/myexample' is
> mapped to the context '/example' on the JServ module, the JServ module
> dispatches the following request to the Tomcat server:
>         ContextName: example
>         ServletName: myservlet
>         RequestURI: /myexample/myservlet
> Note that the context name is removed of the first slash character, i.e.
> it is 'example' and not '/example'.
> This means that 'readNextRequest' method of 'Ajp12ConnectionHandler'
> fails to fined the actual context and 'service' method of
> 'ContextManager' tells all the interceptors to parse the request uri
> (/myexample/myservlet) to get the actual contexts and the servlet
> wrappers. But, of course, the context '/myexample' does not exist in the
> ContextManager.
> The solution is to provide 'AJP12RequestAdapter' with the request uri
> suitable for retrieving both of the context name and the servlet name.
> Yes, while the request uri must be '/myexample/myservlet' on the JServ
> module side, it must be '/example/myservle' on the Tomcat server side.
> The following are the quotes from my modified source:
> 
>     protected void readNextRequest() throws IOException {
> --- ignored ---
>             marker = ajpin.read();
>             switch (marker) {
> --- ignored ---
>             case 1: //beginning of request
> --- ignored ---
>                 requestURI = ajpin.readString("");             //request uri
>                 //Jun Inamori modified;
>                 // We need to fix the request URI here.
>                 if(contextPath!=null && contextPath.length()>0){
>                         // The context of 'engine' means that
>                         // the request is dispatched from
>                         // 'jserv-status' function.
>                     if(contextPath.equals("engine") && servletName!=null){
>                         if(queryString!=null){
>                             requestURI="/"+contextPath+"/"+servletName+"?"+queryString;
>                         }
>                         else{
>                             requestURI="/"+contextPath+"/"+servletName;
>                         }
>                     }
>                     else if(!requestURI.startsWith("/"+contextPath)){
>                         int index=requestURI.indexOf("/",1);
>                         if(index>0){
>                             String original_lookup=requestURI.substring(index);
>                             if(queryString!=null){
>                                 requestURI="/"+contextPath+original_lookup+"?"+queryString;
>                             }
>                             else{
>                                 requestURI="/"+contextPath+original_lookup;
>                                 if(pathInfo==null && !requestURI.endsWith("/")){
>                                   if(servletName==null){
>                                     requestURI=requestURI+"/";
>                                     pathInfo="/";
>                                   }
>                                   else if(!requestURI.endsWith(servletName)){
>                                     requestURI=requestURI+"/";
>                                     pathInfo="/";
>                                   }
>                                 }
>                             }
>                         }
>                         else{
>                             if(queryString!=null){
>                                 requestURI="/"+contextPath+"?"+queryString;
>                             }
>                             else{
>                                 requestURI="/"+contextPath;
>                                 if(pathInfo==null && !requestURI.endsWith("/")){
>                                     requestURI=requestURI+"/";
>                                     pathInfo="/";
>                                 }
>                             }
>                         }
>                     }
>                 }
> 
> --- ignored ---
> }
>