cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sergey Beryozkin <>
Subject Re: JAX-RS help unmarshalling a different object from another namespace
Date Wed, 14 Apr 2010 15:23:13 GMT
Hi Gareth

It all makes sense (I think).
Unfortunately it is not currently possible to explicitly configure
JAXBElementProvider for it to be aware of all the additional
packages/classes which may need to be dealt with when unmarshalling a given
xml instance. But it could be a good enhancement indeed.

There're few options/workarounds at the moment :

1. Write a custom message body reader extending CXF JAXBElementProvider and
overriding its createJaxbContext method by returning a statically created
JAXBContext aware of OAI_DC_PACKAGE, provided that a class for which a
context needs to be created is in the right package.

2. Try CXF JAXBDataBinding, by embedding the following fragment in the

      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
        <property name="namespaceMap">

The namespaceMap property is just an example on how  CXF JAXBDataBinding can
be configured but I believe one can specify additional packages/classes for
which JAXBContexts will be precreated.

Perhaps, it is also possible to use JAXBContext explicitly in your code.

Hope it helps, Sergey

On Wed, Apr 14, 2010 at 12:01 PM, Gareth Hughes

> Hi,
> Background: I'm implementing an OAIPMH repository server using JAXRS.
> I've written the client (called a harvester) already and the server is
> up and running.
> The server returns XML using the OAIPMH namespace
> and this thing is used to return
> information from archives and libraries. The clever bit is that the
> information about each entry can be in any other xml format. Usually
> Dublin Core which is a different xml namespace.
> In code I use objectFactory to build the OAIPMH objects and then add in
> my other object from a different namespace. When the server returns I get
> JAXBException occurred : is
> not known to this context.
> This class can be unmarshalled but the server doesn't know where to find
> this class.
> When I wrote the Harvester, which unmarshal all the xml in the other
> direction, I had to write lines like this to get my marshaller to know
> about all the possible packages:
> ="gov.loc.mets:org.openarchives.oai._2_0.oai_dc:org.purl.dc.elements._1:gov.loc.marc21.slim:org.openarchives.oai._1_1.oai_marc";
> private Unmarshaller oaiDCUnmarshaller =
> JAXBContext.newInstance(OAI_DC_PACKAGE).createUnmarshaller();
> What's equivalent of this for the Spring config of the jaxrs:server? How
> do I tell it what java packages it can unmarshal?
> I currently have the following.
>    <bean id="jaxbProvider"
> class="org.apache.cxf.jaxrs.provider.JAXBElementProvider" />
>    <jaxrs:server id="oaipmhServiceServer" address="/">
>        <jaxrs:serviceBeans>
>            <ref bean="oaiServerInvocation" />
>        </jaxrs:serviceBeans>
>        <jaxrs:providers>
>            <ref bean="jaxbProvider" />
>        </jaxrs:providers>
>    </jaxrs:server>
> Hope this all makes sense
> Is there a reference guide for the values in jaxrs:server? I found that
> the API docs have no comments.
> Thanks very much
> Gareth Hughes
> Axiell Limited (registered no. 01607548) is a private limited company
> registered in England. The address of the Registered Office is Unit 2, Hall
> View Drive, Bilborough, Nottingham, NG8 4GD. VAT registration no. GB 610
> 5069 78.
> This e-mail is only for the use of the intended recipient and may contain
> confidential information. If you have received this e-mail in error, please
> notify the sender immediately, delete it and do not use or disseminate its
> contents. Any views or opinions are solely those of the author and do not
> necessarily represent those of the Company. This e-mail may be monitored.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message