[ 
https://issues.apache.org/struts/browse/WW-2515?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=43419#action_43419
 ] 

Sarat Pediredla commented on WW-2515:
-------------------------------------

I agree with your comments. I think this is a tricky one overall. In RoR (in 
production mode), as far as I can remember, a missing controller raises a 404. 

I also agree that maybe the ContenTypeInterceptor is not the right place to 
throw the 404. Maybe the patch was hasty and in reconsideration I dont entirely 
like the way it closes the response. Could you please remove the current patch?

Maybe the best way is to define a ResourceNotFound exception that gets thrown 
by an action (after all, the action is best placed to know whether the resource 
exists or not) and then trap this in the plugin and convert it into HTTP Status 
Code 404? Likewise, with MethodNotSupported? Currently, I am sure an 
IllegalArgumentException gets thrown instead of a status code when in REST mode.

If this is agreeable, I will create another patch for that solution.

> REST plugin does not throw a 404 if resource cannot be found
> ------------------------------------------------------------
>
>                 Key: WW-2515
>                 URL: https://issues.apache.org/struts/browse/WW-2515
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - REST
>    Affects Versions: 2.1.1
>         Environment: Struts 2.1.1-SNAPSHOT using Jetty 6.1.5
>            Reporter: Sarat Pediredla
>         Attachments: WW-2515.patch
>
>
> When there is a GET request for a resource that does not exist, example GET 
> /authors/25 where author with id 25 does not exist, the getModel() method of 
> the action should return null (and in most cases will return null as the 
> object does not exist).
> However, the current ContentTypeInterceptor implementation is not entirely 
> RESTful as the right response should be HTTP Status Code 404 "Not Found".
> I have patched the ContentTypeInterceptor to return a 404 status if the 
> requested resource could not be found.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to