Hi Gareth

thanks for the confirmation

On Thu, Apr 15, 2010 at 12:46 PM, Gareth Hughes
<[email protected]>wrote:

> Sergey,
>
> many thanks. It worked. The code follows.
>
> The only thing I'd like to fix is that the namespace prefixes are ns2 ns3
> etc. and I would like to manually set them.
>

Perhaps you can set a com.sun.xml.bind.namespacePrefixMapper marshaller
property using 'marshallerProperties' :

http://cxf.apache.org/docs/jax-rs.html#JAX-RS-ConfiguringJAXBprovider


>
> public class MyJAXBElementProvider extends JAXBElementProvider {
>    public String contextPath;
>
>    @Override
>    protected JAXBContext getJAXBContext(Class<?> type, Type genericType)
>            throws JAXBException {
>        JAXBContext jaxbContext = super.getJAXBContext(type, genericType);
>
>        jaxbContext = JAXBContext.newInstance(contextPath);
>        return jaxbContext;
>    }
>
>
>
I'm wondering, perhaps you could do JAXBContext.newInstance(contextPath) in
the property setter and have a private JAXBContext field instead ? Also, you
may not need to call a superclass method in this case.

cheers, Sergey


>    /**
>     * List of package names this will support for marshalling
>     * E.g.
>  
> com.axiell.arena.domain.binding:org.openarchives.oai._2:org.openarchives.oai._2_0.oai_dc:org.purl.dc.elements._1
>     * @param contextPath
>     */
>    public void setContextPath(String contextPath) {
>        this.contextPath = contextPath;
>    }
>
> }
>
>
>
> Replace the normal jaxbProvider entry in Spring config with this.
>
>    <bean id="jaxbProvider"
> class="com.axiell.arena.archive.oai.server.invocation.MyJAXBElementProvider"
> >
>        <property name="contextPath"
> value="com.axiell.arena.domain.binding:org.openarchives.oai._2:org.openarchives.oai._2_0.oai_dc:org.purl.dc.elements._1"/>
>    </bean>
>
>
>
>
> Sergey Beryozkin wrote:
>
> 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
> jaxrs:server:
>
> <jaxrs:dataBinding>
>      <bean class="org.apache.cxf.jaxb.JAXBDataBinding">
>        <property name="namespaceMap">
>                <map>
>                        <entry>
>                        <key><value>
> http://cxf.apache.org/anonymous_complex_type/</value></key>
>                        <value>BeepBeep</value>
>                        </entry>
>                </map>
>        </property>
>      </bean>
>      </jaxrs:dataBinding>
>
> 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
> <[email protected]><mailto:[email protected]>wrote:
>
> > 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
> > http://www.openarchives.org/OAI/2.0/ 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 : com.foo.domain.binding.CatalogueSearchResultDTO
> 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:
> >
> > String OAI_DC_PACKAGE
> >
> >
> ="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.
> >
> > DISCLAIMER:
> > 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.
> >
>
> ________________________________
> 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.
>
> DISCLAIMER:
> 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.
>

Reply via email to