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:[email protected]] 
Envoyé : mercredi 17 février 2010 05:17
À : [email protected]
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=4447&dsMessageId=24482
33

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2464770

Reply via email to