flogiston

Blog

Coldfusion Soap using CFHTTP

· admin · Coldfusion

We just finished debugging a CF app that uses CFHTTP to communicate with a SOAP service.

Finding bits and pieces of debugging tips accross the net we managed to track down the issue.

The problem:

It started with the message "The processing instruction target matching "[xX][mM][lL]" is not allowed."

Following the suggestion in this link: http://forums.sun.com/thread.jspa?threadID=694303&messageID=4033694

we trimmed the response using trim(cfhttp.fileContent). That helped. Kinda.

We got a different message: "Content is not allowed in prolog".

Following the suggestion in this link:
http://www.stillnetstudios.com/2007/07/09/coldfusion-xml-prolog-error/

we removed the UTF-8 BOM using

<cfif Asc(Left(cfhttp.fileContent,1)) EQ 65279>
	<cfset returnedXML = Right(cfhttp.fileContent,Len(cfhttp.fileContent)-1)>
</cfif>

But, alas, that didn't solve our problem.

Changing the encoding from "UTF-8" to "utf-8" as someone suggested in this link

http://www.judahfrangipane.com/blog/?p=53

didn't solve the problem either.

So we wrote out the cfhttp.fileContent. It actually returned "Connection Failure".

That was very odd, because if we called the same service using PHP we got a response.

Nothing else to do but take a look at the response headers.


<cfoutput>
cfhttp.charSet:#cfhttp.charSet#<br/>
cfhttp.errorDetail:#cfhttp.errorDetail#<br/>
cfhttp.mimeType:#cfhttp.mimeType#<br/>
cfhttp.statusCode:#cfhttp.statusCode#<br/>
cfhttp.text    :#cfhttp.text#<br/>
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="5">
<TR><TH>Key</TH><TH>Value</TH></TR>
<CFLOOP COLLECTION=#CFHTTP.ResponseHeader# ITEM="Key">
<CFSET Value = CFHTTP.ResponseHeader[Key]>
<CFIF IsArray(Value)>
<CFLOOP INDEX="i" FROM=1 TO=#ArrayLen(Value)#>
<CFOUTPUT>
<TR><TD>#key#</TD><TD>#value[i]#</TD></TR>
</CFOUTPUT>
</CFLOOP>
<CFELSE>
<CFOUTPUT><TR><TD>#Key#</TD><TD>#value#</TD></TR> </CFOUTPUT>
</CFIF>
</CFLOOP>
</TABLE>

The responseHeader struct was empty, but the cfhttp.errorDetail gave a valid clue:

The message was "I/O Exception: Not in GZIP format"

Back to google. In this thread

http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:57029

someone suggested to add the following two request headers:


<cfhttpparam type="header" name="Accept-Encoding" value="*" />
<cfhttpparam type="Header" name="TE" value="deflate;q=0" />

Now we finally were getting somewhere. Adding these two headers gave back the soap envelope in the cfhttp.fileContent.

Lo and behold. Inspection of this uncompressed xml revealed that it was incomplete. The envelope wasn't properly closed because the response was interupted. So all we had to do was contact the provider of the SOAP service to resolve the issue.

In hindsight I should have detected the incomplete response already when I checked the php version. But it was a huge response and badly formatted. That's my excuse :-)