users@jersey.java.net

[Jersey] Validation a request using BV

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Tue, 09 Apr 2013 15:22:08 -0700

For a resource method:

     @POST
     @Produces(MediaType.TEXT_PLAIN)
     public String post(@Size(min = 3) String payload) {
         return payload;
     }

A request is sent as:

String r = target.request().post(Entity.text("fo"), String.class);

And server.log shows the following exception:

WARNING: StandardWrapperValve[TestServlet]: Servlet.service() for
servlet TestServlet threw exception
javax.ws.rs.BadRequestException: HTTP 400 Bad Request
     at
org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:883)
     at
org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:749)
     at
org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:88)
     at
org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:650)
     at org.glassfish.jersey.internal.Errors.process(Errors.java:275)
     at org.glassfish.jersey.internal.Errors.process(Errors.java:257)
     at org.glassfish.jersey.internal.Errors.process(Errors.java:188)
     at
org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:421)
     at
org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:646)
     at
org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:402)
     at
org.glassfish.jersey.client.JerseyInvocation$Builder.post(JerseyInvocation.java:305)

There is no ConstraintViolation exception thrown in the server log. How
do I know more details about this error ?

Arun

-- 
http://twitter.com/arungupta
http://blogs.oracle.com/arungupta