Jose, that did the trick! I tried out the 'validateOutput' property on the JAXB provider and it works. I have to be honest and say that I didn't see that section on the page - thought it would have been before the stuff about 'catalogs' but that's just me;-)
Thank you all for your quick replies - the solution has made my day! Cheers! On 11 December 2013 16:15, Jose María Zaragoza <[email protected]> wrote: > Hi: > > I've never tried to enable schema validation to data output ( it > doesn't make sense *for me* ) > Reading that webpage: > > - I think that > > <jaxrs:properties> > <entry key="schema-validation-enabled" value="true" /> > </jaxrs:properties> > > doesn't enable JAX-RS schema validation > > > - About that webpage > > "By default, after a valid schema has been located, only JAXB > Unmarshaller will use it to validate the input. > Starting from CXF 2.3.4 and 2.4, the following properties can be used > to enable the output validation: > > validateOutput > validateBeforeWrite > > Setting the 'validateOutput' property will ensure that JAXBMarshaller > will validate the output while writing the data. The > 'validateBeforeWrite' property can be set to ensure the validation is > done before data are written to the output stream." > > Did you test these properties ? > > > > > > > 2013/12/11 Anders Clausen <[email protected]>: > > Hi Sergey > > > > Thanks for replying so quickly. Yes, it is the output data (the response > > sent back to the calling client) that we're trying to validate. > > > > Cheers > > Anders > > > > > > On 11 December 2013 15:45, Sergey Beryozkin <[email protected]> > wrote: > > > >> 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 > >>> > >>> > >> > >> > >> >
