Forum Discussion

simrit's avatar
simrit
Occasional Visitor
7 years ago

adding filters in service v pro

Hi Team,

How do i add filters in Service V PRo 

i am using request response xmls

depending on some parameter in the request the response varies . I need to filter that one parameter from the request xml

could you please help with this

1 Reply

  • jhanzeb1's avatar
    jhanzeb1
    Frequent Contributor

    Hi, 

     

    Late reply though I hope it can help others.

     

    Here is what you can do, you can store the request node or content in a variable (custom property) in your virtual service. You can use an example code 

     

    //NodeValue can be the xpath of the XML in request. The code below will get the node value from request

    def requestCustomerName = requestBody.getNodeValue("//*:name")       

     

    //The code below will create a new custom property in your virtual service - customPropertyName (you can change it to a sensible name) and will store the request content in it.

    requestContext.mockService.setPropertyValue('customPropertyName',requestCustomerName)

     

    //and then finally, you can call that custom property in your response like below.

     <ns3:name>${#MockService#customPropertyName}</ns3:name>

     

    I hope it helps