restfilegroovysoapuilzma

File Corruption Issue When Uploading LZMA File via REST Service in SoapUI


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:

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:

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!


Solution

    1. there is an issue in your code mockRequest.requestContent returns content as a string when tar.lzma is a binary file.

    2. 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()
    }
    
    1. then i tried following - but it works only for PUT request:
    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)

    https://github.com/SmartBear/soapui/blob/next/soapui/src/main/java/com/eviware/soapui/impl/support/AbstractMockRequest.java#L93

    enter image description here

    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