CXF Schema Validation Example

please see the complete structure of ChangeStudent.wsdl below

ChangeStudent.wsdl

<?xml version="1.0" ?>
<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://student.com/"
	xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http"
	name="ChangeStudentDetailsImplService" targetNamespace="http://student.com/">
	<wsdl:types>
		<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
			xmlns:tns="http://student.com/" elementFormDefault="unqualified"
			targetNamespace="http://student.com/" version="1.0">
			<xs:element name="changeName" type="tns:changeName"></xs:element>
			<xs:element name="changeNameResponse" type="tns:changeNameResponse"></xs:element>
			<xs:complexType name="changeName">
				<xs:sequence>
					<xs:element minOccurs="0" name="arg0" type="tns:student"></xs:element>
				</xs:sequence>
			</xs:complexType>
			<xs:complexType name="student">
				<xs:sequence>
					<xs:element name="name">
						<xsd:simpleType>
							<xsd:restriction base="xs:string">
								<xsd:maxLength value="10" />
							</xsd:restriction>
						</xsd:simpleType>
					</xs:element>
				</xs:sequence>
			</xs:complexType>
			<xs:complexType name="changeNameResponse">
				<xs:sequence>
					<xs:element minOccurs="0" name="return" type="tns:student"></xs:element>
				</xs:sequence>
			</xs:complexType>
		</xs:schema>
	</wsdl:types>
	<wsdl:message name="changeName">
		<wsdl:part element="tns:changeName" name="parameters">
		</wsdl:part>
	</wsdl:message>
	<wsdl:message name="changeNameResponse">
		<wsdl:part element="tns:changeNameResponse" name="parameters">
		</wsdl:part>
	</wsdl:message>
	<wsdl:portType name="ChangeStudentDetails">
		<wsdl:operation name="changeName">
			<wsdl:input message="tns:changeName" name="changeName">
			</wsdl:input>
			<wsdl:output message="tns:changeNameResponse" name="changeNameResponse">
			</wsdl:output>
		</wsdl:operation>
	</wsdl:portType>
	<wsdl:binding name="ChangeStudentDetailsImplServiceSoapBinding"
		type="tns:ChangeStudentDetails">
		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http"></soap:binding>
		<wsdl:operation name="changeName">
			<soap:operation soapAction="" style="document"></soap:operation>
			<wsdl:input name="changeName">
				<soap:body use="literal"></soap:body>
			</wsdl:input>
			<wsdl:output name="changeNameResponse">
				<soap:body use="literal"></soap:body>
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	<wsdl:service name="ChangeStudentDetailsImplService">
		<wsdl:port binding="tns:ChangeStudentDetailsImplServiceSoapBinding"
			name="ChangeStudentDetailsImplPort">
			<soap:address location="http://localhost:8080/CXFTutorial/ChangeStudent"></soap:address>
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

Now deploy the project and run the below client and see the output

You need CXF client example in order to run this service

Output

Here we are sending Student name as 'Rockey', response will be 'Hello Rockey' is more than 10 character long, so we get the exception regarding length is not satisfied according to given WSDL

WARNING: Interceptor for
{http://student.com/}ChangeStudentDetailsImplService#{http://student.com/}changeName has thrown exception, 
unwinding now org.apache.cxf.interceptor.Fault:Marshalling Error: cvc-maxLength-valid: Value 'Hello Rockey' 
with length = '12' is not facet-valid with respect to maxLength '10' for type '#AnonType_namestudent'.

 

If we are sending Student name as 'Ramu', we get correct response as 'Hello Ramu' because the length of name is satisfied now.

 





Previous 1 2








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