[OT] HTTP and tomcat filter question

2004-02-16 Thread Duane Burchell

This question is a bit OT, since it deals more with HTTP than tomcat (I
think), but maybe somebody can help.

I'm (still) working with setting up filters in Tomcat, and am seeing some
erratic behavior, which leads me to ask this question :

Assuming I have a URL of
http://www.mysite.com/myservlet.jsp?myvar=1yourvar=2

When the browser sends this request to tomcat (which is also acting as a
webserver - no apache is running), does it put everything after the ? into
the QUERY_STRING HTTP variable, or does it include it in the URL request?

I have a filter in place that will replace /variable/ with variable= to
allow for proper processing of variables.  Here is what I observe :

If I have a URL of :
mysite.com/myservlet.jsp/myvar/1/yourvar/2

then it will properly translate this into :
mysite.com/myservlet.jsp?myvar=1yourvar=2

and everything works.

However, we have a new requirement that we want to keep ?myvar=1 as part
of the original URL, so the incoming request would look like this :
mysite.com/myservlet.jsp?myvar=1/yourvar/2

and, naturally, we want it translated into
mysite.com/myservlet.jsp?myvar=1yourvar=2

but this does NOT happen.  Instead, it seems like the filter is doing
nothing.
The only explanation I can think of is that, now that the ? is in the
original request URL, the browser is taking everthing after it, stripping
it out of the request URL, and putting it into the QUERY_STRING variable -
so that the filter doesn't see it.  The filter would only see
mysite.com/myservlet.jsp
and would not perform any translation.

Does this make any sense?  I've been reading up on HTTP all over the net,
but can't find any sites that really look at how the URL request is broken
down when variables are present.

Any help is greatly appreciated.

- Duane

ps.  For those of you who inquired about my success with the tomcat
filter, I will post an update once I get things working ... and hopefully
it will help some of you as well.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [OT] HTTP and tomcat filter question

2004-02-16 Thread Justin Ruthenbeck
Duane,

This is a pretty crazy set of requirements you're working with here -- 
I'll trust there's a good reason for it and just stick to the question.  ;)

At 11:34 AM 2/16/2004, you wrote:
Assuming I have a URL of
http://www.mysite.com/myservlet.jsp?myvar=1yourvar=2
Your URL is: http://www.mysite.com/myservlet.jsp;
Your Query String is: myvar=1yourvar=2
When the browser sends this request to tomcat (which is also acting as a
webserver - no apache is running), does it put everything after the ? into
the QUERY_STRING HTTP variable, or does it include it in the URL request?
It parses the GET request into the two components listed above.

I have a filter in place that will replace /variable/ with variable= to
allow for proper processing of variables.  Here is what I observe :
If I have a URL of :
mysite.com/myservlet.jsp/myvar/1/yourvar/2
then it will properly translate this into :
mysite.com/myservlet.jsp?myvar=1yourvar=2
and everything works.
Looks good.

However, we have a new requirement that we want to keep ?myvar=1 as part
of the original URL, so the incoming request would look like this :
mysite.com/myservlet.jsp?myvar=1/yourvar/2
Your URL is: http://www.mysite.com/myservlet.jsp;
Your Query String is: myvar=1/yourvar/2
AND

request.getParameter(myvar) == 1/yourvar/2

and, naturally, we want it translated into
mysite.com/myservlet.jsp?myvar=1yourvar=2
but this does NOT happen.  Instead, it seems like the filter is doing
nothing.
The only explanation I can think of is that, now that the ? is in the
original request URL, the browser is taking everthing after it, stripping
it out of the request URL, and putting it into the QUERY_STRING variable -
so that the filter doesn't see it.  The filter would only see
mysite.com/myservlet.jsp
and would not perform any translation.
This is exactly what's happening.  If you want to inspect the entire GET 
request, you need to reconstruct the entire GET request by doing 
something like this (pseudo code):

StringBuffer sb = request.getRequestURL();
sb.append(/);
parse request.getQueryString() into name=value pairs and name/value pairs
for each pair
if pair is name=value, convert each name=value pair into a 
name/value pair
sb.append(name/value pair)

Or whatever, depending on what you need.

Hope that clears up any confusion.  Again, I hope -- for your own sake -- 
you have a *really* good reason for complicating this relatively simple 
process.  ;)

justin

__
Justin Ruthenbeck
Software Engineer, NextEngine Inc.
justinr - AT - nextengine DOT com
Confidential. See:
http://www.nextengine.com/confidentiality.php
__
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]