I'm testing a wsdl
file via SoapUI
and want to send byte[]
of a pdf file to client. byte[]
are received at client side, but the created pdf file is blank. Below is what I have done :
SoapUI response script :
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
byte[] pdfBytes = new File(groovyUtils.projectPath + "//file1.pdf").text.getBytes( 'UTF-8' )
requestContext.pdfBytes = pdfBytes.encodeBase64()
Java code :
byte[] bytes = getFileFromServer();
File f = new File(filePath);
try {
FileOutputStream fileOuputStream = new FileOutputStream(f);
fileOuputStream.write(bytes);
fileOuputStream.close();
} catch (FileNotFoundException e) {
LOG.error("FileNotFoundException", e);
} catch (IOException e) {
LOG.error("IOException", e);
}
By using decode, the created file is damamged :
bytes = Base64.decodeBase64(bytes);
Any idea?
This is the problem - or at least a problem:
new File(groovyUtils.projectPath + "//file1.pdf").text
You're loading a binary file as if it's text. It's not. Don't read it as text and then convert it to byte - use
byte[] pdfBytes = new File(groovyUtils.projectPath + "//file1.pdf").bytes
See more on this question at Stackoverflow