Service Virtualization

Expand all | Collapse all

How to create a virtual service that contains multipart / form-data

Jump to Best Answer
  • 1.  How to create a virtual service that contains multipart / form-data

    Posted 01-10-2018 09:35 AM

    I need to create a virtual service HTTP protocol with multipart / form-data, I've tried using the rest data format to create a virtual service that does not recognize the parameters.

    the message is as follows:
    POST / Tibserver / HomeReceiver HTTP / 1.1
    Pragma: no-cache
    Cache-Control: no-cache
    lisaFrameRoot: true
    lisaFrameID: b3ee8ca0-f137-11e7-a0e4-00e0ed2ebb32
    Content-Type: multipart / form-data; boundary = - AhMMLcbyRtCwVCyAA_dIxh0rCjuNcrix
    Content-Length: 1684
    Connection: Keep-Alive
    User-Agent: Mozilla / 5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident / 5.0)

    ---- AhMMLcbyRtCwVCyAA_dIxh0rCjuNcrix
    Content-disposition: form-data; name = "xmlhead"

    <? xml version = "1.0" encoding = "UTF-8" standalone = "yes"?> <InterBOSS> <Version> 0100 </ Version> <TestFlag> 0 </ TestFlag> <BIPType> <BIPCode> BIP2B971 < BIPCode> <ActivityCode> T2140971 </ ActivityCode> <ActionCode> 1 </ ActionCode> </ BIPType> <RoutingInfo> <OrigDomain> BOSS </ OrigDomain> <RouteType> 00 </ RouteType> <Routing> <HomeDomain> PBSS </ HomeDomain> <RouteValue> 997 </ RouteValue> </ Routing> </ RoutingInfo> <TransInfo> <SessionID> PBSS20180104181455000045207279 </ SessionID> <TransIDO> HZ20180104181455207280 </ TransIDO> <TransIDOTime> 20180104181200 </ TransIDOTime> <TransIDH> 201801041812009535293433 < / TransIDH> <TransIDHTime> 20180104181200 </ TransIDHTime> </ TransInfo> <SNReserve> <TransIDC> 2000110320180104181200811307034 </ TransIDC> <ConvID> 31843248-cbea-470f-973b-ab7a92ef19cc </ ConvID> <CutOffDay> 20180104 </ CutOffDay> <OSNTime> 20180104181200 </ OSNTime> <OSNDUNS> 2000 </ OSNDUNS> <HSNDUNS> 9970 </ HSNDUNS> <MsgSender> 2001 </ MsgSender> <MsgReceiver> 0600 </ MsgReceiver> <Priority> 93 </ Priority> <ServiceLevel > 91 </ ServiceLevel> </ SNReserve> <Response> <RspType> 0 </ R spType> <RspCode> 0000 </ RspCode> <RspDesc> ...... </ RspDesc> </ Response> </ InterBOSS>
    ---- AhMMLcbyRtCwVCyAA_dIxh0rCjuNcrix
    Content-disposition: form-data; name = "xmlbody"

    <? xml version = "1.0" encoding = "UTF-8" standalone = "yes"?> <InterBOSS> <SvcCont> <! [CDATA [<? xml version = "1.0" encoding = "UTF-8"?> <SyncInfo> <Queryinfo> <OprNum> 2001BIP2B97020180104181455060197 </ OprNum> <QueryOprNum> 2001BIP2B96920180104154700210149 </ QueryOprNum> <Supervisor> asdad </ Supervisor> <Date> 20180104 </ Date> <Result> 01 </ Result> <Reason> < / Reason> </ Queryinfo> </ SyncInfo>]]> </ SvcCont> </ InterBOSS>
    ---- AhMMLcbyRtCwVCyAA_dIxh0rCjuNcrix--


    <?xml version="1.0" encoding="UTF-8"?>

  • 2.  Re: How to create a virtual service that contains multipart / form-data
    Best Answer

    Posted 01-10-2018 04:26 PM

    Given the content in your sample, I do not believe there is an OOTB approach.

    I would examine the possibility of creating a custom DPH. The overridden updateRequest( ... ) methods in a custom DPH provide access to the lisa_vse_request object.


    The custom code might use the instance of the incoming Request object to execute .getMetaData().get("Content-Type") . A regex might be used to pull out the boundary value from the Content-Type.


    Get the Request's body and use the boundary as a mechanism for locating the header and body XMLs.

    Iterate over the body and substring the data between the boundary (minus the Content-disposition: form-data; filenames, CRLFs, ending boundary, etc.).


    Repeat the process until the entire Body has been parsed since the example has a header boundary and a body boundary (i.e., two files).


    There are some additional issues that the custom code needs to take care of:

    - Both the header and body XMLs in your example have an XML prolog (e.g., <? xml version ...?>) so the prolog from the body XML needs to be stripped. 

    - In the example, perhaps not in the real content, the XML end element tag contains a blank (e.g., </ InterBoss>) so these need to be cleaned up for the SAX parser.

    - If your requirement includes the XML inside the CDATA, the customization needs to remove the CDATA tags and the XML prolog. It may also be necessary to clean up the end element tags here as well.

    - It is likely that you will need to wrap the XMLs with a different element tag since both the header and body contain <InterBOSS></InterBOSS>. Or, remove the first </InterBOSS> tag from the header and let the one on the Body close the XML.


    If you can get the customization to parse this, set the parsed and cleaned XML content back into the Request object's  body.

    As for DPHs,

    - add the custom DPH first since it sets the XML back into the body,

    - then add an XML DPH to parse the combined XML into an ArgList for the VSI.

    - Add other DPHs (RDM DPH or others) to clean up the payload as necessary. 


    The attached shows how the content might look after the DPH executes.


  • 3.  Re: How to create a virtual service that contains multipart / form-data

    Posted 08-17-2018 05:36 PM

    Hi Joel,


    We have a requirement where we need to send the response based on the different values coming in the multipart/form-data. In the below example based on the filename we need to send the response. I see the "------=_Part_0_1069863891.1534533580490" value in the lisa.vse.http.current.transaction.body


    com.itko.lisa.vse.http.HTTPTransaction[method=POST, uri=/api/rest/v5/transientDocuments, httpVersion=1.1, headers=Accept-Encoding=gzip,deflate&Content-Type=multipart/form-data; boundary="----=_Part_0_1069863891.1534533580490"&MIME-Version=1.0&Content-Length=292791&Host=mdr01vsels:9000&Connection=Keep-Alive&User-Agent=Apache-HttpClient/4.1.1 (java 1.5), request content=
    Content-Type: application/pdf; name="Epic 1 - Activity Flow Diagram.pdf"
    Content-Transfer-Encoding: binary
    Content-Disposition: form-data; name="Epic 1 - Activity Flow Diagram.pdf"; filename="Epic 1 - Activity Flow Diagram.pdf"