Traffic Response - Save Download
Hello,
One of our endpoints streams back a Word document. The Response Headers include the Content-Disposition with the file name and the Content-Type is set to "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
I would like a groovy script to read the Content-Disposition and allow me to save the file off with the file name from Content-Disposition header.
I have tried the Write File Tool and the Word document is corrupt when I attempt to open it (The Write File works for PDFs however).
I have also added the Browse Tool and the browser will do the download, although the file extension is set to ".bin". I can change the file extension to a ".docx" and it works but this is a clumsy solution.
I spent a full day looking at different posts on Google to no avail. Can someone point me to a script for this?
Answers
-
You should use a header data bank to extract the value of the Content-Disposition header. Then you can chain a Write File tool and reference the data bank column in the "Target name" field using ${var_name} syntax. To make sure that the content is not treated as text, you should add that content type under Parasoft > Preferences > MIME Types and make sure that Text is not selected under Implied Types.
0 -
Thank you, that has gotten me to pretty much where I need to be. Would there be a way to get that header value from the header data back in a script and split the string value - and then make a variable available for the write file? The Content-Disposition has more data than just the file name.
0 -
You can reference Data Bank columns from a script using context.getValue("Generated Data Source", "columnName"). The data source name "Generated Data Source" is special, reserved for getting data bank values. The second argument is the name of the data bank column.
See Extensibility and Scripting Basics which has some examples.
0