You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Emmanuel Franquemagne <em...@kelkoo.com> on 2015/03/10 17:41:46 UTC

Is it possible to make Tomcat 6.0.24 to return 50x code when webapp not started?

Hello,

Here is the description of my problem: I have a REST webservice hosted in a tomcat instance and which is accessed by automated processes; these processes request information about business objects and take decision accordingly.
Especially, when business object isn't available, the webservice returns http code 404.

Our problem is that Tomcat also returns 404 when the webservice isn't started. It is fine from Tomcat point of view, but not from client application pov: in this context, it is "normal" to get a "resource not found" which has an applicative meaning, but from client side point of view, down webapp is a internal ws error, and should be returned 50x code (500, 501, 503...). And client must make difference between "business object unknown" and "application unavailable".

So my question is: is it possible to force Tomcat to return *50x* code if a webapp it hosts is not started (or crashed or so), and let *applicative 404* go to client? I've searched the Web to see if other REST webapp developers had this issue, but found nothing. I may also have misread tomcat manuel, but didn't find an answer to my question.

My Tomcat version is 6.0.24

Thanks is advance,
Emmanuel

Kelkoo SAS
Société par Actions Simplifiée
Au capital de € 4.168.964,30
Siège social : 158 Ter Rue du Temple 75003 Paris
425 093 069 RCS Paris

Ce message et les pièces jointes sont confidentiels et établis à l'attention exclusive de leurs destinataires. Si vous n'êtes pas le destinataire de ce message, merci de le détruire et d'en avertir l'expéditeur.

Re: Is it possible to make Tomcat 6.0.24 to return 50x code when webapp not started?

Posted by Mark Thomas <ma...@apache.org>.
On 10/03/2015 16:41, Emmanuel Franquemagne wrote:
> Hello,
> 
> Here is the description of my problem: I have a REST webservice
> hosted in a tomcat instance and which is accessed by automated
> processes; these processes request information about business objects
> and take decision accordingly. Especially, when business object isn't
> available, the webservice returns http code 404.
> 
> Our problem is that Tomcat also returns 404 when the webservice isn't
> started. It is fine from Tomcat point of view, but not from client
> application pov: in this context, it is "normal" to get a "resource
> not found" which has an applicative meaning, but from client side
> point of view, down webapp is a internal ws error, and should be
> returned 50x code (500, 501, 503...). And client must make difference
> between "business object unknown" and "application unavailable".
> 
> So my question is: is it possible to force Tomcat to return *50x*
> code if a webapp it hosts is not started (or crashed or so), and let
> *applicative 404* go to client? I've searched the Web to see if other
> REST webapp developers had this issue, but found nothing. I may also
> have misread tomcat manuel, but didn't find an answer to my
> question.

It you want Tomcat to return something other than a 404 for a resource
that doesn't exist you'll need to deploy something to do that. The
simplest way may be to deploy a servlet to the ROOT web app mapped to
/yourapp that returns a 503.

If a context is deployed to /yourapp the Servlet mapping rules mean any
requests will go to that app, not the ROOT app. If no context is
deployed to /yourapp, the requests go to ROOT which will return the 503
(or whatever).

Mark

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