Forum Discussion

senthkum's avatar
senthkum
Contributor
6 years ago

Send PDF as a response in ServiceV pro?

Hi Team,

 

I have a requirement where I need to send everytime the same PDF as a response. It is a REST service, Could some one help me, Where can I attach the file and continue the testing in serviceV Pro.

Note: I am not talking about SOAPUI or SOAPUI Pro.

 

Thanks

Senthil kumar.M

    • senthkum's avatar
      senthkum
      Contributor

      Hi Tanya,

       

      All the info in there are related to SOAP service, but I am working on REST Service and I do not find a way to attach the PDF file and test it. It's been more than 2 weeks i am stuck with this issue. 

      Why is that, there is no attachment properties for a REST service, it would have been more easy. 

      can you help me with the code or is there any other simpler way to attach a file. The below code did not work.

       

      // get the path to the folder where your project resides.
      def projectPath = new File(context.mockService.project.path).parent
      // Specify the file path that is relative to the project’s path.
      def fileName = projectPath + "\\response\\abcd.pdf"
      log.info "CABIS-MOCK send response with file: " + fileName
      
      import java.io.FileInputStream
      import java.io.File
      
      File f = new File(fileName)
      FileInputStream fis = new FileInputStream(f)
      byte[] b = new byte[f.length()]
      requestContext.mockResponse.responseContent = f.text

       

      Thanks

      Senthil kumar. M