Forum Discussion

junaidgill's avatar
junaidgill
New Contributor
6 years ago

Saving contents of a gzipped Http Post request coming into SoapUI

I am receivng a gzipped HTTP Post request in SoapUI. My task is to save the zipped contents into a file using groovy script.

 

Here is how my groovy script looks like:

import java.nio.file.*

String userDir = context.expand('${projectDir}');

println userDir;

File dir = new File(userDir, "resm");
dir.mkdirs();

File file = new File(dir, "http_post.gz");
file.createNewFile();

Files.copy(new ByteArrayInputStream(mockRequest.requestContent.bytes),
Paths.get( 'http_post.gz') );

 

It doesn't save any file for me.

Secondly, I don't know where I can see the output of println in SoapUI environment.

  • junaidgill's avatar
    junaidgill
    New Contributor

    I think I found at least one of the issues i.e. in the last line. It should be Paths.get(dirString + "/" + file.getName()).

    So the latest script looks like this:

    import java.nio.file.*

    String userDir = context.expand('${projectDir}');

    println userDir;

    File dir = new File(userDir, "resm");
    dir.mkdirs();

    File file = new File(dir, "http_post.gz");
    file.createNewFile();

    Files.copy(new ByteArrayInputStream(mockRequest.requestContent.bytes), Paths.get( dir.toString() + "/" + file.getName() ) );

     

    If the input contents are plain text then this script works fine but now for gzipped contents.

    Any help is much appreciated here.