views:

183

answers:

1

I'm making a SOAP request with cfhttp due to SSL certificates to retrieve a document. We have limited access to the server, so I'm not sure if we can adjust the server to get the certificats added to the CF keystore. (http://www.coldfusionmuse.com/index.cfm/2005/01/29/keystore)

The responseBody returns a ByteArrayOutputStream which holds the content of the soap message and document contents (http://www.w3.org/TR/SOAP-attachments).

Does anyone know if ColdFusion provides any built in methods to separate the two, IE cast it into a ColdFusion.Response object of some sort which is the result of using cfinvoke, or do I need to dust off my Java books and iterate through the ByteArray to strip out my content. Thanks.

+1  A: 

Once you have the byte array (using the stream's toByteArray()) method?), you should be able to use the CharsetEncode() function to convert those bytes into a ColdFusion string. You'll probably have to cut up the MIME segments yourself. For the segment with the SOAP envelope, you can parse that with XmlParse() and deal with it appropriately. The segments containing the binary attachments you should be able to decode with BinaryDecode() (and then do whatever you need to with the resulting bits, like save to a file or database).

Sixten Otto
Thanks Sixten Otto - Any suggestions on cutting the MIME segments. Convert all to Text, look for segment regions, grab encoding type from the mime header, search for region footer, get start and stop points then go back to the BtyeArray and Read/Decode from start to stop points?Guess I'm a bit skeptic of getting accurate start, stop points in a text encoded format of binary data.
Steve
How will the encoding deal with the multiple mime headers, ie SOAP then Attachements. Guess I'm looking for a way to split the byteArray at the different mime type headers to encode each segment separately. ---- But since I'm not the first person trying to decode a SOAP response with attachments I was hoping for a cleaner solution
Steve
Sorry Sixten Otto - you can tell its a Monday. After splitting the Mime type we'll see how the BinaryDecode handles the string encoded segment. Binary to String, mid, to Binary should hopefully work.
Steve
Yeah, you should be fine: the whole point of the Base64 encoding that is almost certainly being used on the binary segments is to turn that data into a string that can safely be thrown around in ASCII (it's designed for really old mail servers, after all). So if you convert the overall response to a string using the encoding in the response headers, you should be fine. You really shouldn't have to (nor would you *want* to) try to parse out the segments in the byte array.
Sixten Otto