RE: Directory returning 500 instead of 404 for missing files
Hi Tal, Thanks for providing this test class. This wasn't the intended behavior and this is now fixed in SVN trunk. The change was done in UniformResource#doCatch() method, which can be overridden as a workaround if necessary. Best regards, Jerome Louvel -- Restlet ~ Founder and Technical Lead ~ http://www.restlet.org Noelios Technologies ~ http://www.noelios.com -Message d'origine- De : Tal Liron [mailto:tal.li...@threecrickets.com] Envoyé : mercredi 17 février 2010 05:17 À : discuss@restlet.tigris.org Objet : Re: Directory returning 500 instead of 404 for missing files Ah! Further digging showed me that what happened was that the behavior of catching thrown ResourceExceptions from a ServerResource has changed. Now, if the exception has a cause, then the error always becomes 500. This was not previously the case... If this is planned behavior, great, but just wanted to be sure. Here is a test case that returns a 500 error: public class Test { public static class MyResource extends ServerResource { @Override public Representation get() throws ResourceException { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND, new IOException( This turns into a 500 error ) ); // The following works as I expected: //throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); } } public static void main( String arguments[] ) throws Exception { Component component = new Component(); try { component.getServers().add( Protocol.HTTP, 8080 ); Application application = new Application(); component.getDefaultHost().attach( application ); component.getInternalRouter().attach( /myapp, application ).setMatchingMode( Template.MODE_STARTS_WITH ); Router router = new Router( application.getContext() ); application.setInboundRoot( router ); router.attach( /test/, MyResource.class ).setMatchingMode( Template.MODE_STARTS_WITH ); component.start(); ClientResource client = new ClientResource( component.getContext(), riap://component/myapp/test/ ); // ClientResource client = new ClientResource( // http://localhost:8080/test/; ); System.out.println( GET: + client.get() ); } catch( ResourceException x ) { System.out.println( x.getStatus() ); } catch( Exception x ) { x.printStackTrace(); } finally { System.exit( 0 ); } } } On 02/16/2010 01:37 AM, Thierry Boileau wrote: Hello Tal, using a ClientResource, I get a ResourceException when the response is not successful, and both the ResourceException and the response's statuses are equals to 404. Using a simple Client instance, the status of the response object is set to 404 also. Could you explain a little bit more what happens in your case? -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=24482 33 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2464770
Re: Directory returning 500 instead of 404 for missing files
Ah! Further digging showed me that what happened was that the behavior of catching thrown ResourceExceptions from a ServerResource has changed. Now, if the exception has a cause, then the error always becomes 500. This was not previously the case... If this is planned behavior, great, but just wanted to be sure. Here is a test case that returns a 500 error: public class Test { public static class MyResource extends ServerResource { @Override public Representation get() throws ResourceException { throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND, new IOException( This turns into a 500 error ) ); // The following works as I expected: //throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND ); } } public static void main( String arguments[] ) throws Exception { Component component = new Component(); try { component.getServers().add( Protocol.HTTP, 8080 ); Application application = new Application(); component.getDefaultHost().attach( application ); component.getInternalRouter().attach( /myapp, application ).setMatchingMode( Template.MODE_STARTS_WITH ); Router router = new Router( application.getContext() ); application.setInboundRoot( router ); router.attach( /test/, MyResource.class ).setMatchingMode( Template.MODE_STARTS_WITH ); component.start(); ClientResource client = new ClientResource( component.getContext(), riap://component/myapp/test/ ); // ClientResource client = new ClientResource( // http://localhost:8080/test/; ); System.out.println( GET: + client.get() ); } catch( ResourceException x ) { System.out.println( x.getStatus() ); } catch( Exception x ) { x.printStackTrace(); } finally { System.exit( 0 ); } } } On 02/16/2010 01:37 AM, Thierry Boileau wrote: Hello Tal, using a ClientResource, I get a ResourceException when the response is not successful, and both the ResourceException and the response's statuses are equals to 404. Using a simple Client instance, the status of the response object is set to 404 also. Could you explain a little bit more what happens in your case? -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2448233
Directory returning 500 instead of 404 for missing files
This seems to be true of revision 6132. Is this intentional, or a regression bug? -Tal -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2447935
Re: Directory returning 500 instead of 404 for missing files
It seems to me that what's going on is that thrown ResourceExceptions are not getting their Status set to the Response. On 02/15/2010 05:58 PM, Tal Liron wrote: This seems to be true of revision 6132. Is this intentional, or a regression bug? -Tal -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2447956
Re: Directory returning 500 instead of 404 for missing files
Hello Tal, using a ClientResource, I get a ResourceException when the response is not successful, and both the ResourceException and the response's statuses are equals to 404. Using a simple Client instance, the status of the response object is set to 404 also. Could you explain a little bit more what happens in your case? Best regards, Thierry Boileau It seems to me that what's going on is that thrown ResourceExceptions are not getting their Status set to the Response. On 02/15/2010 05:58 PM, Tal Liron wrote: This seems to be true of revision 6132. Is this intentional, or a regression bug? -Tal -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2447956 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2447978