users@jersey.java.net

[Jersey] Using ApacheHttpClient in a JerseyTest

From: Damiano ALBANI <damiano.albani_at_univ-nantes.fr>
Date: Mon, 07 Feb 2011 14:08:28 +0100

Hello,

I'd like to use ApacheHttpClient in my JerseyTest-based test suite, to
leverage its cookie management capabilities in particular.
The Java code for my test class looks like this:

     protected AppDescriptor configure() {
         return
             new WebAppDescriptor.Builder("fr.univNantes.spin")
             .clientConfig(
                 new DefaultApacheHttpClientConfig() {
                     {
                         this.getClasses().add(JAXBContextResolver.class);
                         
this.getProperties().put(ApacheHttpClientConfig.PROPERTY_HANDLE_COOKIES,
true);
                         
this.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
                     }
                 }
             )
             .build();
     }

     protected TestContainerFactory getTestContainerFactory() {
         return new ExternalTestContainerFactory();
     }

     @Test
     public void test_login() {
         ClientResponse response =
resource().path("login").get(ClientResponse.class);
     }

But that doesn't make it use an ApacheHttpClient at all.
It looks like the culprit is "JerseyTest::getClient(TestContainer,
AppDescriptor)", which always returns a client based on
URLConnectionClientHandler...

So where/how can I plug in an Apache client in there?

Thanks a lot.

-- 
Damiano ALBANI