I'm starting to set up the infrastructure so I can write tests that test
the URL that I send to a controller and then the XML or JSON response
that I get (mostly to test mocked exception handling).  I'm using the
information I got from
<http://aruld.info/cxf-22-in-action-services-design-simplified/> for the
basic setup.  I'm finding that I'm not certain how to translate the easy
Spring configuration into explicit API calls.

For instance, here is my Spring jaxrs:server configuration:

-----------------
<jaxrs:server name="dynamicContentServer" address="/rest">
        <jaxrs:features>
            <cxf:logging/>
        </jaxrs:features>
        <jaxrs:providers>
            <ref bean="jacksonJsonProvider"/>
        </jaxrs:providers>
         
        <jaxrs:serviceBeans>
            <ref bean="catalogContent"/>
            <ref bean="priceListContent"/>
            <ref bean="marketDataContent"/>
        </jaxrs:serviceBeans>
    </jaxrs:server>
-----------------

What I have so far in my @BeforeClass method is the following:

---------------
        JAXRSServerFactoryBean  sf  = new JAXRSServerFactoryBean();
        CatalogContentController    catalogContentController    = new
CatalogContentController();
        sf.setServiceBeans(catalogContentController);
        sf.getInInterceptors().add(new LoggingInInterceptor());
        sf.getOutInterceptors().add(new LoggingOutInterceptor());
---------------

I've only added one of the service beans, but that's ok for now.
 
The following is the "template" that I'm using, from the aforementioned
example site:

-------------------------
        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
        sf.setResourceClasses(Blogger.class);
        sf.getInInterceptors().add(new LoggingInInterceptor());
        sf.getOutInterceptors().add(new LoggingOutInterceptor());
        sf.setResourceProvider(Blogger.class, new
SingletonResourceProvider(new BloggerImpl()));
        sf.setAddress("http://localhost:9000/rest/blog";);
        Map<Object, Object> mappings = new HashMap<Object, Object>();
        mappings.put("xml", "application/xml");
        mappings.put("json", "application/json");
        sf.setExtensionMappings(mappings);
        sf.create();
---------------------

I'm now trying to figure out how to set the ResourceProvider.  I see
that it's not as simple as creating the JacksonJsonProvider and putting
it in, as that isn't a "ResourceProvider".

In the example, they're using the same class as a resource class and a
resource provider, so I don't know how to interpret that.

Reply via email to