users@jax-rs-spec.java.net

[jax-rs-spec users] Re: Filters and Entity Interceptors

From: Arun Gupta <arun.p.gupta_at_oracle.com>
Date: Fri, 04 Jan 2013 17:19:26 -0800

Thanks!

I got a simple sample working now in all these conditions. Still facing
javax.ws.rs.InternalServerErrorException in a particular case and will
take that up on users_at_jersey.

One part that did not get answered was using filters for processing
headers and entity interceptors for payload. Is that the expected usage ?

Arun

On 1/4/13 1:48 PM, Santiago Pericas-Geertsen wrote:
> Arun,
>
> The client is doing a GET, so there is not entity in the request (no payload), but there's an entity in the response. Thus,
>
> 1) aroundReadFrom called in client to process response entity
> 2) aroundWriteFrom called in server to generate response entity
>
> To get both called on both sides you need a POST/PUT request that sends and entity and expects another entity back. Order should be:
>
> aroundWriteFrom (client)
> aroundReadFrom (server)
> aroundWriteFrom (server)
> aroundReadFrom (client)
>
> -- Santiago
>
> On Jan 4, 2013, at 2:22 PM, Arun Gupta <arun.p.gupta_at_oracle.com> wrote:
>
>> Santiago,
>>
>> There was a inconsistency in my client/server code. After cleaning up, it looks like:
>>
>> Client code:
>>
>> Client client = ClientFactory.newClient();
>> client
>> .configuration()
>> .register(GzipReaderInterceptor.class)
>> .register(GzipWriterInterceptor.class);
>> WebTarget target = client.target("http://"
>> + request.getServerName()
>> + ":"
>> + request.getServerPort()
>> + request.getContextPath()
>> + "/webresources/fruits");
>>
>> Server code:
>>
>> @ApplicationPath("webresources")
>> public class MyApplication extends Application {
>> @Override
>> public Set<Class<?>> getClasses() {
>> Set<Class<?>> resources = new java.util.HashSet<>();
>> resources.add(org.sample.interceptor.MyResource.class);
>> // resources.add(org.sample.interceptor.GzipReaderInterceptor.class);
>> // resources.add(org.sample.interceptor.GzipWriterInterceptor.class);
>> return resources;
>> }
>> }
>>
>> Endpoint:
>>
>> @Path("fruits")
>> public class MyResource {
>> private String[] response = { "apple", "banana", "mango" };
>>
>> @GET
>> public String getList() {
>> System.out.println("endpoint invoked (getList)");
>> return response[0];
>> }
>>
>> If both the interceptors are enabled on client then only aroundReadFrom interceptor is called.
>>
>> How should the resource method and client/server look like to trigger aroundReadFrom and aroundWriteTo interceptors on both sides ?
>>
>> Thanks,
>> Arun
>>
>> On 1/4/13 6:48 AM, Santiago Pericas-Geertsen wrote:
>>> Arun,
>>>
>>> (1) Is there some client code that triggers the reader interceptor here? Could you provide more details about your app?
>>>
>>> (2) What is the J1 slide that you're referring to?
>>>
>>> -- Santiago
>>>
>>> On Jan 3, 2013, at 8:07 PM, Arun Gupta <arun.p.gupta_at_oracle.com> wrote:
>>>
>>>> Filters are meant for processing headers only and Entity Interceptors for HTTP bodies. Is that a good qualification ?
>>>>
>>>> I have a resource method as:
>>>>
>>>> @GET
>>>> public String getList() {
>>>> System.out.println("endpoint invoked");
>>>> return "apple";
>>>> }
>>>>
>>>> and the following reader and writer interceptor:
>>>>
>>>> @Override
>>>> public Object aroundReadFrom(ReaderInterceptorContext ric) throws IOException, WebApplicationException {
>>>> System.out.println("aroundReadFrom");
>>>> return ric.proceed();
>>>> }
>>>>
>>>> @Override
>>>> public void aroundWriteTo(WriterInterceptorContext wic) throws IOException, WebApplicationException {
>>>> System.out.println("aroundWriteTo");
>>>> wic.proceed();
>>>> }
>>>>
>>>> The invocation sequence says
>>>>
>>>> endpointInvoked
>>>> aroundWriteTo
>>>> aroundReadFrom
>>>>
>>>> The slides from JavaOne session seem to indicate it should be:
>>>>
>>>> aroundReadFrom
>>>> endpointInvoked
>>>> aroundWriteTo
>>>>
>>>> Can you please explain the sequence ?
>>>>
>>>> Arun
>>>>
>>>> --
>>>> http://twitter.com/arungupta
>>>> http://blogs.oracle.com/arungupta
>>>>
>> --
>> http://twitter.com/arungupta
>> http://blogs.oracle.com/arungupta
>>

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