Forum Discussion

JHoreczky's avatar
JHoreczky
Contributor
13 years ago

Modyifing REST request msg AFTER submit

Hi,

In a REST type request, sent through HTTP POST to a servlet, an example of a concrete request looks like this (cut and paste from the soapUI log):

Wed Jul 11 23:57:45 MDT 2012:DEBUG:Sending request: POST /myServlet?Province=XY&Address=123&Street=JOHNSON HTTP/1.1

What I wish to do, after when the request was sent, I wish to reformat the request into an XML document and write it back, so that it appears in Message Viewer / Request Message window as an XML document. Currently in Message Viewer / Reques Message there is content under the Raw tab only, as under the XML tab the display says: "<not-xml/>

I am trying to use a groovy script triggered by the RequestFilter.filterRequest event for the above.

I know what I am trying to do is feasible for the response. For example this works for RequestFilter.afterRequest:

context.httpResponse.responseContent = "<myresponse>blah</myresponse>"

- which will then be displayed under Message Viewer / Response Message

Is there a similar way for modifying the request (basically reformatting it for display purposes only) ?


Thanks,

Joseph H.

3 Replies

  • The following seems to work. Is this the proper way for modifying and writing back request content?

    context.requestContent = "<myrequest>blah</myrequest>"
  • Unfortunately in a data driven case the property expansion was not done yet, and it resulted displaying the property name instead of the value. For example:

    In RequestFilter.filterRequest:

    def theCity = request.getPropertyValue("City")
    context.requestContent = "<request><city>" + theCity + "</city></request>"


    Display in Message Viewer / Request Message:

    <request><city>${DataSource#city}</city></request>


    Is there a solution to this problem?


    Thanks,

    Joseph H.
  • Hi,

    try using context.expand( ... ) on the created string - ie

    context.requestContent = context.expand( context.requestContent )

    it should replace all property expansions with their corresponding values..

    regards,

    /Ole
    SmartBear Software