Service Virtualization

Expand all | Collapse all

POST Body in Rest

  • 1.  POST Body in Rest

    Posted May 10, 2017 07:17 AM

    Good Afternoon Sirs,

     

    I'm trying to create a VS image from rrpairs in DevTest version 8.5, the request is a POST request  with a json body like a following file:

     

    POST /api/peticiones HTTP 1.1

    Content-Type: application/json

    {"data":{"age": "15", "name":"Rich"}}

     

    Devtest by default puts the body content in the URL as parameters like a GET request, changing the url depending

    the body content.

     

    In the example the result is:

    POST: /api/peticiones?data_age=15&data_name=Rich

     

    but the request is a POST, and I want to keep the POST request without the parameters and without changing the URL.

    Just, keeping the same URL and choosing the differents responses by the body not changing the URL.

     

    Is there any possibility to do this?

    Best regards.

    Jonathan.



  • 2.  Re: POST Body in Rest

    Posted May 11, 2017 12:06 PM

    Hi Jonathan,

     

    What is the data protocol you were using for this ?

     

    Use JSON 2.0 and you will not face this issue.

     

    Thanks,

    Venkatesh Satturi



  • 3.  Re: POST Body in Rest

    Posted May 12, 2017 06:05 AM

    Thanks for your help,

    But in the version 8.5 there isn´t JSON 2.0 only JSON.

    The protocol is HTTPS.

    In a new version this problem its solved?



  • 4.  Re: POST Body in Rest

    Posted May 16, 2017 09:34 AM

    In your RR pair, is there a blank line between the header information and the payload?



  • 5.  Re: POST Body in Rest

    Posted May 17, 2017 06:20 AM

    Yes, there is a blank line between the header and the payload. 

     

    Sorry, I was wrong to copy.

    This is the POST:

     

    POST /api/peticiones HTTP 1.1

    Content-Type: application/json

     

    {"data":{"age": "15", "name":"Rich"}}



  • 6.  Re: POST Body in Rest

    Posted May 17, 2017 06:55 AM

    Can you give post a request and a response so that we can try this for ourselves?



  • 7.  Re: POST Body in Rest

    Posted May 17, 2017 07:18 AM

    The url is always the same. Only change the body content.

    http://devtest:9530/maiviewer/api/datos-expedientes

     

    Request one:

    POST /maiviewer/api/datos-expedientes HTTP 1.1

    Content-Type: application/json

     

    {"data":{"policy": "555129482","codCliente": "0","name": "PHOENIXTEST","idioma": "tn"}}

    Response one:

    OK1

     

    Request two:

    POST /maiviewer/api/datos-expedientes HTTP 1.1

    Content-Type: application/json

     

    {"data":{"policy": "77733783","codCliente": "0","name": "PHOENIXTEST","idioma": "tn"}}

    Response two:

    OK2



  • 8.  Re: POST Body in Rest

    Posted May 17, 2017 07:20 AM

    Can I assume that your response file contains the 200 OK header lines etc?



  • 9.  Re: POST Body in Rest

    Posted May 17, 2017 07:25 AM

    yes, of course.



  • 10.  Re: POST Body in Rest

    Posted May 17, 2017 07:02 AM

    Hi Jonathan ,

     

    I dont have any lower version to test this. I use 9.5.1 and this works perfectly fine for me with JSON 2.0.

    With your version, If you don't want to add the parameters to URI and compare them with incoming request you can use REST Data protocol.

     

    Try using generic xml payload parser if you want both attribute matching and not adding them to URI because in lower versions of Devtest json is converted to XML first and then parsed. (Not completely sure though. try and let me know if this works.)

     

    Thanks,

    Venkatesh



  • 11.  Re: POST Body in Rest

    Posted May 17, 2017 07:24 AM

    Hi,

     

    In this version the JSON is converted to XML is truth. But, if i use REST DATA PROTOCOL, the attribute are adding to the URI... i want not to that happen

     

    thanks



  • 12.  Re: POST Body in Rest

    Posted May 17, 2017 07:38 AM

    Hi,

     

    I tried in Devtest Version 8 using JSON as a data protocol. The arguments didn't get added to the URI and they can be compared with incoming request.

     

    This should solve your problem. let me know if you still face any issues.

     

    Thanks,

    Venkatesh



  • 13.  Re: POST Body in Rest

    Posted May 17, 2017 09:20 AM

    could you send me your project to my email, please? 
    Because the paremeter get added to the URI, and the data protocol is JSON.



  • 14.  Re: POST Body in Rest
    Best Answer

    Posted May 17, 2017 09:44 AM

    Given a request named j1-req.txt which contains 

    POST /api/peticiones HTTP 1.1

    Content-Type: application/json

     

    {"data":{"age": "15", "name":"Rich"}}

     

    and a response of j1-rsp.txt which contains 

    HTTP/1.1 200 OK

     

    J1 OK

     

    This works. Assuming that the RR pair is held in Data here is the vrs file corresponding to the recording session 

     

    <?xml version="1.0" ?>

    <RecordingSession nonLeaf="WIDE" leaf="LOOSE" asObject="true">
    <Protocol type="com.itko.lisa.vse.stateful.protocol.rrpairs.VSFromRRPairsTransportProtocol">
    <Transport allAreStateless="false" asObject="true" desensitize="false" duptxns="false">
    <exportFile></exportFile>
    <RequestSide>
    <Protocol type="com.itko.lisa.vse.stateful.protocol.json.JSONDataProtocolHandler">
    </Protocol>
    </RequestSide>
    </Transport>
    <rrDir>{{LISA_RELATIVE_PROJ_ROOT}}/Data</rrDir>
    <transportProtocol>
    <Protocol type="com.itko.lisa.vse.stateful.protocol.http.HttpProtocolHandler">
    <Transport allAreStateless="false" asObject="true" desensitize="false" duptxns="false">
    </Transport>
    <listenPort>8001</listenPort>
    <targetHost>localhost</targetHost>
    <targetPort>80</targetPort>
    <useGateway>true</useGateway>
    <hostHeaderPassThrough>false</hostHeaderPassThrough>
    <ssl toClient="false" sslClientAuthType="none" toServer="false"/></Protocol>
    </transportProtocol>
    </Protocol>
    </RecordingSession>



  • 15.  Re: POST Body in Rest

    Posted May 17, 2017 09:48 AM

    I'm sorry, I'll not be able to upload or send an email as it triggers policy violation.

     

    try creating your request file like below, create an image using request response pairs , JSON data protocol. 

     

    POST /api/peticiones HTTP/1.1
    Content-Type: application/json

     

    {
    "data":{"age": "15", "name":"Rich"}
    }



  • 16.  Re: POST Body in Rest

    Posted May 18, 2017 11:41 AM

    Hi,

    For REST- POST method with rr pair, use soap data protocol only. Use rr pair without header information.

     

    You will he able to create vsi vsm. Update your response from XML format to text format(use settings icon to update the format type) and paste your expected json response in response section.

     

    Header information can be provided manually for request and response.

     

    Thanks.