I've figured out more information about the CXF XSD validation problems I was having.
After using Glen's "DoubleIt" example to demonstrate that incoming schema validation worked, I compared it to my project. It turns out CXF was disabling incoming schema validation if any xs:dateTime parameters were declared. I traced this to the org.apache.cxf.jaxb.io.DataReaderImpl class. DataReaderImpl has a special case where, if the class being read has an XMLGregorianCalendar field, then the object is unmarshalled in a different way, using the "unmarshalWithBridge" method instead of the "unmarshall" method. This unmarshalWithBridge method does not enforce XSD validation. So, CXF's incoming XSD validation is quietly disabled for any services that accept an xs:dateTime. You can work around this by binding the XML xs:dateTime type to a java.util.Date. After I applied this binding, inbound XSD validation worked OK. This kind of behavior sets kind of a weird precedent for anybody who's counting on CXF's annotations for XSD validation. If XSD validation can be accidentally disabled on a service-by-service basis, I guess that puts the responsibility on the developer to verify that inbound and outbound XSD validation is enabled for each individual service. - Aaron -----Original Message----- From: Pieper, Aaron [mailto:[email protected]] Sent: Tuesday, December 14, 2010 2:45 PM To: [email protected] Subject: RE: Enabling jaxws schema validation through CXF? Glen, I initially had some trouble where Tomcat 6.0.20 was being finicky deploying the war file, but Tomcat 6.0.29 did a better job, and I was able to get your example up and running. I then modified the WSDL so that "numberToDouble" and "doubledNumber" have numeric constraints, and it works, reporting incoming and outgoing validation errors properly. I can now use this validation example as a reference, to figure out why validation isn't being enabled properly in my project. Thanks! - Aaron -----Original Message----- From: Glen Mazza [mailto:[email protected]] Sent: Tuesday, December 14, 2010 12:58 PM To: [email protected] Subject: Re: Enabling jaxws schema validation through CXF? Hi Aaron -- might this blog entry help you: http://www.jroller.com/gmazza/entry/soap_xml_schema_validation Regards, Glen On 12/14/2010 12:46 PM, Pieper, Aaron wrote: > Hello, > > > > I am trying to enable incoming schema validation on a CXF endpoint. I > know this is a very common question. I am using CXF 2.3.0. I tried > adding the annotation to my web service, and I also tried the > "jaxws:properties" approach, modifying my cxf-servlet file. Both of > those approaches worked, kind of - but they only enable outgoing > validation. Incoming messages are still unvalidated, and I'm not sure > why. > > > > I'm 90% sure the problem is on my side, so my real question is - is > there one of the code samples in CXF which I can easily tweak to enable > validation, so that I can see how it's supposed to work? Or are there > any of the examples which already have validation enabled? The closest > thing I could find was the wsdl-first examples, which are a little > broken I think. > > > > The "wsdl_first_soap12" Client.java has a try/catch block which says > something along the lines of, "Invoking greetMe with invalid length > string, expecting exception..." but, the exception isn't thrown, and the > test passes anyways, since there's no "Assert.fail" in the try block. > > > > I also looked at the "wsdl_first" project because its cxf.xml had the > jaxws validation tags in it. The wsdl_first project didn't work out of > the box, because the pom.xml file referenced a "hello_world.wsdl" which > didn't exist. After fixing that, though, schema validation is still not > enabled - it seems like the "mvn -Pserver" sidesteps the cxf.xml > configuration file, the endpoint is configured in the > CustomerServiceServer.java file. > > > > What is the easiest way to get an example up and running with incoming > schema validation? I have been running most of the examples with the > "mvn -Pserver" approach which seems like it would not activate any of > the annotations or any of the CXF configuration files which trigger > validation. Do I have to modify one of the examples to enable XSD > validation, launch a standalone tomcat instance, build a war file, and > deploy the war file into that instance? Or is there a simpler way? > > > > Thanks, > > > > - Aaron > > > >
