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.
- Comparing Files: The saved file has the same size in bytes as the original, but the checksums and the byte content are different(though the bytes are almost identical).
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
- Changing Content-Type to application/x-lzma in two previous methods
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.lzmais a binary file.ideally the following code should work but it's not working (at least in soapui 5.4.0):
seems there is a bug in soapui
any
POSTrequest transformed to a string (what is breaking real binary content)https://github.com/SmartBear/soapui/blob/next/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockRequest.java#L93
even
mockRequest.getRawRequestData()returns bytes converted from a string.https://github.com/SmartBear/soapui/blob/next/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockRequest.java#L261