Mark,

I attempted to do what you prescribed but I am running into a snag and
can't figure out what I've done incorrectly.

I have a context, we'll call it /foo

In my ROOT web application (/) I created a servlet with a mapping of /foo/*
like so:
<servlet>
  <servlet-name>foo-404-change</servlet-name>

<servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
  <servlet-name>foo-404-change</servlet-name>
  <url-pattern>/foo/*</url-pattern>
</servlet-mapping>

The above configuration loads fine (servlet starts up no problem).

I've created a simple JSP to respond with a 503.  We'll call it
change-status.jsp.  If I call this page, it works fine.  However, when I
stop the context /foo, and attempt to reach /foo/whatever, I still get a
404 as if my servlet isn't even trying to handle the request.

I thought maybe I needed to specify an error page so that ROOT would know
what to do with a 404, so I setup the following in the ROOT web app's
web.xml:
<error-page>
  <error-code>404</error-code>
  <location>/change-status.jsp</location>
</error-page>

If I go to http://myserver:8080/not-a-real-page"; the 404 triggers the
location specified, and my JSP correctly returns a blank page with an HTTP
status of 503.

If I go to http://myserver:8080/foo/not-a-real-page"; while the context /foo
is running, I get a 404 as expected.

If I go to http://myserver:8080/foo/some-other-fake-page"; while the
context /foo is stopped, I still just get a 404.

I'm not sure where to go from here, and would greatly appreciate any ideas
you (or anyone else) have.

Thanks,
Kyle Harper




From:   Mark Thomas <ma...@apache.org>
To:     Tomcat Users List <users@tomcat.apache.org>
Date:   06/14/2012 03:19 PM
Subject:        Re: Modify HTTP status returned by stopped context



On 14/06/2012 20:37, kharp...@oreillyauto.com wrote:
>
> Hello,
>
> I am running multiple web applications on a tomcat server.  When a
request
> to a context in the stopped state is made, tomcat is returning 404 "not
> found" rather than 503 "unavailable".  Is it possible to change this
> behavior in any way?  Obviously I can't just modify _all_ HTTP 404
> responses to 503.  Just those which are coming from a context in the
> stopped state.

Assume the context in question is /foo

In the ROOT web application add a servlet with a mapping of /foo/*

The servlet should just return a 503 (or any other error code)

This works because the mapping rules require the longest match to the
context be considered first. While /foo is running, requests will be
mapped to the /foo context and the servlet in the ROOT web application
is ignored. When /foo is not running, the request is mapped to the
servlet in the ROOT web app.

This obviously won't work for stopping the ROOT web app.

HTH,

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.



This communication and any attachments are confidential, protected by 
Communications Privacy Act 18 USCS ยง 2510, solely for the use of the intended 
recipient, and may contain legally privileged material. If you are not the 
intended recipient, please return or destroy it immediately. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to