users@jersey.java.net

[Jersey] Re: Validation a request using BV

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Wed, 10 Apr 2013 13:17:29 +0200

Hi Arun,

ConstraintViolationExceptions are logged at the Level.FINER level on the
server. If you want to see the error message on the client side you need
to explicitly enable outputting of validation error entity into response
by setting ServerProperties. FEATURE_OUTPUT_VALIDATION_ERROR_ENTITY
([1]) in your application (using
web.xml/Application#getProperties/ResourceConfig#property; see [2]). The
returned entity should, after this, contain all validation error messages.

[1]
https://github.com/jersey/jersey/blob/2.0-rc1/core-server/src/main/java/org/glassfish/jersey/server/ServerProperties.java#L277
[2]
https://github.com/jersey/jersey/blob/2.0-rc1/examples/bean-validation-webapp/src/test/java/org/glassfish/jersey/examples/beanvalidation/webapp/ContactCardTest.java#L91

thanks,
Michal

On 10.04.2013 00:22 , Arun Gupta wrote:
> 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
>