Contributions
Re: Add a pdf as an attachment for a mock response
Got the solution.Here you go: import com.itextpdf.text.Document import com.itextpdf.text.Paragraph import com.itextpdf.text.pdf.PdfWriter import org.apache.commons.io.IOUtils def headers = mockResponse.responseHeaders Document document = new Document(); File file = new File("response.pdf") FileOutputStream fos= new FileOutputStream(file) PdfWriter pdfWriter = PdfWriter.getInstance(document, fos); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add("Hello groovy!"); document.add(paragraph); document.close() fos.close() try { def httpResponse = mockRequest.httpResponse FileInputStream fis= new FileInputStream(file); OutputStream outputStream = httpResponse.getOutputStream() IOUtils.copy(fis,outputStream) fis.close() outputStream.close() } catch (Exception e){ log.info "error" } mockRequest.httpResponse.addHeader("Content-Type", "application/pdf") mockRequest.httpResponse.addHeader("Content-Disposition", "attachment;filename="+file)8 years agoPlace ReadyAPI QuestionsReadyAPI Questions10KViews1like0CommentsRe: Add a pdf as an attachment for a mock response
import com.itextpdf.text.Document import com.itextpdf.text.Paragraph import com.itextpdf.text.pdf.PdfWriter Document document = new Document(); File file =new File("HelloWorld1.pdf") PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add("Hello World!"); document.add(paragraph); document.close(); mockResponse.contentType=file.toString() def headers = mockResponse.responseHeaders headers["Content-Disposition"]=["attachment; filename="+file()] headers["Content-Type"]=["application/pdf"] when i try to dispose this file in the response, its giving me 0 bytes, where as normally, it creates a file with the content TanyaYatskovska8 years agoPlace ReadyAPI QuestionsReadyAPI Questions10KViews0likes3CommentsAdd a pdf as an attachment for a mock response
I am reading a file from my system and i need to send it as a pdf attachment in my mock response. I am using ready api. Can any body give me advice please? I have tried the below code and when the request is made, the pdf is downloaded but it fails to load it on the browser. String filename='C:/soapui.log' File file = new File(filename); def headers = mockResponse.responseHeaders headers["Content-Type"]=["application/pdf"] headers["Content-Disposition"]=["attachment.pdf"] mockResponse.responseHeaders=headers How do i return a file as a pdf,which i am reading in from my system Any suggestions please? Thank youSolved10KViews0likes8Comments