users@jersey.java.net

[Jersey] Re: Validation a request using BV

From: Michal Gajdos <michal.gajdos_at_oracle.com>
Date: Mon, 15 Apr 2013 11:21:46 +0200

Hi Arun,

yes, I know that the issue is pretty old but I think it should be fixed
in one of our next sprints.

thanks,
Michal

On 12.04.2013 05:23 , Arun Gupta wrote:
> Michal,
>
> This RFE was filed almost 3 years ago. Are you planning to fix this
> for Jersey 2.0 ?
>
> Arun
>
> On 4/11/13 7:04 AM, Michal Gajdos wrote:
>> I see why are you interested in seeing validation errors in the
>> server log but it doesn't make much sense in the production
>> environment. The BadRequestException is logged by container and not
>> by Jersey itself (Jersey just passes this exception to the
>> container). We don't want to pass ConstraintViolationException
>> directly to the container/user because it may, by default, expose
>> some information about how the resource class/method look like
>> (sending validation errors is not enabled by default as well).
>> Besides this logging this kind of exceptions may introduce unwanted
>> overhead under high load.
>>
>> Anyways, we're considering to do something similar by introducing
>> 'development' mode (see [1]).
>>
>> Michal
>>
>> [1] http://java.net/jira/browse/JERSEY-528
>>
>> On 10.04.2013 15:31 , Arun Gupta wrote:
>>> +1
>>>
>>> I'd like to see any related errors to be shown by default instead of
>>> changing any logging settings.
>>>
>>> Arun
>>>
>>> On 4/10/13 5:46 AM, Jan Algermissen wrote:
>>>> Hi Michal,
>>>>
>>>> On 10.04.2013, at 13:17, Michal Gajdos <michal.gajdos_at_oracle.com>
>>>> wrote:
>>>>
>>>>> Hi Arun,
>>>>>
>>>>> ConstraintViolationExceptions are logged at the Level.FINER level
>>>>> on the server.
>>>> Hmm, I find that a bit odd. How would I ever be able to understand
>>>> what happened from the log without turning FINER on?
>>>>
>>>> I recall having had a similar issue where it was simply impossible
>>>> to determine the cause of a problem beyond seeing a 500
>>>> WebApplicationException in the GF logs.
>>>>
>>>> Jan
>>>>
>>>>
>>>>> 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
>>>>>>
>>>
>>
>