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

ParasofttoudayaParasofttoudaya Posts: 222 ✭✭

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_parasoftbenken_parasoft Posts: 658 ✭✭✭
    edited January 11

    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.

  • ParasofttoudayaParasofttoudaya Posts: 222 ✭✭
    edited January 12

    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_parasoftbenken_parasoft Posts: 658 ✭✭✭

    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.

Sign In or Register to comment.