Hi
On 08/06/14 19:44, Lambert, Michael wrote:
I solved it but its non intuitive. I used the following block in my
beans.xml content file:
<jaxrs:server id="services" address="/">
<jaxrs:serviceBeans>
<ref bean="userDataServiceImpl" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jaxbProvider"/>
<ref bean="jsonProvider"/>
</jaxrs:providers>
</jaxrs:server>
<bean id="userDataServiceImpl"
class="com.healthmedia.ws.service.userdata.v1.UserDataServiceImpl" />
<util:list id="xmlTypes">
<value>application/xml</value>
<value>text/xml</value>
<value>application/*+xml</value>
<value>application/vnd.com.healthmedia.user-data-collection+xml;version=1.0</value>
<value>application/vnd.com.healthmedia.user-data+xml;version=1.0</value>
</util:list>
<bean id="jaxbProvider"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="unmarshallAsJaxbElement" value="true"/>
<property name="marshallAsJaxbElement" value="true" />
<property name="produceMediaTypes" ref="xmlTypes"/>
<property name="consumeMediaTypes" ref="xmlTypes"/>
</bean>
<util:list id="jsonTypes">
<value>application/json</value>
<value>application/*+json</value>
<value>application/vnd.com.healthmedia.user-data-collection+json;version=1.0</value>
<value>application/vnd.com.healthmedia.user-data+json;version=1.0</value>
</util:list>
<bean id="jsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="unmarshallAsJaxbElement" value="true"/>
<property name="marshallAsJaxbElement" value="true" />
<property name="ignoreNamespaces" value="true"/>
<property name="produceMediaTypes" ref="jsonTypes"/>
<property name="consumeMediaTypes" ref="jsonTypes"/>
</bean>
It SEEMS though that I shouldnt have to jump thorugh hoops to get this
working. Is there a reason why it shouldnt work out of the box?
@XmlRootElement will be added automatically if you have anonymous
complex types, it might also be possible to configure Maven Java plugin
to generate @XmlRootElement in all the cases.
The fact
that the JSONProvider need to be told about a JAXB implementation detail
seems wrong to me.
Well, CXF JSONProvider/Jettison is completely dependent on JAXB, these
are the properties that both CXF JAXB/XML and JSONProvider share to deal
with beans that have no @XmlRootElement, it requires the use of
JAXBElement.
I also ran into a JSON namespace issue that I had to
solve as well.
We do not know who the consumer is, dropping the namespaces by default
would break the consumers expecting deserialize the payload back into
the namespace qualified bean.
Cheers, Sergey
Is there a better way to configure this?
Thanks again,
-Mike
On Sun, Jun 8, 2014 at 2:15 PM, Lambert, Michael <mich...@michaellambert.com
wrote:
I have written an example service to implement standards I am trying to
stand up where I work.
I want to do contract first development and so derive all artifacts from a
predefined xml schema and wadl for rest services.
The project generates the artifacts and I import those artifacts into an
implementation project to write the sample code. I then overrode the media
types that the JAXBElementProvider and JSONProvider operate on in my
context file (bean.xml).
When I attempt to access the implemented service using a curl statement
the following error occurs:
curl -X GET -H "Accept:
application/vnd.com.healthmedia.user-data+json;version=1.0"
http://localhost:8080/user-data-service/user-data/11
JAXBException occurred : unable to marshal type
"com.healthmedia.ws.entity.userdata.v1.UserDataType" as an element because
it is missing an @XmlRootElement annotation. unable to marshal type
"com.healthmedia.ws.entity.userdata.v1.UserDataType" as an element because
it is missing an @XmlRootElement annotation.
I am really stuck can someone help?
The sample code is on my github account:
https://github.com/MacFlecknoe/service-repository-sample
The schemas and wadl are in the schema project (
https://github.com/MacFlecknoe/service-repository-sample/tree/master/schema),
the java artifacts are generated in the artifact project (
https://github.com/MacFlecknoe/service-repository-sample/tree/master/user-data/artifacts)
and the implementation is in the user-data-service project (
https://github.com/MacFlecknoe/service-repository-sample/tree/master/user-data/service
)
Thank you in advance!
Michael Lambert