Hi all,

today I was trying to create tests my JAX-RS services created with CXF
2.6.13. I wanted to use the local transport mechanism for this, but it
seems I'm running into issues I can't really explain.

I created a new test class based on the local transport example provided by
the wiki[1]

In essence what I do is create a server:

    private static void startServer() throws Exception {
        List<Object> providers = new ArrayList<Object>();
        providers.add(JacksonJaxbJsonProvider.class);

        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(SystemResource.class);
        sf.setProviders(providers);
        sf.setAddress(ENDPOINT_ADDRESS);
        sf.getInInterceptors().add(new LoggingInInterceptor());
        sf.getOutInterceptors().add(new LoggingOutInterceptor());

        server = sf.create();
    }


Where I specify the JacksonJaxbJsonProvider as an additional provider.

Now in my actual test I try to use the WebClient like this:

@Test
public void testGetSystemInfo() {
    WebClient client = WebClient.create(ENDPOINT_ADDRESS);

client.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON);

WebClient.getConfig(client).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
    final Response response = client
                .path("v1/system/jvm")
                .accept(MediaType.APPLICATION_JSON)
                .type(MediaType.APPLICATION_JSON)
                .get(Response.class);

    assertTrue(response.getStatus() == Response.Status.OK.getStatusCode());
}

So far so good.

Now when I try this test it fails, with the message:

"No message body writer has been found for response class LinkedHashMap".
Somehow it seems not to map to my JacksonJaxbJsonProvider.class, which does
work when doing this via the browser.

While debugging the problem a bit I noticed that when I run from my browser
I get the following debug statements:

03.03.2014 20:49:19 DEBUG http-8080-1
[JAXRSInInterceptor.processRequest:228] Request path is: /v1/system/jvm
03.03.2014 20:49:19 DEBUG http-8080-1
[JAXRSInInterceptor.processRequest:229] Request HTTP method is: GET
03.03.2014 20:49:19 DEBUG http-8080-1
[JAXRSInInterceptor.processRequest:230] Request contentType is: */*
03.03.2014 20:49:19 DEBUG http-8080-1
[JAXRSInInterceptor.processRequest:231] Accept contentType is:
application/json
03.03.2014 20:49:19 DEBUG http-8080-1
[JAXRSInInterceptor.processRequest:233] Found operation: getMemoryInfo
Now if I run this with the local transport I get the following output.

03.03.2014 22:20:46 DEBUG main [JAXRSInInterceptor.processRequest:231]
Request path is: /v1/system/jvm
03.03.2014 22:20:46 DEBUG main [JAXRSInInterceptor.processRequest:232]
Request HTTP method is: GET
03.03.2014 22:20:46 DEBUG main [JAXRSInInterceptor.processRequest:233]
Request contentType is: application/json
03.03.2014 22:20:46 DEBUG main [JAXRSInInterceptor.processRequest:234]
Accept contentType is: null
03.03.2014 22:20:46 DEBUG main [JAXRSInInterceptor.processRequest:236]
Found operation: getMemoryInfo

It seems there is something wrong with the Accept contentType somehow.

Does somebody have any clues or pointers into which direction I should take
a look?

[1]https://cwiki.apache.org/confluence/display/CXF20DOC/JAXRS+Testing

-- 
Jeroen Reijn
Hippo
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 101 Main Street, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

http://about.me/jeroenreijn

Reply via email to