users@jersey.java.net

Re: [Jersey] Response or void or String ??

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 05 May 2009 22:08:30 +0200

On May 5, 2009, at 7:52 PM, Felipe Gaścho wrote:

> Now I have three choices for my methods with return type void:
>
> ---------- option #1: do nothing..
> @DELETE
> @Path("/delete/{id}")
> public void delete(@PathParam("id") String id) throws ... {
> FpEvent event = eventFacade.read(Long.valueOf(id));
> eventFacade.delete(event);
> }
>
> ---------- option #2: return a String..
> @DELETE
> @Path("/delete/{id}")
> public String delete(@PathParam("id") String id) throws ... {
> FpEvent event = eventFacade.read(Long.valueOf(id));
> eventFacade.delete(event);
> return "what is the benefit?";
> }

> ---------- option #2: use a void response ?
>
> private static final Response VOID_RESPONSE =
> Response.noContent().build();
>
> @DELETE
> @Path("/delete/{id}")
> public Response delete(@PathParam("id") String id) throws ... {
> FpEvent event = eventFacade.read(Long.valueOf(id));
> eventFacade.delete(event);
>
> return VOID_RESPONSE;
> }
>

The above option is equivalent to option 1, that is what Jersey does
when a method returns void.

My preference is to utilize option 1 unless i need to return something
other than a 204 response. It is the most concise.

Paul.

> ---------- option #4: any better choice ?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>