Search code examples
javaweb-servicessoapuisoap-clientexi

Intercept SOAP response in SOAP UI


A webservice returns

<SOAP: Envelope>
<SOAP: Header>
    <SOAP: Body>
        <RootElement>
        <![CDATA[Base64 encoded string]]>
        </RootElement>
    </SOAP : Body>
</SOAP: Header>

Base64 encoded string is actually an EXI encoded XML. I know how to decode base 64, then convert EXI to XML. Lets call that MyEXIEncoder.class (Java class)

However, we currently have a lot of SOAP UI test cases that are based on the XML responses.

At the moment the only way seems to be adding a groovy script that can invoke my java class class, but that is an additional test step, which means, I would have to write some script to update my SOAP UI test cases. More over I am not sure how my assertions would work and how much of a change that would be for my test cases (I have several hundreds of test cases)

I need a means to

Intercept the SOAP response from my test step, use my custom class that does the decode and return the response back SOAP UI so that existing assertions can work.

Any help wold be greatly appreciated!

Thanks in advance.


Solution

  • Add a monitor listener as shown here

    e.g

    Event Handler:
    //MonitorListener.afterProxy
    
    // get the raw response as a string
    def str = new String( messageExchange.getResponseContent()  )
    
    // Decode
     </ConversionRateResult", "Result>1.0</ConversionRateResult");
    
    // save the response back
    messageExchange.rawResponseBody = str 
    

    Edit : Based on the comment of OP, updating with the link to use context.

    As per Tip and tricks of SOAPUI point 6. using RequestFilter.afterRequest one can set the response back.

    // write it back 
    context.httpResponse.responseContent = content
    

    MonitorListener.afterProxy does not give the context object.

    RequestFilter.afterRequest + using context turned out to be better solution.