wood burning stoves 2.0*
The moose likes Web Services and the fly likes Using REST, How to Put Error 404 and Error 500 in HTTP Header? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Using REST, How to Put Error 404 and Error 500 in HTTP Header?" Watch "Using REST, How to Put Error 404 and Error 500 in HTTP Header?" New topic
Author

Using REST, How to Put Error 404 and Error 500 in HTTP Header?

Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
I am working on an application that requires me construct Error 404 and Error 500 manually. My application is client application --> Core --> Wrapper --> Adaptor --> database. All the communications between the Core and the Wrapper and between the Wrapper and Adapter use REST. And I am working on the Wrapper module.

When the Wrapper contacts the Adaptor to request for some data, if resource-not-found encountered, I am supposed to put 404 status code in the HTTP header and return it to the "core". All other exception internal to the Wrapper, I am supposed to put 500 status code in the HTTP header.

Would you guide me as to how to construct the code please?

For example, I think that I can do something like: ex.getCause(); But, how do I know it is resource-not-found so that I can construct the header and put 404 there? Thank you very much.

Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

Have an Interceptor on wrapper which will analyze the exception thrown by the service & will send 500/400/404 or any other required Http Response Code.
Natalie Kopple
Ranch Hand

Joined: May 06, 2003
Posts: 325
What is an Interceptor. How to use the Interceptor to analyze the exception thrown? Please help. Thank you.
Anurag Verma
Ranch Hand

Joined: Mar 30, 2012
Posts: 124

Interception is a concept using which you can execute some code before/after or around your actual service implementation. Implementation of Interceptors & how to use them is specific to the library that you are using to implement your web-services. Look this into the documentation of the library that you are using. I am known to apache CXF, & for that i can give reference as - http://cxf.apache.org/docs/interceptors.html
 
Don't get me started about those stupid light bulbs.
 
subject: Using REST, How to Put Error 404 and Error 500 in HTTP Header?
 
Similar Threads
Exception Handling - Construct Error 404 and Error 500 Manually
Problem while Deploy web service
Tiles in JSF
HTTP Status 404 -
Not able to run servlet program in weblogic