Misha

Not sure about behaviour on other implementations, we've only ever used the Felix Jetty one.

In one of our handlers we have the following code:

diag.debug("** auth GET, context path = " + request.getContextPath()
                    + ", servlet path : " + request.getServletPath()
                    + ", path info: " + request.getPathInfo()
                    + ", auth reason: " + reason
                    );

Which produces the following output:

   10-11-05 08:09:31 DEBUG - ** auth GET, context path = , servlet path
   : /VtWebUi/cafeauth, path info: /auth, auth reason: null

So maybe getPathInfo can help?

In our example, the full path requested being http://localhost:8084/VtWebUi/cafeauth/auth, with the servlet being mounted at http://localhost:8084/VtWebUi/cafeauth

According to my reading of the normal Http spec I think this is correct:


         getServletPath

   public java.lang.String*getServletPath*()

   Returns the part of this request's URL that calls the servlet. This
   includes either the servlet name or a path to the servlet, but does
   not include any extra path information or a query string.


         getPathInfo

   public java.lang.String*getPathInfo*()

   Returns any extra path information associated with the URL the
   client sent when it made this request. The extra path information
   follows the servlet path but precedes the query string.


These calls are actually just redirected to the underlying Jetty implementation, which I think is quite widely used - so I suspect there coding is probably correct. So maybe it's more a difference in how "servlet path" is interpreted for servlets registered using OSGi calls.

-- Rob

On 05/11/2010 4:04 AM, misha680 wrote:
Dear All:

Sorry for bothering. We use HttpServletRequest.getServletPath() in OpenMRS,
and I have noticed a difference in behavior between HTTP Service (both Felix
and Equinox) and Jetty, and was wondering if there was some explanation for
this.

My apologies if I am missing something simple. Here are two versions:

1) Jetty version:

http://old.nabble.com/file/p30137615/my-webapp.zip my-webapp.zip

Request: http://localhost:9999/my-webapp/index.htm
Result of getServletPath: [/index.htm]

2) Felix version (exact same servlet):

http://old.nabble.com/file/p30137615/test.zip test.zip

Request: http://localhost:8080/hello/index.htm
Result of getServletPath: [/hello]

Here is the servlet:
http://old.nabble.com/file/p30137615/HelloWorld.java HelloWorld.java

and the web.xml:
http://old.nabble.com/file/p30137615/web.xml web.xml

for the Jetty version.

Fyi, per Servlet 2.1 API spec:
http://download.oracle.com/docs/cd/E17802_01/products/products/servlet/2.1/api/javax.servlet.http.HttpServletRequest.html#getServletPath()

"public abstract String getServletPath()
Gets the part of this request's URI that refers to the servlet being
invoked. Analogous to the CGI variable SCRIPT_NAME."

and, e.g.,
http://www.perlfect.com/articles/cgi_env.shtml

"SCRIPT_NAME

The virtual path from which the script is executed.
This is very useful if your script will output html code that contains calls
to itself. Having the script determin its virtual path, (and hence, along
with DOCUMENT_ROOT, its full URL) is much more portable than hard coding it
in a configuration variable. Also, if you like to keep a log of all script
accesses in some file, and want to have each script report its name along
with the calling parameters or time, it is very portable to use SCRIPT_NAME
to print the path of the script."

The Jetty behavior seems correct even for Servlet API 2.1. However, clearly
both Felix and Equinox chose to implement this differently from the Jetty
HTTP Server.

Am I missing something?

More importantly, where would I get the relevant string (i.e. /index.htm)
from the Felix and/or Equinox implementations of HttpServletRequest?

Thank you
Yours
Misha

p.s. The relevant OpenMRS controller:

http://source.openmrs.org/browse/~raw,r=16192/OpenMRS/trunk/web/src/main/java/org/openmrs/web/controller/patient/ShortPatientFormValidator.java

--


Ascert - Taking systems to the Edge
[email protected]
+44 (0)20 7488 3470
www.ascert.com

Reply via email to