users@jersey.java.net

[Jersey] Re: 2 questions

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 30 Dec 2010 13:49:07 +0100

On Dec 29, 2010, at 3:53 PM, Cédric Marcone wrote:
> Hello all.
>
> First of all kudos to Jersey developers, to Jax-RS JCP members and
> to all the JEE6 actors.
>
> You're doing a wonderful job at providing a breakthrough JEE web
> development platform that finally let us use a modern REST MVC
> approach without having to resort on using tons of additional
> libraries.
>

Thanks!


> We are trying hard, as users of the platform, to limit ourselves to
> only use platform components.
>
> At the Jersey/Jax-RS level, we only have two issues preventing us to
> get to the web developers heaven :
>
> 1) Jersey is a superset of Jax-RS
>
> The full MVC model provided by Jersey (Templates integration using
> Viewables) is not part of current Jax-RS.
> Does anyone know if there is a desire to integrate an similar API at
> the Jax-RS level for JEE7 ?
>

Yes, it is in scope for JAX-RS 2.0.

If you don't want to depend on Jersey you can in the interim copy the
relevant code into your code base and maintain it. The only area that
requires some specific Jersey integration is support for implicit
views. So if you are happy with support for explicit views the
functionality can be implemented using MessageBodyWriter.



> 2) Mapping of empty strings to non String parameters
>
> As I've read many discussions about it, I know others raised this
> issue before.
> I understand the jersey team position regarding the choices that
> were made.
> I understand the risks of regressions such a change could lead to.
> I read somewhere that a global flag could be introduced to change
> this default behavior.
> What is the status of this issue ?
>

No status as of yet. I think from a Jersey perspective an annotation
should be supported @NullOnEmptyString.

For a global flag all we need to do is support a filter that removes
all parameters (form or query) for parameters names with no value (or
perhaps more specifically for parameter names with an empty value e.g.
"x=" rather than just "x".

The latter can be implemented by anyone using a
ContainerRequestFilter. The former requires some changes to Jersey.

Paul.


> The following example says it all :
>
> ---------------------------------------------------------------------------------
>
> import com.sun.jersey.api.view.Viewable;
> import javax.ws.rs.FormParam;
> import javax.ws.rs.POST;
> import javax.ws.rs.Path;
> import javax.ws.rs.Produces;
>
> @Path("/test")
> @Produces("text/html")
> public class Test {
>
> /**
> * Current recommended way of handling empty non-string parameters
> */
> @POST
> @Path("/asString")
> public Viewable testAsString(@FormParam("value") String value) {
>
> Integer iValue = null;
>
> if (value != null && !value.isEmpty()) {
> try {
> iValue = Integer.valueOf(value);
> }
> catch (NumberFormatException exception) {}
> }
>
> return new Viewable("/test.xhtml", iValue);
> }
>
> /**
> * Produces a status 400, seems more than correct.
> */
> @POST
> @Path("/asInt")
> public Viewable testAsInt(@FormParam("value") int value) {
>
> return new Viewable("/test.xhtml", value);
> }
>
> /**
> * Should not produce a status 400, but a null parameter
> */
> @POST
> @Path("/asInteger")
> public Viewable testAsInteger(@FormParam("value") Integer value) {
>
> return new Viewable("/test.xhtml", value);
> }
> }
>
> ----------------------------------------------------------------------------------
>
> Thank you,
> --
> Cédric Marcone
> Valraiso
> France
>
>