An API GET response returns an image in the body, like this: This is not an attachment.
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Sat, 06 May 2017 15:32:05 GMT
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: max-age=0
X-Content-Type-Options: nosniff
X-XSS-Protection: 1
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: image/jpeg
Content-Length: 12888
ÿØÿà JFIF ` ` ÿáÈExif MM * 2 J; ^GF GI ? ‡i
f Æ2009:03:12 13:48:28 Corbis ? œ? °’‘ 17 ’’ 17
2008:02:11 11:32:43 2008:02:11 11:32:43 ( $
œ ` ` ÿØÿÛ C
$.' ",#(7),01444'9=82<.342ÿÛ C
2!!2 ...... and so on.
Postman decodes the image an displays it, it is an animal in this case.
I have to store the response as an image file (.jpg) using a groovy script in soapUI(soapUI is used to test the API)
This is what I've tried in a Groovy Script step, but the image saved is unintelligible malformed.
testRunner.runTestStepByName("GETjpg");
def getImageResponse = new String(testRunner.testCase.testSteps["GET Image"].testRequest.response.responseContent);
byte[] imageInByte;
BufferedImage originalImage = ImageIO.read(new ByteArrayInputStream(getImageResponse.getBytes()));
// convert BufferedImage to byte array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(originalImage, "jpg", baos);
baos.flush();
imageInByte = baos.toByteArray();
baos.close();
// convert byte array back to BufferedImage
InputStream inRead = new ByteArrayInputStream(imageInByte);
BufferedImage bImageFromConvert = ImageIO.read(inRead);
ImageIO.write(bImageFromConvert, "jpg", new File("C:\\animal.jpg"));
I guess that what I am doing to save the image in .jpg is not correct. Can someone help?
Attach is the raw response.
Thanks in advance.