I'm working on a REST service in SoapUI where I need to upload a .lzma file, unpack it, and then process the XML files inside to return different responses based on their content. However, I'm encountering an issue where the uploaded file gets corrupted when I try to save it as a first step. The file saves correctly but cannot be unpacked manually afterwards.
Here's what I've done so far:
Created a Mock Action and Response: I set up a mock action in SoapUI with a corresponding mock response.
Script for Saving the File: In the onRequest script, I'm saving the incoming file using the following Groovy script:
def requestContent = mockRequest.requestContent
new File("C:/test/new_container.tar.lzma").withOutputStream { it.write(requestContent.getBytes()) }
log.info "File saved successfully"
The file is saved, but it's corrupted. I can open it but not unpack it.
Upload Methods Tried:
Postman with Content-Type: application/octet-stream
cURL command:
curl -X POST -H "Content-Type: application/octet-stream" --data-binary @"C:\test\container.tar.lzma" http://localhost:8080/archive-service/send/archive
In all cases, the result is the same – the file gets corrupted. I'm looking for guidance on how to correctly receive and save this LZMA file without corruption. Any insights or suggestions on what might be causing this issue or how to resolve it would be greatly appreciated!
Thank you in advance!
there is an issue in your code mockRequest.requestContent returns content as a string when tar.lzma
is a binary file.
ideally the following code should work but it's not working (at least in soapui 5.4.0):
new File("/11/out.dat").withOutputStream {
it << mockRequest.getRawRequestData()
}
new File("/11/out.dat").withOutputStream {
it << mockRequest.getHttpRequest().getInputStream()
}
seems there is a bug in soapui
any POST
request transformed to a string (what is breaking real binary content)
even mockRequest.getRawRequestData()
returns bytes converted from a string.