You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Anthony Fryer <ap...@hotmail.com> on 2014/09/11 12:19:11 UTC

tomee and moxy

I have been trying to use moxy as the JAXBContext implementation in tomee and
have had some issues.  I had the following war file...

moxy-test.war
|-WEB-INF
  |-lib
    |-config-moxy.jar
      |- META-INF
        |- services
          |-javax.xml.bind.JAXBContext

The content of the javax.xml.bind.JAXBContext file is
"org.eclipse.persistence.jaxb.JAXBContextFactory"

When i created a JAXBContext in my app, it was always creating an instance
of com.sun.xml.bind.v2.runtime.JAXBContextImpl.

I tried setting the following in system.properties...
javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

but that also didn't work and still i was always getting an
com.sun.xml.bind.v2.runtime.JAXBContextImpl instance.

Lastly i tried moving config-moxy.jar into tomee/lib and finally i started
getting instances of org.eclipse.persistence.jaxb.JAXBContext.

Then i renamed config-moxy.jar to moxy-config.jar in tomee/lib and it
stopped working.  That's when i looked at the jars packaged in tomee/lib and
found that jaxb-impl.jar has a META-INF/services/javax.xml.bind.JAXBContext
file with the content "com.sun.xml.bind.v2.ContextFactory" which was causing
all my JAXBContext instances to be of that type.  I got lucky when i named
my file config-moxy.jar in tomee/lib because it came before jaxb-impl.jar
and configured moxy. 

I then deleted the META-INF/services folder from tomee/lib/jaxb-impl.jar and
tested my original war file which had the config-moxy.jar in WEB-INF/lib and
it started working.

I was wondering, should jaxb-impl.jar have that
META-INF/services/javax.xml.bind.JAXBContext file?  It makes it very
difficult to configure your own jaxb implementation from a war file.

Also shouldn't the javax.xml.bind.context.factory system property override
any jar file configuration?

Regards,

Anthony





--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-and-moxy-tp4671723.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: tomee and moxy

Posted by Romain Manni-Bucau <rm...@gmail.com>.
it will but if we remove this services file it will still pick
jaxb-impl and not moxy cause of the classloading.


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-09-11 15:09 GMT+02:00 Anthony Fryer <ap...@hotmail.com>:
> I'm creating a jaxws client and want to use the same jaxbcontexts used to
> marshal the jaxb objects to xml to also marshal to json in a Handler for
> indexing the web service requests and responses in elastic search.  The
> default JAXBContext can't marshal to json, so i need to use moxy.  I tried
> using jackson (ie. not use a jaxbcontext at all) for serializing to json but
> when it came to deserialization from json to an object, it couldn't handle
> some cases (object inheritance etc).  I found using moxy i could reuse the
> same jaxbcontext using by the dispatcher and it handled complex
> deserialization better than anything else.
>
> Wouldn't the container (and cxf) still use
> com.sun.xml.bind.v2.runtime.JAXBContextImpl even if you removed
> META-INF/services folder from tomee/lib/jaxb-impl.jar?  I just need my
> deployed app to use moxy, not the container libs.
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-and-moxy-tp4671723p4671726.html
> Sent from the TomEE Users mailing list archive at Nabble.com.

Re: tomee and moxy

Posted by Anthony Fryer <ap...@hotmail.com>.
I'm creating a jaxws client and want to use the same jaxbcontexts used to
marshal the jaxb objects to xml to also marshal to json in a Handler for
indexing the web service requests and responses in elastic search.  The
default JAXBContext can't marshal to json, so i need to use moxy.  I tried
using jackson (ie. not use a jaxbcontext at all) for serializing to json but
when it came to deserialization from json to an object, it couldn't handle
some cases (object inheritance etc).  I found using moxy i could reuse the
same jaxbcontext using by the dispatcher and it handled complex
deserialization better than anything else.

Wouldn't the container (and cxf) still use
com.sun.xml.bind.v2.runtime.JAXBContextImpl even if you removed
META-INF/services folder from tomee/lib/jaxb-impl.jar?  I just need my
deployed app to use moxy, not the container libs.



--
View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-and-moxy-tp4671723p4671726.html
Sent from the TomEE Users mailing list archive at Nabble.com.

Re: tomee and moxy

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
can't work since the container uses jaxb as well (and cxf uses
container loader and not app loader so it can't load it).

That's said moxy has a provider which should work for you no? MOXyJsonProvider


Romain Manni-Bucau
Twitter: @rmannibucau
Blog: http://rmannibucau.wordpress.com/
LinkedIn: http://fr.linkedin.com/in/rmannibucau
Github: https://github.com/rmannibucau


2014-09-11 12:19 GMT+02:00 Anthony Fryer <ap...@hotmail.com>:
> I have been trying to use moxy as the JAXBContext implementation in tomee and
> have had some issues.  I had the following war file...
>
> moxy-test.war
> |-WEB-INF
>   |-lib
>     |-config-moxy.jar
>       |- META-INF
>         |- services
>           |-javax.xml.bind.JAXBContext
>
> The content of the javax.xml.bind.JAXBContext file is
> "org.eclipse.persistence.jaxb.JAXBContextFactory"
>
> When i created a JAXBContext in my app, it was always creating an instance
> of com.sun.xml.bind.v2.runtime.JAXBContextImpl.
>
> I tried setting the following in system.properties...
> javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
>
> but that also didn't work and still i was always getting an
> com.sun.xml.bind.v2.runtime.JAXBContextImpl instance.
>
> Lastly i tried moving config-moxy.jar into tomee/lib and finally i started
> getting instances of org.eclipse.persistence.jaxb.JAXBContext.
>
> Then i renamed config-moxy.jar to moxy-config.jar in tomee/lib and it
> stopped working.  That's when i looked at the jars packaged in tomee/lib and
> found that jaxb-impl.jar has a META-INF/services/javax.xml.bind.JAXBContext
> file with the content "com.sun.xml.bind.v2.ContextFactory" which was causing
> all my JAXBContext instances to be of that type.  I got lucky when i named
> my file config-moxy.jar in tomee/lib because it came before jaxb-impl.jar
> and configured moxy.
>
> I then deleted the META-INF/services folder from tomee/lib/jaxb-impl.jar and
> tested my original war file which had the config-moxy.jar in WEB-INF/lib and
> it started working.
>
> I was wondering, should jaxb-impl.jar have that
> META-INF/services/javax.xml.bind.JAXBContext file?  It makes it very
> difficult to configure your own jaxb implementation from a war file.
>
> Also shouldn't the javax.xml.bind.context.factory system property override
> any jar file configuration?
>
> Regards,
>
> Anthony
>
>
>
>
>
> --
> View this message in context: http://tomee-openejb.979440.n4.nabble.com/tomee-and-moxy-tp4671723.html
> Sent from the TomEE Users mailing list archive at Nabble.com.