CXF and Validation - Schema Restrictions Ignored
Asked Answered
B

2

5

I've been working on a CXF web service and have had some trouble. With the help of SO, I've got my service validating against a fairly complex schema- a requirement of the project. I've noticed some weird issues with the validation, however.

While datatypes are validated- eg, a random alphanumeric string instead of a date is caught and returned as a SOAP fault- length and pattern restrictions aren't. If an xs:string has a maxLength of 20 set, and I enter 25 'a's, the service is happy to oblige.

I'm using 2.2.7-SNAPSHOT- I'm stuck with a non-release because of another issue in 2.2.6 that the snapshot addresses. Anyone have any ideas? I've posted more details on the project in my other questions, but let me know if config files or output would help.

Barra answered 9/2, 2010 at 19:16 Comment(0)
Y
6

We chatted on IRC, but for recording purposes, the solution is to provide a wsdlLocation attribute on the jaxws:endpoint so that the original wsdl (and thus schemas) get picked up. Without that, it's validating against the schema that jaxb would generate from the classes. Since JAXB doesn't record the lenght facets and such, those would be "lost" and thus wouldn't be validated.

Yogurt answered 10/2, 2010 at 19:42 Comment(1)
12 years after the answer, was still useful after spending a few hours on it. Thanks!Embitter
C
1

The accepted answer was the lead to my solution, I could not provide the wsdl as this would class with the generated code. However I was able to provide the schema locations through the endpoint and that also solved my issue.

        List<String> schemaLocations = new ArrayList<>();
        schemaLocations.add("random0.xsd");
        schemaLocations.add("random1.xsd");
                schemaLocations.add("CustomSOAPFault_1p0.xsd");
        endpoint.setSchemaLocations(schemaLocations);
Callahan answered 26/8, 2022 at 13:29 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.