Hi
On 11/12/13 15:22, Anders Clausen wrote:
Hi
I've only used CXF for a little while and still trying to find my way. I've
got a question that I hope you can help me resolve. For our current project
we expose a service both as REST and as SOAP. We have defined our
interfaces through XSDs and use JAXB2. We want to turn on response
validation during development time and have successfully done that for our
SOAP service, however, when it comes to our REST service I am not sure if
this can be done. How does JSON work with XSDs? I've been trying to follow
the guidelines from this page
CXF<https://cwiki.apache.org/confluence/display/CXF20DOC/JAX-RS+Data+Bindings#JAX-RSDataBindings-Schemavalidation>
but
without any luck.
This is the code I've used:
<bean id="exRSJsonProvider"
class="org.apache.cxf.jaxrs.provider.json.JSONProvider">
<property name="dropRootElement" value="false" />
<property name="supportUnwrapped" value="true" />
<property name="ignoreNamespaces" value="true" />
<property name="schemaHandler" ref="schemaHolder"/>
</bean>
<bean id="jaxbProvider"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="schemaHandler" ref="schemaHolder"/>
</bean>
<bean id="schemaHolder"
class="org.apache.cxf.jaxrs.utils.schemas.SchemaHandler">
<property name="schemas" ref="theSchemas"/>
</bean>
<util:list id="theSchemas">
<value>classpath:webapi/xsd/GetSchedulesV01_C.xsd</value>
</util:list>
<jaxrs:server name="exRSScheduleResource"
address="${ex.rs.endpoint.address}">
<jaxrs:serviceBeans>
<bean
class="com.ex.rs.ScheduleResource" />
<bean class="com.ex.rs.LocationResource" />
</jaxrs:serviceBeans>
<jaxrs:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxrs:properties>
<jaxrs:schemaLocations>
<jaxrs:schemaLocation>classpath:/webapi/xsd/GetSchedulesV01_C.xsd</jaxrs:schemaLocation>
</jaxrs:schemaLocations>
<jaxrs:providers>
<ref bean="exRSJsonProvider" />
<ref bean="jaxbProvider" />"
<ref bean="dateParamHandler" />
<ref bean="timeParamHandler" />
</jaxrs:providers>
....................
....................
</jaxrs:server>
Is this even possible to be done or should I just drop the idea?
Technically it is possible, we have tests where input JSON sequences are
validated, it works with Jettison because they are eventually handled by
JAXB.
I'm presuming that the input JSON sequence has no namespace prefixes,
right ? Does the JAX-RS resource method accepting a JAXB bean populated
from such a sequence has a namespace property at all ?
Or are you trying to validate output data by any chance ?
Cheers, Sergey
Cheers
Anders