I've added a couple of properties to AbstractJAXBProvider, for the output validation be enabled as well.
You need to have a schema location set on JAXBElementProvider. Next, if a 'validateOutput' boolean property is set then Marshaller will validate using the schema and possibly a registered ValidationEvenetHandler. If a 'validateBeforeWrite' property is also set then Marshaller will validate first and write only if the validation succeeds Will work for JSON too. I'll update the docs. What you can do right now is to extend JAXBElementProvider and override its createMarshaller method and set a Schema instance on it (which is initialized by JAXBElementProvider)... thanks, Sergey On Sat, Apr 9, 2011 at 4:17 PM, Sergey Beryozkin <[email protected]>wrote: > Hi > > Do you mean you'd like to prevent malformed XML being sent back, in case > when JAXB failed to finish the serializaton process ? The only option here > is to cash the response, use an "enableBuffering' and 'enableStreaming' > properties, see > > > http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-ConfiguringJAXBprovider > > thanks, Sergey > > On Sat, Apr 9, 2011 at 1:25 AM, wsdev <[email protected]> wrote: > >> Hi, >> >> I'm creating a RESTful service with CXF that creates a resource when the >> user POSTs some XML. The service works fine when the XML is valid, but >> when >> I send some bad XML, JAXB can't convert it to my java bean and sends back >> a >> 500 Internal Server error. How can I make it so that if bad XML is sent to >> my service, I capture it and send back a 400 Bad Request response. >> >> Any help is greatly appreciated!! >> >> Thanks, >> Steve >> >> -- >> View this message in context: >> http://cxf.547215.n5.nabble.com/JAXB-and-REST-Response-tp4292165p4292165.html >> Sent from the cxf-user mailing list archive at Nabble.com. >> > > > -- Sergey Beryozkin Application Integration Division of Talend <http://www.talend.com> http://sberyozkin.blogspot.com
