Forum Discussion

mtroost's avatar
mtroost
Occasional Contributor
10 years ago

[solved]Decoding an attachment of XOP (base64binary)

[edit] Ok, seems like someone sent a plain file along, not encoded at all. It was just a zip :S. The question is therefore not relevant anymore.

------------------------

 

The SOAP response I receive includes an attachment <xop:Include href="cid:3f38c9b5-83b1-49cb-ace3-4ed18eaff555%40null" xmlns:xop="http://www.w3.org/2004/08/xop/include"/>. This attachment is in binary and I need to turn it into regular XML again.

Disclaimer: I am a noob so i might leap to bizar conclusions and make assumptions that are wrong.

 

Based on this single attachment in binary I decided this is a base64binary encoded file. Because I dont know any better I thought a SOAPUI assertion might check it and meanwhile decode it so I can actually understand it as a human. Below is the assertion but it turns out to be doing not so great.

Using the simple "encodedString.decodeBase64()" wont work because it is not a string but binary data.

 

assert messageExchange.responseAttachments.length == 1
def atta = messageExchange.getResponseAttachments()[0]
log.info atta.getContentEncoding() 
assert atta.getSize() != 0
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
import org.apache.commons.codec.binary.Base64;
Base64 decoder = new Base64();

def eIS = atta.getInputStream()
def f = new File(groovyUtils.projectPath + "decoded");
f.delete();
def inp = new byte[1];
while (eIS.read(inp) != -1 ) { //EOF
	log.info "enc "+inp
	f << decoder.decode(inp)
	log.info "dec "+decoder.decode(inp)
}
log.info(groovyUtils.projectPath + "decoded");

 The execution of this yiled me this log

Tue Mar 17 22:40:30 CET 2015:INFO:binary
Tue Mar 17 22:40:30 CET 2015:INFO:enc [80]
Tue Mar 17 22:40:30 CET 2015:INFO:dec [0]
Tue Mar 17 22:40:30 CET 2015:INFO:enc [75]
Tue Mar 17 22:40:30 CET 2015:INFO:dec [0]
Tue Mar 17 22:40:30 CET 2015:INFO:enc [3]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [4]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [20]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [0]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [8]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [0]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [8]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [0]
Tue Mar 17 22:40:30 CET 2015:INFO:dec []
Tue Mar 17 22:40:30 CET 2015:INFO:enc [68]
Tue Mar 17 22:40:30 CET 2015:INFO:dec [0]
Tue Mar 17 22:40:30 CET 2015:INFO:enc [-104]

 At this point there pops up a dialoguebox titled "Error" with the content "-104". I am clueless as to what is happening and what an proper decoding from an attachment would be like.

No RepliesBe the first to reply