users@jersey.java.net

[Jersey] Re: How about the access to the entity by Jersey Filter?

From: Kobayashi Satoshi <satoshi-k_at_iij.ad.jp>
Date: Tue, 30 Aug 2011 18:07:34 +0900

Hello Pavel,

I was expecting the API.
Thank you very much!

By the way, I tested and new questions was caused.
I tried to use Bean Validation (JSR303) in Jersey Filter.
Bean Validation is annotation-based framework.
Of course, The annotation of JavaBean is necessary for the validation.
# Up to now, I have used it in the resource
# I think that JAX-RS and Bean Validation are compatible

First, I tried ContainerRequestFilter
The return value of ContainerRequest#getEntity() has become LinkedHashMap.
# the representation of my API is JSON
I was expecting to become representation class object (not
LinkedHashMap) of the resource.
Of course, LinkedHashMap have no annotations that I need.

Second, I tried ContainerResponseFilter
The return value of ContainerResponse#getEntity() has become
representation class object of the resource. yeah!
But, it have no annotations that I need...

ContainerResponseFilter can not be used for validation.
But I think it is useful if the content of JavaBean can be rewritten
based on annotation like Bean Validation.

It is the following that I want to do either (pre or post) processing.
  (in filter method)
    Object entity = r.getEntity();
    /* do something (based on annotation of the entity) */
    r.setEntity(entity);
    return r;

I might be misunderstanding something.
Do you have any ideas?

Regards,
Satoshi

(11/04/12 19:21), Pavel Bucek wrote:
> See rev. 4837, ContainerRequest.setEntity was added.
>
> it will be present in 1.7-ea03.
>
> Regards,
> Pavel
>
> On 4/7/11 1:31 PM, Pavel Bucek wrote:
>> Hello Satoshi,
>>
>> good question. I'm already investigating what can be improved - I have
>> first working implementation of setEntity method, needs some polishing
>> though. Will keep you updated.
>>
>> Pavel
>>
>>
>> On 04/04/2011 04:53 AM, Kobayashi Satoshi wrote:
>>> Hello
>>>
>>> I'm using Jersey in a project of my company.
>>> I like Jersey very much.
>>>
>>> but, I feel that a part of the Jersey Filter is inconvenient.
>>> because it is difficult to access to the entity of JavaBean form.
>>> I want often to rewrite it in preprocessing by using the Jersey Filter.
>>>
>>> ContainerRequestFilter can get the entity from ContainerRequest#getEntity(),
>>> but can't put again it because pairing ContainerRequest#setEntity()
>>> doesn't exist.
>>> If the marshaler is created or can be got in the filter,
>>> ContainerRequest#setEntityInputStream can be used?
>>> However, I think the method in which it is not good so much.
>>>
>>> Please tell if there is a good way.
>>>
>>> thanks!
>>>
>>> --
>>> Internet Initiative Japan Inc.
>>> Research& Development Section
>>> Product Development Department
>>> SEIL Business Unit
>>>
>>> Satoshi Kobayashi<satoshi-k_at_iij.ad.jp>
>>>
>>
>
>