users@jersey.java.net

[Jersey] Re: Is Jersey/REST good for the following?

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 01 Nov 2011 16:46:46 +0100

Hi John,

You can stick with your original error codes to get detailed error
information out
and only use the HTTP codes for sort of a higher level status information,
i.e. 2xx->all right, 4xx -> client error, 5xx-> server error, etc.
Where appropriate (especially 4xx, 5xx, and maybe also somewhere else),
you simply wrap your original resulting XML to a response with a
corresponding
HTTP status code.

To do this with Jersey, you may want to utilize the response builder class.
See [1] for more detailed information.

~Jakub

[1]http://jersey.java.net/nonav/apidocs/latest/jersey/javax/ws/rs/core/Response.ResponseBuilder.html


On 1.11.2011 16:08, John Smith wrote:
> I have an old lightweight message oriented web service pre "WS/SOAP"
> buz. It pretty much receives value/pair or XML over HTTP(s) POST does
> something with the XML (Insert to Database, Communicate to 3rd party
> etc...) and returns a response value/pair or XML response to the client.
>
> I'm currently looking to update this service to keep up with
> technology and make it more standard.
>
> The old service uses POST pretty much for anything but it works. You
> just POST the required XML or value/pairs to it and it does what it
> needs and replies back appropriately.
>
> So REST seems more suited here then say a heavy SOAP service.
>
> Now the issue I'm having is trying to standardize the old way with the
> new way.
>
> The old service always processes POST and always returns HTTP 200 OK
> and the client parses the XML response to get a "status" code
>
> So for instance if the service executed correctly it will return
> <code>100</code><message>Approved</message>
> If for example there is something wrong with the request then it will
> return <code>900</code><message>Phone Number Submitted Invalid</message>
>
> But looking at REST in general I need to start mapping my codes to
> HTTP ones, but I have 100s of codes. I can have various success codes
> based on the business logic executed etc... Or various failure codes.
> So I cannot just simply map all success under HTTP 200 and all
> failures under HTTP 500 or what ever it is... Or is there a way to
> return HTTP 200 and a subcode or something? Or for isnatnce 400 Bad
> Request but I would need to tell the client exactly what the Bad
> Request is.
>