Hi
It will be fixed shortly as part of enhancing the default JAXB-based message body providers (XML and JSON), such that additional
properties can be used during the JAXBContext creation.
In meantime there's always a workaround available : copy&paste the existing JAXBElement message body provider, add required bean
setters (liek setProperties() or setEnableValidation) and configure your custom provider as needed from Spring. In JAX-RS it's
tricky to enable such a property at a jaxrs:server element level as there could be a number of data bindings involved at the same
time (perhaps a bit hypothetic but still feasible), all of which have their own ways to enable the validation, so such a property
has to be set on a message body provider level...
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