CXF Schema Validation Example

CXF Schema Validation Example explains about How to validating wsdl/schema using CXF framework

How to enable schema validation on CXF SOAP requests and responses

How can I turn on schema validation for jaxws endpoint?‎

CXF is providing in built schema validation, so that we can define different rule on WSDL schema level and if the request/response is not satisfying according to the schema, an error is produced

It is very helpful because, we get error message very before than it need to validate on server side.

I am going to reuse  CXF Web Service Tutorial,Please see the project structure on below screenshot

CXF Schema Validation Example

Here we made only changes are inside cxf.xml we have added following tag for the CXF schema validation

<entry key="schema-validation-enabled" value="true"/> Also added wsdlLocation="WEB-INF/ChangeStudent.wsdl" in order to utilize contract first approach, please see the complete structure of cxf.xml below

Modify cxf.xml

<beans xmlns=""
	xmlns:xsi="" xmlns:jaxws=""
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<jaxws:endpoint id="changeStudent"
		implementor="com.student.ChangeStudentDetailsImpl" address="/ChangeStudent"
			<entry key="schema-validation-enabled" value="true" />

Here I am showing an example where reqeust need to be validated that student name length must be less than 10. please check the student complexType extracted from WSDL below

<xs:complexType name="student">
		<xs:element name="name">
				<xsd:restriction base="xs:string">
					<xsd:maxLength value="10" />

1 2 Next

Your email address will not be published. Required fields are marked *