Service Virtualization

Expand all | Collapse all

How to create stub response with pdf attachment?

  • 1.  How to create stub response with pdf attachment?

    Posted Dec 17, 2016 06:27 AM

    Hello Friends,

     

    I got one requirement in which we want to attach one PDF file with response in VSI (Virtual Service Image). After that when we will test that service with SOAP ui, we want that stubbed response with attachment.

     

    Please help me in this on urgent basis as it is impacting our work.

     

    Thanks in advance.

     

    Shivam Garg



  • 2.  Re: How to create stub response with pdf attachment?
    Best Answer

    Posted Dec 21, 2016 12:17 AM

    Hi Shivam, 

     

       It is very simple, you just need to convert your PDF to binary format and copy and past the binary content to virtual response. 

     

     

    To convert the pdf file to binary content, follow the steps for work around. 

     

    1.  Create a new response on SI and change the response type to Graphical Image. 

     

    Change response to Graphic Image

     

    2. Upload the pdf file to the virtual response by click "Load from File" button from the response panel. 

    Select PDF

     

    3. After you select you will get the screen as shown below, meaning you have uploaded the wrong file type but you are still fine with the message

     

    4. Now change the response format to Graphic Image to Binary. 

     

    5. Once you change to binary format the virtual response will be as shown below. 

     

    6. Change the character encoding to ISO-8859-9

     

    7. Save the service image. 

     

     

    Now change the response content type  PDF. To do that change the Content-Type attribute on the response meta-data.  

     

     

    I have tested it from the Postman I can see the binary response. 

     

    If the test the same request from the browser I can see the PDF. 

     

     

    Hope this helps, 

     

    Vamsi Kurukuri | CA Technologies | Service Architect



  • 3.  Re: How to create stub response with pdf attachment?

    Posted Dec 21, 2016 06:33 AM

    Hello Vamsi,

     

    thanks for your response. It was very helpful. But Now one more issue, I have configured binary code with response and testing using SOAP UI, I am getting response with attachment. I am able to download attachment from SOAP UI but I am not able to see content inside it while original pdf is having content.

     

    Can you please help in this also?

     

    Thanks in advance.

     

    Shivam Garg



  • 4.  Re: How to create stub response with pdf attachment?

    Posted Dec 22, 2016 09:22 AM

    Hi.  I had the same issue.  You need to save the pdf as a fdf file.  Then it will work.  Example: "filename._pdf_.fdf".  Adobe reader reads fdf as well.



  • 5.  Re: How to create stub response with pdf attachment?

    Posted Dec 22, 2016 09:29 AM

    Hello Hart,

     

    Thank you so much for your reply.

     

    But still it is not working. I have renamed it with .fdf extension but still not able to see content of pdf. I am giving name like ****.fdf. Is it correct?

     

    Please give me any other solution. It is very urgent.

     

    thanks..

    Shivam



  • 6.  Re: How to create stub response with pdf attachment?

    Posted Dec 22, 2016 09:35 AM

    Let me look into the virtual service I created and get back to you.



  • 7.  Re: How to create stub response with pdf attachment?

    Posted Dec 22, 2016 09:42 AM

    Hello Hart,

     

    ------=_Part_3_30345399.1413353227843
    Content-Type: text/xml; charset=utf-8
    Content-Transfer-Encoding: 8bit
    Content-ID: <rootpart@soapui.org>

     

    <Response XML>

     

    ------=_Part_3_30345399.1413353227843
    Content-Type: application/pdf
    Content-Transfer-Encoding: binary
    Content-ID: <CA303B5BB1B9090AFBE6A5D3CFEDAC45>

     

    and in response meta data, I am using below.

     

    Content-Type: multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_3_30345399.1413353227843"

     

    please check if I am doing any mistake here. Also provide me screen shot of how we can test same thing in CA Lisa test case. I will be thankful to you if you will come to me asap and will resolve this issue. I am doing lot of searching round this from last 3 days but not getting any luck.

     

    Thanks in advance

     

    Shivam Garg



  • 8.  Re: How to create stub response with pdf attachment?

    Posted Dec 22, 2016 10:21 AM

    Shivam,

    Hi,

    Make sure you have the response meta data set to :

    Content-Type

     

    application/pdf

     

     

    Make sure you imported the pdf with the file extension “.fdf” and follow the exact instructions as outlined in the proposed solution.

     

    I just did that again and my virtual service works fine.  I suggest opening up a ticket, with CA Support, and they will help you.  They are very good and within a short period of time you will be up and running.

     

    Also see attached screen shots as that might be helpful.

     

     

    Tom Shokite



  • 9.  Re: How to create stub response with pdf attachment?

    Posted Dec 22, 2016 10:33 AM

    Hello Tom,

     

    thanks for your reply. I will do that what you suggested.

     

    I raised ticket to CA support but they are saying the version I am using is out of support. So they can not help.

     

    I would suggest if you can put some screen shot from your end , screen shots of steps, that will be helpful.

     

    thanks...



  • 10.  Re: How to create stub response with pdf attachment?

    Posted Dec 23, 2016 10:36 AM

    Hello Vamsi,

     

    Thanks for screen shot it sorted out issue to maximum extent. But it is not solving exact requirement. Requirement is that , we want this attachment with soap response and I am using below code in response body. and it is giving attachment in SOAP UI tool. But I am facing two problems:

     

    1. When I am testing using SOAP UI tool, I am getting response with attachment , but when I am opening attachment I am not able to see content of pdf file. It is showing as blank.

     

    2. When I am testing same service using CA Lisa test case then I am getting binary code only not pdf attachment in response.

     

    Your help is must. Please reply. Waiting for your reply.

     

     

    **********************************************************************Response Body******************************************

    ------=_Part_3_30345399.1413353227843
    Content-Type: text/xml; charset=utf-8
    Content-Transfer-Encoding: 8bit
    Content-ID: <rootpart@soapui.org>

     

    <Response XML>

     

    ------=_Part_3_30345399.1413353227843
    Content-Type: application/pdf
    Content-Transfer-Encoding: binary
    Content-ID: <CA303B5BB1B9090AFBE6A5D3CFEDAC45>

     

    and in response meta data, I am using below.

     

    Content-Type: multipart/related; type="text/xml"; start="<rootpart@soapui.org>"; boundary="----=_Part_3_30345399.1413353227843"



  • 11.  Re: How to create stub response with pdf attachment?

    Posted Dec 23, 2016 10:15 PM

    Hi Shivam, 

     

       I am on vacation so my response are little late,  can you please send me your sample SOAP response. 

     

    Thanks,

    Vamsi 



  • 12.  Re: How to create stub response with pdf attachment?

    Posted Dec 24, 2016 02:49 AM

    Thanks you so much for your reply.

     

    Oh so sorry I am disturbing you on vacation. Please get sample request and response XMLs. PDF attachment you can use any one from your system.

     

    Request XML:

     

    <soapenv:Envelope xmlns:soap="http://www.lloydstsb.com/Schema/Infrastructure/SOAP" xmlns:ifw="http://www.lloydstsb.com/Schema/CommunicationDispatch/IFW" xmlns:commn="http://www.lloydstsb.com/Schema/Enterprise/IFWXML_Communication" xmlns:ri="http://www.lloydstsb.com/Schema/Enterprise/IFWXML_ResourceItem" xmlns:com="http://www.lloydstsb.com/Schema/Enterprise/IFWXML_Common" xmlns:typ="http://g1.com/service/doc1gen/types" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Header/>
       <soapenv:Body>
          <typ:CompositionRequest>
             <typ:key>ATTACHMENT</typ:key>
             <typ:publicationName>LBGDOCUMENTATIONSUMMARY</typ:publicationName>
             <typ:data dataRef="cid:printXML"/>
          </typ:CompositionRequest>
       </soapenv:Body>
    </soapenv:Envelope>

     

    Response XML:

     

    <soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
          <ns1:CompositionResult xmlns:ns1="http://g1.com/service/doc1gen/types">
             <ns1:key>ATTACHMENT</ns1:key>
             <ns1:elapsedTime>1671</ns1:elapsedTime>
             <ns1:attachmentType>
                <ns1:alias>output1</ns1:alias>
                <ns1:data dataRef="cid:CA303B5BB1B9090AFBE6A5D3CFEDAC45"/>
                <ns1:content>document</ns1:content>
             </ns1:attachmentType>
          </ns1:CompositionResult>
       </soapenv:Body>
    </soapenv:Envelope>

     

     

    I am pasting binary code in with this response with line of codes as mentioned in previous post. Please sort out this problem and suggest around two issues I mentioned in previous post.

     

    Thanks again.

     

    Merry Xmas..



  • 13.  Re: How to create stub response with pdf attachment?

    Posted Dec 28, 2016 04:48 AM

    Hello Vamsi,

     

    Hope you have enjoyed your Xmas holiday. Have you got time to look into this?

     

    Thanks...

    Shivam Garg



  • 14.  Re: How to create stub response with pdf attachment?

    Posted Jan 03, 2017 03:18 PM

    I am just back from my vacation , I will look into this issue and get back to you by today evening. 

     

     

    Thanks,

    Vamsi 



  • 15.  Re: How to create stub response with pdf attachment?

    Posted Jan 04, 2017 04:14 AM

    Hello Vamsi,

     

    Hope you enjoyed your vacations.

    Thanks for looking into this. I will wait for your response and timely help.



  • 16.  Re: How to create stub response with pdf attachment?

    Posted Jan 05, 2017 03:23 AM

    Hi Shivam, 

     

     You have to create the virtual service response as multi-part response.   The first part will be the SOAP response and second part will be PDF attachment. 

     

    See the below sample response content, the key part is 'Content-Transfer-Encoding' , there are three types of encoding you can use  base64, binary, and 8bit. If you encode your pdf into binary the specify 'Content-Transfer-Encoding' as 'binary' or the pdf is encoded with base64 then specify' Content-Transfer-Encoding' as 'base64'.  I

     

    I have tested it and it is working file

     

    --MIME_boundary
    Content-Type: text/xml; charset=UTF-8
    Content-Transfer-Encoding: 8bit
    Content-ID: <myclaim.xml@ca.com>

    <?xml version='1.0' ?>
    <SOAP-ENV:Envelope
    xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body>
    <theSignedForm href="cid:myclaim.pdf@ca.com"/>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    --MIME_boundary
    Content-Type: application/pdf
    Content-Transfer-Encoding: base64
    Content-ID: <myclaim.pdf@ca.com>

     

    //Add PDF as base64 bit encoded string. 

     

    --MIME_boundary--

     

     

    Add the following paraments to response meta data. 

     

    Content-Type :  Multipart/Related; boundary=MIME_boundary; type="text/xml"; start="<myclaim.xml@ca.com>"

    Content-Description : [Add some desctiption]

    MIME-Version : 1.0

     

     

    On SOAP-UI , I get the SOAP response with attachment and I can open it successfully. 

     

     

     

    hope this helps,

     

    Thanks,

    Vamsi 



  • 17.  Re: How to create stub response with pdf attachment?

    Posted Jan 05, 2017 04:33 AM

    Thanks Vamsi. That is really helpful.

     

    I will try with same thing with Binary encoding. can you tell me how to encode it with base 64, please?

     

    thanks again.



  • 18.  Re: How to create stub response with pdf attachment?

    Posted Jan 05, 2017 10:53 AM

    It is pretty simple, on the DevTest workstation , create a new test. 

     

    1.  Add Base64 Encoder Step 

     

     

    2.  Load the pdf file and click on load button to generate the Base64 encoded string, then copy and past it to virtual response. 

     

     

    Thanks,

    Vamsi Kurukuri



  • 19.  Re: How to create stub response with pdf attachment?

    Posted May 25, 2017 02:13 PM

    Hi, Can anyone share the sample project which downloads pdf ? 

     

    Thanks,

    Anna



  • 20.  Re: How to create stub response with pdf attachment?

    Posted Apr 03, 2018 05:45 AM

    Hi Vamsi, I have tried as per your comments above and getting below error when tested. Could you please help me out. Thanks in Advance.

     

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Body>
    <soapenv:Fault>
    <faultcode>soapenv:Server.userException</faultcode>
    <faultstring>java.io.IOException: End of stream encountered before final boundary marker.</faultstring>
    <detail>
    <ns1:stackTrace xmlns:ns1="http://xml.apache.org/axis/">java.io.IOException: End of stream encountered before final boundary marker.
    at org.apache.axis.attachments.BoundaryDelimitedStream.read(BoundaryDelimitedStream.java:308)
    at org.apache.axis.attachments.BoundaryDelimitedStream.read(BoundaryDelimitedStream.java:358)
    at com.sun.mail.util.BASE64DecoderStream.getByte(BASE64DecoderStream.java:358)
    at com.sun.mail.util.BASE64DecoderStream.decode(BASE64DecoderStream.java:249)
    at com.sun.mail.util.BASE64DecoderStream.read(BASE64DecoderStream.java:144)
    at java.io.FilterInputStream.read(Unknown Source)
    at org.apache.axis.attachments.ManagedMemoryDataSource.&lt;init&gt;(ManagedMemoryDataSource.java:146)
    at org.apache.axis.attachments.MultiPartRelatedInputStream.readTillFound(MultiPartRelatedInputStream.java:557)
    at org.apache.axis.attachments.MultiPartRelatedInputStream.readAll(MultiPartRelatedInputStream.java:433)
    at org.apache.axis.attachments.MultiPartRelatedInputStream.getAttachments(MultiPartRelatedInputStream.java:439)
    at org.apache.axis.attachments.AttachmentsImpl.mergeinAttachments(AttachmentsImpl.java:174)
    at org.apache.axis.attachments.AttachmentsImpl.getContentLength(AttachmentsImpl.java:455)
    at org.apache.axis.Message.getAttachmentSize(Message.java:684)
    at com.itko.lisa.ws.axis.LisaHTTPSender.doInvoke(LisaHTTPSender.java:650)
    at com.itko.lisa.ws.axis.LisaHTTPSender.invoke(LisaHTTPSender.java:274)
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
    at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
    at org.apache.axis.client.Call.invokeEngine(Call.java:2837)
    at org.apache.axis.client.Call.invoke(Call.java:2820)
    at com.itko.lisa.ws.nx.NxWSStep.executeCall(NxWSStep.java:383)
    at com.itko.lisa.ws.nx.NxWSStep.execute(NxWSStep.java:287)
    at com.itko.lisa.ws.nx.ui.NxWSStepEditor$6.run(NxWSStepEditor.java:599)</ns1:stackTrace>
    <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">VPCAUMWHW70320</ns2:hostname>
    </detail>
    </soapenv:Fault>
    </soapenv:Body>
    </soapenv:Envelope>



  • 21.  Re: How to create stub response with pdf attachment?

    Posted Nov 07, 2017 11:58 AM

    Hi ,

     

    I have a similar requirement. First of all I want to know how to create the virtual service response as multi-part response.

    I have SOAP response along with Binary data, which should load as attachment at UI. 

     

    Thanks,

    Venu