Hi I'm not sure. IMHO the more info we can put out of the actual code the better. What happenes to the code when say the schema document name changes ? It's just one extra issue, as far as the maintainability is concerned...
Perhaps we cab use aliases rather than actual names in such annotations and rely on catalogs to resolve them to the actual locations - but this options does look like the source of an extra headache at the moment :-) Cheers, Sergey -----Original Message----- From: Ferry Syafei Sapei [mailto:[EMAIL PROTECTED] Sent: 11 October 2008 09:19 To: [email protected] Subject: Re: Input validation for RESTful Service Hi, Wouldn't it be better if we could set schemas on the service class itself by using an annotation like below? @Schemas=(locations={"classpath:/foo.xsd", "foo2.xsd"}) public class DummyService { ... } Regards, Ferry ----- Original Message ---- From: Sergey Beryozkin <[EMAIL PROTECTED]> To: [email protected] Sent: Friday, October 10, 2008 6:56:00 PM Subject: Re: Input validation for RESTful Service Hi, I did some initial work for the schema validation be supported by JAXB-based providers. It should be available in the coming 2.1.3 release. The good schema validation support can be quite involved - all the helper classes are available inside CXF so we'll get there eventually with JAX-RS too. So this is how you would be able to do it : <jaxrs:server> <!-- this is identical on how you can do it with jax-ws if no schemas are available from wsdl --> <jaxrs:schemaLocations> <jaxrs:schemaLocation>classpath:/foo.xsd</jaxrs:schemaLocation> <jaxrs:schemaLocation>../foo2.xsd</jaxrs:schemaLocation> </jaxrs:schemaLocations> </jaxrs:server> Any MessageBodyReader which has setSchemas() method will be provided with this info (List<String>). Default JAXB provider does it. As such you can also configure the same at the provider level : <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"> <property name="schemas"> <list> <value>classpath:/foo.xsd</value> </list> </property> </bean> But configuring it at the jaxrs:server level can be handly if you say have XMLBeans validation as well (if such one exists :-))... The reason setSchemas will be called on provider (as opposed to setSchemaLocations) is that JAXBElementProvider also supports jaxb.schemaLocation property which is less shareable as schemas and it's to do with supporting xsi:schemaLocation on the XML instances...So we have setSchemaLocation on the JAXBElementProvider alongside with setSchemas which is to do with the validation... I haven't checked if imports can be done properly. Perhaps <jaxrs:server> <!-- this is identical on how you can do it with jax-ws if no schemas are available from wsdl --> <jaxrs:schemaLocations> <jaxrs:schemaLocation>../foo.xsd</jaxrs:schemaLocation> <jaxrs:schemaLocation>../importedByfoo.xsd</jaxrs:schemaLocation> </jaxrs:schemaLocations> </jaxrs:server> will do it... Cheers, Sergey > Hi all, > > I develop a RESTful Web Service following the tutorial on CXF Website (http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html). > > To marshall/unmarshall the request and response, I use JAXB. > > The request is defined as follows: > @XmlRootElement(name="orderRequest") > @XmlAccessorType(XmlAccessType.FIELD) > public class OrderRequest { > private AuthorizationRequest authorizationRequest; > @XmlElement(required=true, nillable=false) > private URI confirmationURL; > private PurchaseRequest purchaseRequest; > //getters and setters > ... > } > > The code for the RESTful Web Service is given below: > @Path("/ideal/") > public class IdealPaymentService { > @POST > @Path("/submitOrder/") > public Response submitOrder(OrderRequest orderRequest) throws URISyntaxException { > System.out.println("----invoking submitOrder" + orderRequest.toString()); > return Response.ok("http://www.google.com").build(); > } > } > > The service is published by JAXRSServerFactoryBean in the Spring context: > ... > <!-- Initialize JAXRSServer --> > <jaxrs:server id="restServices" address="/payment"> > <jaxrs:serviceBeans> > <ref bean="idealPaymentService" /> > </jaxrs:serviceBeans> > </jaxrs:server> > > <bean id="idealPaymentService" class="com.lycoseurope.cbp.ideal.restful.service.IdealPaymentService" /> > ... > > After the deployment, the service works perfectly, but the request is not correctly validated. I sent a request with a missing > confirmationURL, but I got no error message even though the confirmationURL has been specified as a mandatory XML element, which > is not nullable. > > On publishing a web service using JAX-WS, we could set the option "schema-validation-enabled" to true in the spring context to > turn on the input validation. Is there a similar property in JAX-RS to enable input validation? > > Thank you very much in advance. > > > > ---------------------------- IONA Technologies PLC (registered in Ireland) Registered Number: 171387 Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland ---------------------------- IONA Technologies PLC (registered in Ireland) Registered Number: 171387 Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
