Ask the Expert

Differentiating whether an incoming message is SOAP

I am writing an XML-based servlet that can receive general XML messages and also XML over SOAP. In the servlet I want to differentiate whether or not the incoming message is SOAP. Is that the best way to do it?

    Requires Free Membership to View

The easiest way would be to use XPATH to check the existence of the SOAP envelope element in the message. Or, instead of using XPath, you could look at the document element (getDocument()->getFirstChild() in DOM speak, IIRC) and see if it's <soap:envelope xmlns:soap="..."/>. If there's no envelope, there's no SOAP. Since, presumably, you've got to parse the message anyway, I'd wager that's a more convenient way.

That said, in SOAP 1.1, the SOAPAction HTTP header is supposed to be present, though it has no particular required value ("to express the intent of the message"). You might check your vendor's SOAP implementation to verify this. So, without parsing the message, one could simply check for the presence of the SOAPAction HTTP header. That's probably a little less fault-tolerant, but "officially" correct. In general, if it's present, you most likely have a SOAP message. If it's not present, then you should check the root element of the document).

In SOAP 1.2(XMLP), the media type may be "application/soap+xml", so that can be used as an indicator as well. However, as with SOAPAction, at least at this point in the XMLP design, the application/soap+xml media type is not required. So if it is missing (as with SOAPAction above), you would still have to check the root element of your XML message (presuming, of course, that your message is XML -- if not, well, that's a different matter).

This was first published in April 2003

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: