Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although semantically correct, I believe Nathan's proposed solution is somewhat incomplete.</p> <p>I guess he forgot do Base64 decode the extracted text prior to step 1. I would also include an improvement so that no human intervention is needed by verifying the temporary file using 3rd party ZIP utilities. </p> <p>That would translate into accessing the temporary ZIP file and checking whether it's a valid ZIP file. Therefore, an algorithm for implementing your requirement would be:</p> <ol> <li>Access element Base64-encoded text content and Base64 decode it</li> <li>Output ZIP raw text into a temporary file, thus creating a ZIP file</li> <li>Check if the temporarily created ZIP file is valid</li> </ol> <p>With all that in mind, here's how the complete Groovy script would look like:</p> <pre><code>import org.apache.commons.codec.binary.Base64 // Step 1: Access element Base64-encoded text content and Base64 decode it String tempZipFilename = "temp.zip" def textBase64 = context.expand( '${Step#Request#//ns2:getInputConfigFilesResponse[1]/return[1]}' ) def b64 = new Base64() def zipTextBytes = b64.decode(textBase64.getBytes()) // Step 2: Output ZIP raw text into a temporary file def zipFile = new java.io.File(tempZipFilename) FileOutputStream fos = new java.io.FileOutputStream(zipFile) fos.write( zipTextBytes ) fos.flush() fos.close() log.info "Temporary ZIP file stored as: ${zipFile.getCanonicalPath()}" // Step 3: Check if the temporarily created ZIP file is valid boolean responseValid try { zipFile = new java.util.zip.ZipFile(tempZipFilename) responseValid = true log.info "Number of files in the ZIP file: ${zipFile.size()}" } catch (java.util.zip.ZipException e) { responseValid = false log.error "The received response contains a bad ZIP" } log.info "Web service response is " + (responseValid ? "valid" : "invalid") </code></pre> <p>Please let me know if this works for you as it does for me. :-)</p> <p>Cheers!<br/> Shonzilla</p> <p>p.s. I would suggest adding "ZIP" tag to this question so that people can more easily find a solution for handling ZIPs from Groovy that's embedded here.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload