Project

Profile

Help

validate an incoming SOAP message

Added by Anonymous about 15 years ago

Legacy ID: #7321699 Legacy Poster: Orjan Lundberg (oluies)

Hi, I have a requirement to (1) validate an incoming SOAP message where the (2) the XSD is stored in a properitary repository server (IBM WSRR). The validation (1) is where I have questions, I have no problem of doing (2) against an XML Instance that contains a schemaLocation, but in a SOAP instance there is seldom any schemaLocations i believe... Thanks, Orjan Example LSResourceResolver WSRR code used together with main... Resolver resolver = new Resolver(); // create a validator to validate against grammar sch. Validator schemaValidator = schemaGrammar.newValidator(); schemaValidator.setResourceResolver(resolver); schemaValidator.setErrorHandler(handler); class Resolver implements LSResourceResolver { public LSInput resolveResource(String type, String namespace, String publicId, String systemId, String baseURI) { byte[] schema = getSchemaFromWSRR(namespace); LSInput ret = new DOMInputImpl(); try { String s = new String(schema,"UTF-8"); ByteArrayInputStream bs= new ByteArrayInputStream(schema); ret.setByteStream(bs); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return ret; } private byte[] getSchemaFromWSRR(String namespace) { try { WSRRCoreSDOClient serviceRegistry = connectServiceRegistry(); // Example code to retrieve myXmlSchema.xsd with a version string of "2.0" // Assuming we don't already know the bsrURI of the required XSD document we // need to run a property query. PropertyQuery propertyQuery = (PropertyQuery)DataFactory.INSTANCE.create(TypeConstants.SR_URI, TypeConstants.TYPE_PROPERTYQUERY); String xpath = "/WSRR/XSDDocument[@namespace='"+namespace+"']"; propertyQuery.setQueryExpression(xpath); // We only need the "bsrURI" of the XSDDocument BSRSDOHelper.INSTANCE.addProperty(propertyQuery, "prop1", "bsrURI"); System.out.println(" running query " + xpath); List results = new LinkedList(); results = serviceRegistry.executeQuery(propertyQuery); propertyQuery = null; //The result size should be 1. System.out.println(" result size = " + results.size()); PropertyQueryResult result = (PropertyQueryResult)results.get(0); String myXmlSchemaDocumentBsrUri = null; myXmlSchemaDocumentBsrUri = BSRSDOHelper.INSTANCE.getPropertyQueryResultValue(result, "bsrURI"); // Example code to retrieve myXmlSchema.xsd with a version string of "2.0" // given its bsrURI System.out.println(" retrieving schema for " + namespace +" from the repository"); XSDDocument myXmlSchemaDoc = (XSDDocument)serviceRegistry.retrieve(myXmlSchemaDocumentBsrUri); return myXmlSchemaDoc.getContent(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }


Replies (3)

Please register to reply

RE: validate an incoming SOAP message - Added by Anonymous about 15 years ago

Legacy ID: #7321816 Legacy Poster: Michael Kay (mhkay)

It's not clear to me what your question/problem is. Presumably you want to use the Saxon schema validator, or you wouldn't be asking here? Which Saxon API are you using to invoke the validation? Assuming you're using s9api, you need to load the relevant schema documents into the cache maintained by the SchemaManager, and then call newSchemaValidator(), which will then be equipped to validate an instance against the schema you have loaded. That leaves the question of how to load the schema from the "IBM WSRR" repository - I'm afraid that I have no knowledge of this software product so I can't help you with it.

RE: validate an incoming SOAP message - Added by Anonymous about 15 years ago

Legacy ID: #7321920 Legacy Poster: Orjan Lundberg (oluies)

Hi, I have no problem with the WSRR interaction. The problem is that I do not know what schema is used prior to recieving the document. So all I have is the namespaces in the incoming XML Instance (soap env). And Based on your answer I understand that I have to look in the XML instance referenced namespaces, load the appropriate xsd documents into the schema validator, and then call validate. I thought there would be a way to register a resolver into saxon that automatically is called for all referenced namespaces needed for validation. Thanks, Örjan

RE: validate an incoming SOAP message - Added by Anonymous about 15 years ago

Legacy ID: #7322133 Legacy Poster: Michael Kay (mhkay)

>I thought there would be a way to register a resolver into saxon that automatically is called for all referenced namespaces needed for validation. Well, you can register such a resolver (Configuration.setSchemaURIResolver()), but it's only invoked when someone asks to load a schema, and that doesn't happen simply because you're validating a source document and find a new namespace. I guess you could put a filter between the XML parser and the validator that looks at the namespace of each element, and calls this hook if no schema for that namespace is currently available. I'm not sure how well this would work - you'd have to try it. (Could be difficult to manage things like wildcards with processContents="skip").

    (1-3/3)

    Please register to reply