2

I'm trying to use EclipseLink MOXy as my JAXB Provider, but I'm still having some problems.

I've already put a jaxb.properties file in the same package as the Error class. Nonetheless, I still get following error, when calling my webservice:

Error 500 org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: br.services.model.Error of media type: application/xml;charset="UTF-8"

If I run the following code in my Error class

public static void main(String[] args) throws JAXBException
{
    System.out.println(JAXBContext.newInstance(Error.class).getClass());
}

I will get this: class org.eclipse.persistence.jaxb.JAXBContext

So could anyone please help me?

bdoughan
  • 147,609
  • 23
  • 300
  • 400
Felipe S
  • 21
  • 1

1 Answers1

1

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

Location of eclipselink.jar

You need to make sure that you have the eclipselink.jar in the following location (see: http://wiki.eclipse.org/EclipseLink/Examples/JPA/JBoss_Web_Tutorial#Specific_Server)

$JBOSS_HOME/server/default/lib

jaxb.properties

You are right that the jaxb.properties file needs to be in the same package as you domain model (Error class). You need to make sure that it has the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html):

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

EclipseLink Version

There is a chance that RESTEasy is depending upon some proprietary JAXB reference implementation extension. We've added support for all the ones we know about to MOXy so you'll want to make sure you are using the latest version of EclipseLink. I would recommend using EclipseLink 2.4.1 which can be obtained from the link below:

MessageBodyReader/MessageBodyWriter

There is a chance that RESTEasy was not written (well enough) to support pluggable JAXB implementations. In this case you could create a MessageBodyReader/MessageBodyWriter to leverage MOXy. Below is an example I created for using MOXy as a JSON-binding provider that you could use as a model.

Just as MOXy ships with a pre-built MessageBodyReader/MessageBodyWriter to enable JSON-binding (see: MOXy as Your JAX-RS JSON Provider - MOXyJsonProvider). When I'm back from vacation I will add a pre-built MessageBodyReader/MessageBodyWriter` to make it easier to enable MOXy as an XML provider for the RESTEasy environment.

bdoughan
  • 147,609
  • 23
  • 300
  • 400