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