Java. Validate SOAP message against a WSDL
NickName:David Portabella Ask DateTime:2011-09-02T17:49:16

Java. Validate SOAP message against a WSDL

I need to validate a SOAP message against a WSDL? (in the same way that an XML file can be validated against a XSD schema).

I am not calling any webservice; I just have a SOAP message and a WSDL, and I need to verify that the SOAP message is correct. without calling the webservice or whatsoever afterwards.

I need to make this validate within a Java program. Do you know of a small Java library to do this?

ps: I am aware that several JAX-WS libraries can validate the request/response when you call a webservice. But again, I am not calling any webservice; I have a simple SOAP message, and a WSDL, and I a need a function that validates the SOAP message against the WSDL.

ps: I am also aware that there tools that can do this, such as SOAPUI and XMLSpy. Again, I need to do this validation within my Java program.

ps: I am aware that I could extract the body part of the SOAP message, and validate it against the XSD. However, I'd like to validate the entire SOAP message against the WSDL.

Copyright Notice:Content Author:「David Portabella」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/7281755/java-validate-soap-message-against-a-wsdl

Answers
Ren 2012-01-05T21:48:28

If you are creating a webservice client using a code generator based on Apache CXF or Apache Axis 2 , Chances are high that your webservice code should work just fine as long as both the webservice provider and your client are in the same version of SOAP/WS* standards .Based on the API you choose to invoke the webservice you can see whether the logging capability of that API can be used to print out the SOAP request generated . \n\nAnother approach could be to use a tool like SOAPUI. You could try to setup a mock webservice using SOAP UI based on the WSDL you have and then call test your webservice client by calling the mock service . See SOAP UI Link here http://www.soapui.org/Getting-Started/web-service-sample-project/1-Web-Service-Mocking.html ",


explorer 2011-09-19T17:20:12

You can create a stub using the WSDL you have and then make the query to the stub using your XML request. If this goes properly your request is correct. \n\nYou can import the WSDL in your project and then make a call to the stub service using your XML. This way you can make changes to the validations without any change in the code.",


Srijit 2012-11-01T21:15:58

Try this\n\n\nUse the WSDL and create a Jax-RPC proxy\nCreate a webservice JAX RPC handler and register it to the webservice reference\nPlease refer this link to see howto create webservice handlers\nIn the handler, try the below code\nin the public boolean handleRequest(MessageContext mc) add these lines\n\nmc.setProperty(\"USE_TEST_FILE\", <your response in .xml file>);\nreturn false;\n\nIn the public boolean handleResponse(MessageContext mc)\n\nString testFileName = (String) mc.getProperty(\"USE_TEST_FILE\");\nInputStream instream = <read file as an input stream>\nSOAPMessageContext smc = (SOAPMessageContext) mc;\nSOAPMessage message = smc.getMessage();\nSOAPPart soapPart = message.getSOAPPart();\nsoapPart.setContent(new StreamSource(instream));\nsmc.setMessage(message);\nreturn false;\n\n\n\nnow run your proxy.. the proxy will fail if the message is not valid per WSDL",


Ryan Ransford 2011-09-02T18:46:04

I think that you may be looking for an answer which is way too complex for what you really need. All you really need to do is have the appropriate DTD/XSD documents registered so that the normal JAXP classes can reference them.\n\nThis code, from Sun/Oracle, implements a basic EntityResolver. You need to build this class such that it will provide the DocumentBuilder with the appropriate InputSources for the schema defined in the documents you are trying to validate.\n\nimport org.xml.sax.EntityResolver;\nimport org.xml.sax.InputSource;\n\npublic class MyResolver implements EntityResolver {\n public InputSource resolveEntity (String publicId, String systemId) {\n if (systemId.equals(\"http://www.myhost.com/today\")) {\n // return a special input source\n MyReader reader = new MyReader();\n return new InputSource(reader);\n } else {\n // use the default behaviour\n return null;\n }\n }\n}\n\n\nUsing this code, you can pull in your custom EntityResolver and have it used during the parsing/validation of the document.\n\nfinal DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();\ndbf.setNamespaceAware = true;\ndbf.setValidating = true;\nfinal DocumentBuilder db = dbf.newDocumentBuilder();\nfinal MyResolver r = MyResolver.newInstance();\ndb.setEntityResolver(r);\nfinal Document docFromFile = db.parse(\"path/to/my/document.xml\");\n// or\nfinal Document docFromStream = db.parse(new FileInputStream(\"blah\"));\n",


Paperback Writer 2012-11-29T13:32:37

As SOAP message is xml, you can validate whole message against xsd. For example I found this schema for SOAP message. You could:\n\n\nExtract schema from your wsdl,\nValidate message against schema from wsdl and soap schema.\n\n\nShould you want to validate against specific WSDL, you can prepare you schema by hand: just place root element of your message instead of this part:\n\n<xs:sequence>\n<xs:any namespace=\"##any\" minOccurs=\"0\" maxOccurs=\"unbounded\" processContents=\"lax\"/>\n</xs:sequence>\n\n\nin SOAP schema.",


ThomasRS 2016-10-29T21:42:07

Validate against the SOAP envelope schema, then extract body and headers and validate against specific schema. Should be simple enough.",


BPS 2012-12-28T14:17:50

You might look at the source code for the WsdlValidator class in the open-source soapUI project.\n\nhttps://github.com/SmartBear/soapui\n\nhttp://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/support/wsdl/WsdlValidator.html",


More about “Java. Validate SOAP message against a WSDL” related questions

Java. Validate SOAP message against a WSDL

I need to validate a SOAP message against a WSDL? (in the same way that an XML file can be validated against a XSD schema). I am not calling any webservice; I just have a SOAP message and a WSDL, ...

Show Detail

How to validate a SOAP request against a WSDL (yes, WSDL, not XSD), in ruby

I have, in the context of a SOAP request, a WSDL a bunch of XSDs, referenced by the WSDL an example SOAP request I would like to validate that the SOAP request fits the WSDL and all the XSDs. I am

Show Detail

Validate SOAP message against WSDL

Just like validating an XML file against an XML Schema Definition in Java is there a way to validate an XML file that contains a SOAP Envelope against a WSDL file?

Show Detail

Validating SOAP message against WSDL with multiple XSD's

I've been looking around the net for a good few hours now, trying to find a simple way to validate a full SOAP message against a WSDL. I am aware that there are ways to do this with the various Web

Show Detail

php soap client validate against wsdl

I have a problem with validation of my web services against the wsdl file. I use php with Laravel 5.2 framework, and i have to create a Soap web server. I've put the server and client class in a

Show Detail

Validate jaxws soap request against schema inside wsdl:types

I'm wanting to validate a soap request against the schema inside this wsdl. &lt;wsdl:types &gt; &lt;xsd:schema targetNamespace="http://ws.thecompany.com/FormSubmissionService20100824" ...

Show Detail

Validate an incoming SOAP request to the WSDL in PHP

The built-in PHP extension for SOAP doesn't validate everything in the incoming SOAP request against the XML Schema in the WSDL. It does check for the existence of basic entities, but when you have

Show Detail

How can i validate a SOAP message with a WSDL file?

when we receive a SOAP message, then we Resolve it, then we have a TEXT like: &lt;soap:Envelope&gt; &lt;soap:Body&gt; &lt;GetDNS&gt; &lt;xx&gt;1&lt;

Show Detail

How to Validate a SOAP Payload Request XML and SOAP Response XML against WSDL using .Net core 3.1?

I am receiving the SOAP Request XML which need to be validated against the WSDL. Also, SOAP Response XML should be validated against the WSDL using the .Net core 3.1 version

Show Detail

Java, Validate XML against an embedded schema in WSDL

I have a .wsdl file with an embedded schema. I want to validate an XML file/string using that .wsdl file (the same way you would validate against an .xsd). The schema is between the &lt;types&gt; t...

Show Detail