cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <sberyoz...@gmail.com>
Subject Re: How to configure CXF to use different JAXBContextFactory?
Date Tue, 24 Jan 2012 17:24:28 GMT
Hi Dave


On 24/01/12 17:06, hdave wrote:
> Thank you Sergey, I'll try that.
>
> I think part of my problem is that I am confused about the Spring bean
> configuration of the CXF server.   I don't really understand what
> <jaxrs:server>  is doing inside.  Is it setting up an instance of
> JAXRSServerFactoryBean?
>
> Also what is supposed to go into<jaxrs:providers>?  Anything with an
> "@Provider" annotation or anything that implements
> ContextResolver<JAXBContext>  ?

@Provider is the annotation introduced by JAX-RS to facilitate the 
scanning of class resources for custom providers be loaded automatically.

I've never implemented that in CXF because it's kind of non-practical 
IMHO. It can not work well in complex environments and is too 
coarse-grained (ex, not possible to register multiple instances 
configured differently) and it can not be customized. Narrowing down the 
class path to scan for the providers is usually more of an effort than 
registering a provider from Spring or CXFNonSpringJAXRSServlet :-)

But having said it's something CXF (JAX-RS) lacks even though I do not 
see using this feature myself (at the moment at least :-))...


>
> I ask because, looking into it, I am now surprised my Jackson JSON provider
> ever worked.  It does NOT implement ContextResolver<JAXBContext>.  Here is
> the class definition:

Custom (JAXB) providers may want to check custom JAXBContexts and 
ContextResolver is something that can be used. They need to be 
registered as providers and in CXF case this means they have to be 
referenced from jaxrs:providers (alongside with other providers)

CXF JAXBElementProvider and JSONProvider will check custom ContextResolver

>
> -----------------------------------------------------------------
> @Provider
> @Consumes({MediaType.APPLICATION_JSON, "text/json"})
> @Produces({MediaType.APPLICATION_JSON, "text/json"})
> public class JacksonJsonProvider
>      implements
>          MessageBodyReader,
>          MessageBodyWriter,
>          Versioned // since 1.6
>
> .....
> -----------------------------------------------------------------
>
> How did this work?  What is the requirements for being placed into the
> <jaxrs:providers>  configuration stanza?

Just placing it there tells the runtime it must be a provider :-)
But I've no idea if JacksonJSONProvider checks ContextResolver or not

Cheers, Sergey


>
> Thanks,
> Dave
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/How-to-configure-CXF-to-use-different-JAXBContextFactory-tp5281773p5318636.html
> Sent from the cxf-user mailing list archive at Nabble.com.


Mime
View raw message