I have a jaxws webservice with @SchemaValidation on it.
@SchemaValidation(handler = MySchemaValidationHandler.class)
@WebService(portName = "MyService", serviceName = "MyService", targetNamespace = "urn:com.my.urn", wsdlLocation = "/wsdls/mywsdl.wsdl", endpointInterface = "com.my.MyService")
@BindingType("http://schemas.xmlsoap.org/wsdl/soap/http")
public class MyServiceImpl
implements MyService {
@Resource
WebServiceContext wsContext;
public void myOperation(Holder<XMLGregorianCalendar> tag1, Holder<XMLGregorianCalendar> tag2, Holder<String> message) {
...
}
}
in xsd I have the following example:
<xsd:choice>
<xsd:element name="tag1" type="xsd:dateTime" minOccurs="0"/>
<xsd:element name="tag2" type="xsd:dateTime" minOccurs="0"/>
</xsd:choice>
When I send the request with empty tags, I get an error concerning the field format (doesn’t fit the restrictions of a date format).
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:com.my.urn">
<soapenv:Header/>
<soapenv:Body>
<urn:myOperation>
<Tag1>value1</Tag1>
<Tag2></Tag2>
</urn:myOperation>
</soapenv:Body>
</soapenv:Envelope>
In request description I have mandatory tags and choice tags and have to return the correct error message in the response, so I can’t just skip such errors in the handler.
Also I can’t modify nor xsd nor wsdl
Logically empty tags mean the same as missing tags. How can I make the validation treat empty tags as missing or how can I delete empty tags before the validation?
Thanks.
Edit: Don’t send invalid XML. In the example you give, you should remove
<Tag2></Tag2>in whatever your client code is. Don’t try to abuse the server’s validation to handle invalid XML.