Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

How to download decrypted pdf document in Traffic response for get method call

Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭

Hi Team,

We are getting a pdf file in response as decrypted format for Get method call. There is no option to download the file in response.

Header :
Content-Disposition: attachment; filename="Temp.pdf"

Same service working fine in Postman and able to download the pdf document, please let us know the download option for Parasoft tool.

Regards
Udaya

Tagged:

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited January 2019

    In the past, I've seen users handle this with an Extension Tool chained to the tool's Response output. This seems to work:

    import com.parasoft.api.*
    import java.io.*
    import org.jvnet.mimepull.*
    
    void getAttachment(Object input, ScriptingContext context) {
        String inputStr = input.toString()
        String boundary = inputStr.substring(2, inputStr.indexOf('\r'))
        byte[] rawBytes = inputStr.getBytes("ISO-8859-1")
        MIMEMessage mimeMessage = null
        try {
            mimeMessage = new MIMEMessage(new ByteArrayInputStream(rawBytes), boundary)
            MIMEPart mimePart = mimeMessage.getPart(0)
            String contentDisposition = mimePart.getHeader("Content-Disposition").get(0)
            String fileName = contentDisposition.substring(contentDisposition.indexOf("filename=") + 9)
            mimePart.moveTo(new File("C:/somefolder/" + fileName))
        } finally {
            if (mimeMessage != null) {
                mimeMessage.close()
            }
        }
    }
    
    

    You'll can tweak this script as needed, like change which MIME part it is getting in the call to mimeMessage.getPart(int index), and change which file the attachment is written to.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭
    edited January 2019

    Thanks @benken_parasoft Do we have feature request in progress for this? If not, would be possible to create it? It would be easier to have as settings.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    Do we have feature request in progress for this?

    Yes. There's a long outstanding feature request (SOA-4428). For background, SOAtest has a tool called the Attachment Handler which was created for the SOAP Client (SOAtest) and Message Responder (Virtualize) for consuming multi-part SOAP payloads, implementing MTOM and SwA SOAP specifications. However, it isn't currently able to be used with other client tools.

  • reactancexl
    reactancexl Posts: 160

    Has this ever been resolved? 9.10.7 version?

  • jakubiak
    jakubiak Posts: 798 admin

    Unfortunately built-in support for this has not yet been added and there is no defined timeframe right now. A script like the one mentioned by @benken_parasoft should still be used.

Tagged