Service Virtualization

Expand all | Collapse all

"404 not found" error while sending request to REST api virtual service , method GET

Jump to Best Answer
  • 1.  "404 not found" error while sending request to REST api virtual service , method GET

    Posted 04-19-2018 10:45 AM

    Hi,

     

    I have created a virtual service using request response pairs for rest api , method id GET.  In Virtual service image operation name is populated as -

     

    /api/retrieveId/{URLPARAM0} and arguments have parameter - URLPARAM0 with value 12.

     

    When I try to send request to above virtual service through REST step -

     

    http://hostname:port/api/retrieveId/{URLPARAM0} or http://hostname:port/api/retrieveId/12.

     

    I am getting error - The requested URL was not found on this server. (404) which is unable to match stateless request.

     

    I also tried by sending URLPARAM0 value in query parameters but no luck. Also when I tried by having only operation name as /api/retrieveId/ . I can receive response. So it means that URLPARAM0 value is not resolve during requestcall.

     

    Can anybody suggest a way to call these GET REST api ? is there somethings needs to be chnaged while sending request ?

     



  • 2.  Re: "404 not found" error while sending request to REST api virtual service , method GET
    Best Answer

    Posted 04-19-2018 02:02 PM

    You need to make some changes during the generation process, not during the replay ...

     

    Firstly, examine the request message in your request-response pair. Look at the first line. If the first line reads

    GET http://hostname/api/retrieveId/12 HTTP/1.1

    Then that's contributing to your problem. The request message was generated incorrectly - we want base path there, not URL.

     

    You fix this by opening the listen step in your VSM file, and changing the base path in there, so you don't get a 404 error. You could change that to "/api/" so any api requests are dealt-with, or "/api/retrieveId/" so only retrieveId messages are dealt-with, or "/" so all requests are dealt-with.

     

    Your other problem with generating 404s is that your operation name needs to be made more generic. Add the Request Data Manager to your list of data protocol handlers. You want to copy the attribute "http-sequence-2" (or something - whatever points to "retrieveId" ) to your operation name. This will mean that any request to retrieveId will be matched, and your URLPARAM0 (perhaps you can change this during generation to a better name, such as {retrieveId} ) will determine whether you have an exact or a signature match.