users@jersey.java.net

Re: [Jersey] Some questions on the usage of LoggingFilter

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 18 Nov 2008 10:31:49 +0100

On Nov 18, 2008, at 5:19 AM, Srinivas Naresh Bhimisetty wrote:

> Hi,
>
> I have a doubt on the usage of LoggingFilter. Can the LoggingFilter
> api be used to send requests and get response the following way:
> ------------------------------------------------------------------------------------
> LoggingFilter loggingFilter = new LoggingFilter();
> ClientRequest request = ClientRequest.create().build(BASE_URI,
> "GET");
> ClientResponse clientResponse = loggingFilter.handle(request);
> ------------------------------------------------------------------------------------
>
> When I tried running the above code, the following error was thrown:
> ----------------------------------------------------------------------------
> java.lang.NullPointerException
> at
> com
> .sun
> .jersey.api.client.filter.LoggingFilter.handle(LoggingFilter.java:152)
> at
> com
> .sun
> .jersey
> .qe
> .tests
> .jmaki
> .JMakiBackendWebappTest
> .doTestPutPrinterBasedOnId(JMakiBackendWebappTest.java:251)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun
> .reflect
> .NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> ....
> --------------------------------------------------------------------------------------------------------------------
>
> This indicates that the ClientHandler is null. Should this handler
> be set, if we want to use the API this way? If so, is there a way it
> could be set?
> Moreover, is this a proper use case?
>

No.

You add an instance of a ClientFilter to an instance of Filterable
using the Filterable.addFilter.

Both Client and Async/WebResource implement Filterable.

Paul.