Hi
On 02/02/12 15:47, hdave wrote:
I am having difficulty getting CXF to use the MOXy JAX-B implementation when
I have multiple media types.  I have successfully provided the MOXy
implementation with two different JAX-B binding XML files (they call them
OXM files).  Each of the two supports a different media type.   I have two
context resolvers as follows:


@Provider
@Produces({ "application/vnd.foo"})
public class JaxbContextResolverMediaFoo
                implements ContextResolver<JAXBContext>  {


@Provider
@Produces({  "application/vnd.bar" })
public class JaxbContextResolverBar
                implements ContextResolver<JAXBContext>  {


My problem is that from within a provider,  the call:

resolver = providers.getContextResolver(JAXBContext.class, mediaType);

Does not seem to respect the media type.  Instead is seems to return
whatever context resolver is first in the list of providers.   I have also
created Foo and Bar providers to help diagnose the problem.  My CXF
configuration is as follows:

                <jaxrs:providers>
                        <ref bean="jaxbContextResolverFoo" />
                        <ref bean="jaxbContextResolverBar" />
                        <ref bean="FooXMLProvider" />
                        <ref bean="BarXMLProvider" />
                </jaxrs:providers>

My understanding from the JAX-RS spec is that getContextResolver should
return the context resolver with the most specific media type match that
also returns a JAXBContext from its "getContext" method.

I am unfamiliar with where this sorting of contextresolvers based on media
type takes place, so I can't really tell yet if it is a bug with CXF.


It is, I'm on it...
At the moment the workaround is to register a single ContextResolver which will have "@Context HttpHeaders" injected. In its getContext() method it would check the first element in httpHeaders.getAcceptableTypes() and will delegate to the appropriate internal ContextResolverImpl, a bit messy, but should work as a temp solution

Cheers, Sergey

Sergey

--
View this message in context: 
http://cxf.547215.n5.nabble.com/Issue-with-JAX-RS-providers-getContextResolver-tp5451093p5451093.html
Sent from the cxf-user mailing list archive at Nabble.com.


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to