Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
Chuck, I got the same error with your version. Which got me thinking. So removed all of my webapp files and tried a again with a fresh war file and now they both work. Thanks! Nathan On Jan 29, 2009, at 8:27 PM, Caldarale, Charles R wrote: From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. Sorry for not responding earlier, things have been a little hectic this week. I just got try it today and here is what happened: I just tried the same thing, with no problems. I made this class: I don't see a package clause in your code, nor are the imports shown. Here's the entire code I used, including the poor man's logger, System.out: package mypackage; import javax.servlet.http.HttpServletRequest; import org.apache.catalina.Globals; 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 = /; System.out.println(StaticContentServlet returning + 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 = /; System.out.println(StaticContentServlet returning + result); return result; } } I added it to my web.xml file: Mine is almost the same, with the addition of a listings param: servlet servlet-namedocs/servlet-name servlet-classmypackage.StaticContentServlet/servlet-class init-param param-namelistings/param-name param-valuetrue/param-value /init-param load-on-startup1/load-on-startup /servlet just so the /docs mapping would do something useful. (The servlet mappings are identical to yours.) Referencing the URLs: http://localhost:8080/sample/docs http://localhost:8080/sample/docs/test.txt got me this result in stdout: StaticContentServlet returning /docs StaticContentServlet returning /docs/test.txt and the expected directory listings and the text file contents in the browser window. - 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 Potterndp 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
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. Sorry for not responding earlier, things have been a little hectic this week. I just got try it today and here is what happened: I just tried the same thing, with no problems. I made this class: I don't see a package clause in your code, nor are the imports shown. Here's the entire code I used, including the poor man's logger, System.out: package mypackage; import javax.servlet.http.HttpServletRequest; import org.apache.catalina.Globals; 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 = /; System.out.println(StaticContentServlet returning + 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 = /; System.out.println(StaticContentServlet returning + result); return result; } } I added it to my web.xml file: Mine is almost the same, with the addition of a listings param: servlet servlet-namedocs/servlet-name servlet-classmypackage.StaticContentServlet/servlet-class init-param param-namelistings/param-name param-valuetrue/param-value /init-param load-on-startup1/load-on-startup /servlet just so the /docs mapping would do something useful. (The servlet mappings are identical to yours.) Referencing the URLs: http://localhost:8080/sample/docs http://localhost:8080/sample/docs/test.txt got me this result in stdout: StaticContentServlet returning /docs StaticContentServlet returning /docs/test.txt and the expected directory listings and the text file contents in the browser window. - 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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
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-namedocs/servlet-name servlet-classopendap.coreServlet.StaticContentServlet/ servlet-class load-on-startup1/load-on-startup /servlet servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/url-pattern /servlet-mapping servlet-mapping servlet-namedocs/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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
Chuck, Answers inline and below. On Jan 16, 2009, at 8:20 PM, Caldarale, Charles R wrote: The above mapping is not useful; since it contains no wildcards, it can only be used as an exact match for the directory, and you've disabled directory listings. Oops. My fault. In my web.xml it simply doesn't work. Are you seeing errors in the logs? No. What are you trying that doesn't work? What errors are you seeing? It appears that no servlet is associated with /docs or /docs/*. What leads you to that conclusion? Lack of responses. Interestingly my IDE can't seem to find the class Take the IDE out of the picture - run Tomcat by itself and see what happens. That's what I've been doing. I only mentioned the IDE because I thought it strange that it couldn't find the class. I turned on listings and now I am getting a response, but unexpected behavior. My guess is I have fouled up the servlet mapping... The context is opendap, and there are three servlets: servlet servlet-namehyrax/servlet-name servlet-classopendap.coreServlet.DispatchServlet/servlet- class load-on-startup1/load-on-startup /servlet servlet servlet-namedocs/servlet-name servlet-classorg.apache.catalina.servlets.DefaultServlet/ servlet-class init-param param-namedebug/param-name param-value0/param-value /init-param init-param param-namelistings/param-name param-valuetrue/param-value /init-param load-on-startup1/load-on-startup /servlet servlet servlet-nametest/servlet-name servlet-classopendap.experiments.SendErrorTest/servlet- class load-on-startup1/load-on-startup /servlet With these mappings: servlet-mapping servlet-nametest/servlet-name url-pattern/test/url-pattern /servlet-mapping servlet-mapping servlet-nametest/servlet-name url-pattern/test/*/url-pattern /servlet-mapping servlet-mapping servlet-namehyrax/servlet-name url-pattern/hyrax/url-pattern /servlet-mapping servlet-mapping servlet-namehyrax/servlet-name url-pattern/hyrax/*/url-pattern /servlet-mapping servlet-mapping servlet-namehyrax/servlet-name url-pattern*/url-pattern /servlet-mapping servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/url-pattern /servlet-mapping servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/*/url-pattern /servlet-mapping When I go to: http://localhost:8080/opendap/docs I get an empty listing. When I go to: http://localhost:8080/opendap/docs/ I get a listing of the directory $CATALINA_HOME/webapps/opendap/ (minus the WEB-INF and META-INF directories as expected). The links on the page appear to be correct: docs/ http://localhost:8080/opendap/docs/ initialContent/ http://localhost:8080/opendap/initialContent/ javadocs/ http://localhost:8080/opendap/javadocs/ olfs_libraries/ http://localhost:8080/opendap/olfs_libraries/ views/http://localhost:8080/opendap/views/ When I try clicking on the docs/ link I (not surprisingly) get the same page back. When I try clicking on the other links I get empty page responses sent with a 404 HTTP status. Again, not surprising since the Default Servlet isn't getting correctly mapped. If I remove the error-page mapping: error-page error-code404/error-code location/docs/error404.html/location /error-page Then when I try to access initialContent/, javadocs/, etc. I get the default 404 response. Can you see the configuration issue? Thanks, Nathan Here is the complete web.xml: ?xml version=1.0 encoding=ISO-8859-1? !DOCTYPE web-app PUBLIC -//Sun Microsystems, Inc.//DTD Web Application 2.2//EN http://java.sun.com/j2ee/dtds/web-app_2_2.dtd; web-app display-nameHyrax/display-name descriptionOPeNDAP Hyrax Server/description context-param param-nameContextPath/param-name param-valueopendap/param-value /context-param servlet servlet-namehyrax/servlet-name servlet-classopendap.coreServlet.DispatchServlet/servlet- class init-param param-nameDebugOn/param-name param-value /param-value /init-param init-param param-nameOLFSConfigFileName/param-name param-valueolfs.xml/param-value /init-param load-on-startup1/load-on-startup /servlet servlet servlet-namedocs/servlet-name servlet-classorg.apache.catalina.servlets.DefaultServlet/ servlet-class init-param param-namedebug/param-name param-value0/param-value /init-param init-param
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
Chuck et. al, I tried the thing below, but Tomcat can't find the class: org.apache.catalina.servlets.DefaultServlet On this page of the Tomcat docs: http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html There is good infrormation but when I put this: servlet servlet-namedocs/servlet-name servlet-classorg.apache.catalina.servlets.DefaultServlet/ servlet-class init-param param-namedebug/param-name param-value0/param-value /init-param init-param param-namelistings/param-name param-valuefalse/param-value /init-param load-on-startup1/load-on-startup /servlet ... servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/url-pattern /servlet-mapping servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/*/url-pattern /servlet-mapping In my web.xml it simply doesn't work. It appears that no servlet is associated with /docs or /docs/*. Interestingly my IDE can't seem to find the class, although it is used in $CATALINA_HOME/conf/web.xml Is there something else I need to do? Include or copy a jar file from somewhere? Nathan On Jan 14, 2009, at 9:20 PM, Caldarale, Charles R wrote: From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. So do you mean something like this? servlet servlet-namedefault/servlet-name servlet-class org.apache.catalina.servlets.DefaultServlet /servlet-class load-on-startup1/load-on-startup /servlet servlet-mapping servlet-namedefault/servlet-name url-pattern/err/*/url-pattern /servlet-mapping Yes, but I think you're going to have to change the servlet-name value to something else so it doesn't conflict with the one in conf/ web.xml that's shared by all webapps. (It's been a while since I had to do this, but I seem to recall that was necessary to avoid ugly messages at startup.) And I place all of my default error pages in $CATALINA_HOME/webapps/myContext/err/ Yes. You could also use the same technique to have the DefaultServlet handle other static content if you want. - 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 Potterndp at opendap.org OPeNDAP, Inc.541.752.1852
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/url-pattern /servlet-mapping The above mapping is not useful; since it contains no wildcards, it can only be used as an exact match for the directory, and you've disabled directory listings. In my web.xml it simply doesn't work. Are you seeing errors in the logs? What are you trying that doesn't work? What errors are you seeing? It appears that no servlet is associated with /docs or /docs/*. What leads you to that conclusion? Interestingly my IDE can't seem to find the class Take the IDE out of the picture - run Tomcat by itself and see what happens. - 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
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. I mapped one of my servlets to be the default servlet: servlet-mapping servlet-namehyrax/servlet-name url-pattern*/url-pattern /servlet-mapping And since it doesn't serve static content like the Tomcat DefaultServlet, I'm not seeing the expected behavior for the error-page mappings. If you don't want to rewrite your mappings (and probably program logic), then isolate your static content - including error pages - to some particular branch of your directory tree and put in a mapping for the existing DefaultServlet to handle it. - 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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
On Jan 14, 2009, at 1:38 PM, Caldarale, Charles R wrote: From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. I mapped one of my servlets to be the default servlet: servlet-mapping servlet-namehyrax/servlet-name url-pattern*/url-pattern /servlet-mapping And since it doesn't serve static content like the Tomcat DefaultServlet, I'm not seeing the expected behavior for the error-page mappings. If you don't want to rewrite your mappings (and probably program logic), then isolate your static content - including error pages - to some particular branch of your directory tree and put in a mapping for the existing DefaultServlet to handle it. So do you mean something like this? servlet servlet-namedefault/servlet-name servlet-class org.apache.catalina.servlets.DefaultServlet /servlet-class load-on-startup1/load-on-startup /servlet ... servlet-mapping servlet-namedefault/servlet-name url-pattern/err/*/url-pattern /servlet-mapping And I place all of my default error pages in $CATALINA_HOME/webapps/ myContext/err/ - 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 Potterndp 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
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. So do you mean something like this? servlet servlet-namedefault/servlet-name servlet-class org.apache.catalina.servlets.DefaultServlet /servlet-class load-on-startup1/load-on-startup /servlet servlet-mapping servlet-namedefault/servlet-name url-pattern/err/*/url-pattern /servlet-mapping Yes, but I think you're going to have to change the servlet-name value to something else so it doesn't conflict with the one in conf/web.xml that's shared by all webapps. (It's been a while since I had to do this, but I seem to recall that was necessary to avoid ugly messages at startup.) And I place all of my default error pages in $CATALINA_HOME/webapps/myContext/err/ Yes. You could also use the same technique to have the DefaultServlet handle other static content if you want. - 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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
Nathan Potter wrote: I mapped one of my servlets to be the default servlet: servlet-mapping servlet-namehyrax/servlet-name url-pattern*/url-pattern /servlet-mapping And since it doesn't serve static content like the Tomcat DefaultServlet, I'm not seeing the expected behavior for the error-page mappings. Which is kind of a bummer: People pretty much rely on the fact that the service defaults to the hyrax servlet. Are there other servlets? If so, your app is relying on the 'longer matche is best' principal for those servlets, and defaulting to hyrax when nothing else matches. In this case you could create a a servlet that responds to url-pattern '/index.jsp' and redirects to hyrax. In fact, you could just put an additional mapping in with that url-pattern instead of * if the above applies. If this isn't suitable can you define the behaviour that your app needs in more detail? p - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. Tomcat returns the designated page, but with an HTTP status of 200. If I drop the default page then I get the canned response with an HTTP status of 404. Is that correct? Don't think so. Does your code happen to call response.setStatus(200) somewhere along the way? - 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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
On Jan 12, 2009, at 3:34 PM, Caldarale, Charles R wrote: Don't think so. Does your code happen to call response.setStatus(200) somewhere along the way? - Chuck Well at first I didn't think so, but now I am wondering After adding some more instrumentation I have determined that I am inadvertently setting the status to 200. I was replicating the problem with this servlet: package opendap.experiments; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; public class SendErrorTest extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { try { System.out.println(Calling HttpServletResponse.sendError(404)); response.sendError(HttpServletResponse.SC_NOT_FOUND); System.out.println(HttpServletResponse.sendError(404) returned.); } catch (Exception e) { System.out.println(e.getMessage()); } } } And a simple document service servlet: servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/*/url-pattern /servlet-mapping With this error-page: error-page error-code404/error-code location/docs/error404.html/location /error-page I added some instrumentation and looked at the logs and saw that when the sendError() method is called in the SendErrorTest servlet the call returns immediately. And is followed by a the docs servlet receiving a request for the error document, which since it is successfully returning a document sets the HTTP status to 200. Is sendError() using a redirect? Is there a way to set the value of the location element in the error- page declaration so that tomcat just grabs the file from the context directory? The java servlet spec (2.4) says: If the sendError method is called on the response, the container consults the list of error page declarations for the Web application that use the status-code syntax and attempts a match. If there is a match, the container returns the resource as indicated by the location entry. So what does the container returns the resource as indicated by the location entry mean for tomcat? Is there an example of a design pattern you can point me to? Thanks, Nathan = = = Nathan Potterndp 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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
On Mon, Jan 12, 2009 at 19:58, Nathan Potter n...@opendap.org wrote: On Jan 12, 2009, at 3:34 PM, Caldarale, Charles R wrote: Don't think so. Does your code happen to call response.setStatus(200) somewhere along the way? - Chuck Well at first I didn't think so, but now I am wondering After adding some more instrumentation I have determined that I am inadvertently setting the status to 200. I was replicating the problem with this servlet: package opendap.experiments; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletRequest; public class SendErrorTest extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) { try { System.out.println(Calling HttpServletResponse.sendError(404)); response.sendError(HttpServletResponse.SC_NOT_FOUND); System.out.println(HttpServletResponse.sendError(404) returned.); } catch (Exception e) { System.out.println(e.getMessage()); } } } And a simple document service servlet: servlet-mapping servlet-namedocs/servlet-name url-pattern/docs/*/url-pattern /servlet-mapping With this error-page: error-page error-code404/error-code location/docs/error404.html/location /error-page I added some instrumentation and looked at the logs and saw that when the sendError() method is called in the SendErrorTest servlet the call returns immediately. And is followed by a the docs servlet receiving a request for the error document, which since it is successfully returning a document sets the HTTP status to 200. Is sendError() using a redirect? Is there a way to set the value of the location element in the error-page declaration so that tomcat just grabs the file from the context directory? The java servlet spec (2.4) says: If the sendError method is called on the response, the container consults the list of error page declarations for the Web application that use the status-code syntax and attempts a match. If there is a match, the container returns the resource as indicated by the location entry. So what does the container returns the resource as indicated by the location entry mean for tomcat? Is there an example of a design pattern you can point me to? Thanks, Nathan It sounds like error404.html isn't a plain HTML file, but a page that's generated by a servlet. Is that right? If so, the servlet should not set the status to 200 for an error page - it should leave the error status alone. Maybe you need a different version of the servlet to handle error pages, or maybe your error pages should just be static HTML files. -- Len - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
On Jan 12, 2009, at 5:38 PM, Len Popp wrote: It sounds like error404.html isn't a plain HTML file, but a page that's generated by a servlet. Is that right? Yes. If so, the servlet should not set the status to 200 for an error page - it should leave the error status alone. I can see that. Maybe you need a different version of the servlet to handle error pages, That's waht I have been slowly getting to: Make an error handling servlet. or maybe your error pages should just be static HTML files. Well, they certainly could be. But how do I serve them without a servlet to do it? That was ultimately my question: How do I set the value of the location element in the error page declaration: error-page error-code404/error-code location/docs/error404.html/location /error-page So that tomcat will grab a static HTML page from disk? Let's say that the error document is here: $CATALINA_HOME/webapps/myContext/docs/error404.html Because it doesn't do it if I disable the servlet (and it's mappings) that hands our the docs, it just returns an empty document. Nathan -- Len - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org = = = Nathan Potterndp 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
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. Is sendError() using a redirect? No, more like an internal forward. Is there a way to set the value of the location element in the error-page declaration so that tomcat just grabs the file from the context directory? Yes - don't give it a URL pattern that matches the mapping for any of your servlets. So what does the container returns the resource as indicated by the location entry mean for tomcat? Haven't checked the code yet, but I believe it treats it like a GET for the resource, so it's subject to whatever servlet mapping you have in place. - 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
RE: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
From: Nathan Potter [mailto:n...@opendap.org] Subject: Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called. But how do I serve them without a servlet to do it? You don't have to serve them - Tomcat's DefaultServlet does it for you, just as it does for all static resources. How do I set the value of the location element in the error page declaration: So that tomcat will grab a static HTML page from disk? You normally would put static error pages in a separate directory, so that they will not be processed by any of your servlets. - 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
Re: Tomcat returns HTTP status of 200 when HttpServletResponse.sendError() called.
On Jan 12, 2009, at 6:08 PM, Caldarale, Charles R wrote: But how do I serve them without a servlet to do it? You don't have to serve them - Tomcat's DefaultServlet does it for you, just as it does for all static resources. How do I set the value of the location element in the error page declaration: So that tomcat will grab a static HTML page from disk? You normally would put static error pages in a separate directory, so that they will not be processed by any of your servlets. I see the conflict in my design now: I mapped one of my servlets to be the default servlet: servlet-mapping servlet-namehyrax/servlet-name url-pattern*/url-pattern /servlet-mapping And since it doesn't serve static content like the Tomcat DefaultServlet, I'm not seeing the expected behavior for the error- page mappings. Which is kind of a bummer: People pretty much rely on the fact that the service defaults to the hyrax servlet. Is sendError() using a redirect? No, more like an internal forward. I just did some more testing and discovered that if I don't actually call response.setStatus() in my docs servlet (which serves the static content) then it seems to inherit(?) a status from the internal forward . Is that right? Would I be better off just not calling response.setStatus() unless something actually goes awry with the request? = = = Nathan Potterndp 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