Chuck,
I just got try it today and here is what happened:
I made this class:
public class StaticContentServlet extends
org.apache.catalina.servlets.DefaultServlet {
protected String getRelativePath(HttpServletRequest request) {
// Are we being processed by a RequestDispatcher.include()?
if
(request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR) != null) {
String result =
(String)request.getAttribute(Globals.INCLUDE_PATH_INFO_ATTR);
if (result == null) {
result =
(String)request.getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
}
if (result == null || result.equals("")) result = "/";
return result;
}
// No, extract the desired path directly from the request.
String result = request.getPathInfo();
if (result == null) {
result = request.getServletPath();
} else {
result = request.getServletPath() + result;
}
if (result == null || result.equals("")) result = "/";
return result;
}
}
I added it to my web.xml file:
<servlet>
<servlet-name>docs</servlet-name>
<servlet-class>opendap.coreServlet.StaticContentServlet</
servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>docs</servlet-name>
<url-pattern>/docs</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>docs</servlet-name>
<url-pattern>/docs/*</url-pattern>
</servlet-mapping>
and when I try to hit it I get this:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
java.lang.ClassCastException:
org.apache.naming.resources.ProxyDirContext
org.apache.catalina.servlets.DefaultServlet.init(DefaultServlet.java:
256)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org
.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
563)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
263)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
844)
org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:584)
org.apache.tomcat.util.net.JIoEndpoint
$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:613)
note The full stack trace of the root cause is available in the Apache
Tomcat/6.0.14 logs.
And in my debugger it looks like the getRelativePath() never gets
called. It dies long before that.
Any ideas?
N
On Jan 17, 2009, at 9:13 AM, Caldarale, Charles R wrote:
From: Nathan Potter [mailto:n...@opendap.org]
Subject: Re: Tomcat returns HTTP status of 200 when
HttpServletResponse.sendError() called.
My guess is I have fouled up the servlet mapping...
It looks o.k. to me (other than the aforementioned /docs mapping),
but this discussion does trigger a memory: as currently coded, the
DefaultServlet doesn't take into account the <servlet-mapping> used
to invoke it. It assumes its references start at the base of the
webapp, rather than some number of directories deeper. I think the
code at lines 299 - 302 (6.0.18 level) in the getRelativePath()
method of DefaultServlet should really be:
String result = request.getPathInfo();
if (result == null) {
result = request.getServletPath();
} else {
result = request.getServletPath() + result;
}
Turn on debugging in the DefaultServlet <init-param> to verify
that's what's happening.
You could try implementing your own class that extends
DefaultServlet and overrides only the getRelativePath() method with
the above modification to see what happens. Here's the complete -
but untested - code for the suggested revised method:
protected String getRelativePath(HttpServletRequest request) {
// Are we being processed by a RequestDispatcher.include()?
if (request.getAttribute(Globals.INCLUDE_REQUEST_URI_ATTR) !=
null) {
String result =
(String)request.getAttribute(Globals.INCLUDE_PATH_INFO_ATTR);
if (result == null) {
result =
(String)request.getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR);
}
if (result == null || result.equals("")) result = "/";
return result;
}
// No, extract the desired path directly from the request.
String result = request.getPathInfo();
if (result == null) {
result = request.getServletPath();
} else {
result = request.getServletPath() + result;
}
if (result == null || result.equals("")) result = "/";
return result;
}
There are no explicit constuctors for DefaultServlet, so you won't
need any either.
- Chuck
THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE
PROPRIETARY MATERIAL and is thus for use only by the intended
recipient. If you received this in error, please contact the sender
and delete the e-mail and its attachments from all computers.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
= = =
Nathan Potter ndp at opendap.org
OPeNDAP, Inc. 541.752.1852
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org