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.

Responder with MIME type application/pdf

bhargavy
bhargavy Posts: 3

Hello,
I want to add new responder to my virtual asset that returns application/pdf but I don't see the MIME type application/pdf available. Not sure if I am missing something. Please let me know if anyone handled a response of type application/pdf from parasoft.

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,302 ✭✭✭
    edited November 2020

    but I don't see the MIME type application/pdf available

    I notice that only textual MIME types are listed here. The "MIME type" selection is only present when "Text" is selected which is why it only lists textual media types. To send a binary file like a pdf you need to pick File instead.

    You can configure the HTTP "Content-Type" header on the Transport Header tab.

  • benken_parasoft
    benken_parasoft Posts: 1,302 ✭✭✭
    edited November 2020

    You may also consider posting your question to the Virtualize forum next time.

  • williammccusker
    williammccusker Posts: 672 ✭✭✭

    Hi,

    How are you providing the pdf file that is being sent back in the response? If you are using a "file" to provide the pdf then you could set a custom HTTP header to indicate the desired mime type.

  • bhargavy
    bhargavy Posts: 3

    @williammccusker @benken_parasoft
    Thanks for your response. My requirement a little different. I want to return the base64 format of the pdf in response instead of the pdf itself. The next layer would encode the base64 message and generate pdf. Do you think I should select a different MIME type other than application/pdf in my case?

  • benken_parasoft
    benken_parasoft Posts: 1,302 ✭✭✭
    edited November 2020

    I want to return the base64 format of the pdf in response instead of the pdf itself.

    Is the entire response payload just a base64 encoded pdf? Or is the pdf base64 encoded within an XML element or JSON String? Depending on the situation, you may need to script the response. If you were to script the response, you could use java.util.Base64.getEncoder().encodeToString(bytes) from a Groovy script, for example. If your response is XML or JSON, and described by a service definition or schema that indicates which elements are binary, then the Form Input or Form JSON view will provide controls to select the file and base64 the contents automatically.

    Do you think I should select a different MIME type other than application/pdf in my case?

    What MIME type does the service you are virtualizing actually return? I suspect it isn't application/pdf if it is not the raw pdf but something else that contains a base64 encoded version of the pdf.

  • bhargavy
    bhargavy Posts: 3

    @benken_parasoft My problem is solved with your simple solution! I just needed to configure the Content-Type in Transport Header tab. Thanks so much.