i want add 2 xsd files validation in payloadvalidatinginterceptor, i'm able add 1 xsd file under property schema, there way can add 2 or more xsd files validation.
assuming 2 xsd files have different namespaces, following:
1) extends class payloadvalidatinginterceptor
public class payloadvalidatinginterceptor extends payloadvalidatinginterceptor { private resourceloader resourceloader; private static final logger logger = logger.getlogger(this.getclass()); @override protected final source getvalidationrequestsource(webservicemessage webservicemessage_) { source _source = null; try { _source = webservicemessage_.getpayloadsource(); validateschema(_source); } catch (soapfaultclientexception _soapexception) { logger.error("soap fault " + _soapexception.getmessage(), _soapexception); } catch (exception _exception) { logger.error("exception " + _exception.getmessage(), _exception); } return _source; } private string getnamespace(final source source_) { domsource _currentdomsource = (domsource) source_; node _currentnode = _currentdomsource.getnode(); if (_currentnode != null) { string _currentnamespaceuri = _currentnode.getnamespaceuri(); // whatever need identifiy namespace } else { logger.warn("the namespace not recognized: " + _currentnamespaceuri); } } else { logger.warn("the current namespace not determined"); } return null; } private void validateschema(source source_) throws ioexception, saxexception { final string _namespace = getnamespace(source_); if (_namespace != null) { schemafactory _schemafactory = schemafactory.newinstance(xmlconstants.w3c_xml_schema_ns_uri); schema _schema = null; // based on identified namespace can choose appropriate xsd // example : _schema = _schemafactory.newschema(getschemas()[0].getfile()); validator _validator = _schema.newvalidator(); domresult _result = new domresult(); try { _validator.validate(source_, _result); } catch (saxexception _exception) { setfaultstringorreason(generic_error_message + " : " + _exception.getlocalizedmessage()); } } else { setfaultstringorreason(namespace_error_message); } } public final resourceloader getresourceloader() { return resourceloader; } public final void setresourceloader(resourceloader resourceloader_) { this.resourceloader = resourceloader_; } } 2) modify spring configuration adding following bean
<bean class="payloadvalidatinginterceptor" > <property name="schemas"> <array> <value>/web-inf/1.xsd</value> <value>/web-inf/2.xsd</value> </array> </property> <property name="addvalidationerrordetail" value="false"/> <property name="validaterequest" value="true"/> <property name="validateresponse" value="false"/> </bean>
Comments
Post a Comment