Question

I am developing a Web service using Apache CXF and contract first approach with schema validation. Problem is, that validation is not working. There is no error, so it like is not activated. But validation is configured.

So, I have took a look to official Apache CXF examples you can find here.

I took a look to wsdl_first example and modify it adding schema validation and some restriction in WSDL:

<!-- HTTP Endpoint -->
<jaxws:endpoint xmlns:customer="http://customerservice.example.com/"
    id="CustomerServiceHTTP" address="http://localhost:9090/CustomerServicePort"
    serviceName="customer:CustomerServiceService" endpointName="customer:CustomerServiceEndpoint"
    implementor="com.example.customerservice.server.CustomerServiceImpl">

    <jaxws:features>
        <bean class="org.apache.cxf.feature.LoggingFeature" />
    </jaxws:features>
            <!-- schema validation-->
    <jaxws:properties>
        <entry key="schema-validation-enabled" value="true" />
    </jaxws:properties>
</jaxws:endpoint>

To my surprise, it doesn't work either.

OK, so I took a look to wsdl_first_xmlbeans example, where according with the README.txt file, it also shows how CXF configuration can be used to enable schema validation.

And for this example, schema validation works. The difference between both examples is that the second one use JAX-WS APIs and with the XMLBeans approach. Does it have something to do? Why schema validation is not working for first example? Probably, I am missing something.

Was it helpful?

Solution

For validation on the service side, it would likely need to have a wsdlLocation attribute set on the jaxws:endpoint so it would load the WSDL (that would then contain the schemas). Currently, the validation in that example is on the client side only. If you run the service, the log shows:

INFO: Creating Service {http://server.customerservice.example.com/}CustomerServiceImplService from class com.example.customerservice.CustomerService

which shows it's not using the WSDL at all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top