2

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.

The g
  • 43
  • 5

1 Answers1

1

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.

Optional
  • 4,387
  • 4
  • 27
  • 45
  • Thank you. I will explore the link provided by you. – The g Oct 06 '17 at 19:05
  • I tried the code snippet. It did not work. So I tried just doing some log statements to check if the event handler is getting fired or not. I could not see the log statements in the log section of Ready API screens. I am using Ready API 2.1.0 and the code I used `log.error("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% : ");` @Optional – The g Oct 09 '17 at 13:19
  • Todays update - I am now able to see my log entries in the event handler for MonitorListener.afterProxy. I had set up proxy under preferences and I was running a HTTP Monitor due to which the event handler was not firing. I later removed the proxy and used only the HTTP Monitor. I was able to get into the event handling part. – The g Oct 10 '17 at 16:36
  • I am now able to do string replace, and log the replaced string. However, I am not able to save the response back. When I do `messageExchange.rawResponseBody = str` I dont see my modified response on the response panel. – The g Oct 10 '17 at 16:40
  • You are almost there. Page suggest, that's all you need. If you can't update the UI, you can still assert in the converted string you got. Neverthless this link https://www.soapui.org/scripting-properties/tips-tricks.html says to update context. See point 6. // write it back `context.httpResponse.responseContent = content` – Optional Oct 10 '17 at 18:57
  • Great! It worked!!! I ditched MonitorListener.afterProxy since it does not give me the context object. I used RequestFilter.afterRequest as suggested in the link you provided. I was able to set the response back, plus I dont need to have a http monitor or proxy to make my event handler fire. So RequestFilter.afterRequest + using context turned out to be better solution. thanks @Optional – The g Oct 11 '17 at 10:12
  • I clicked the vote up on the answer, but it said since my reputation is not 15 yet, it recorded my vote, but will not increase the count. Is there any other way to "accept" the answer ? – The g Oct 11 '17 at 11:06
  • :) no problem. Cheers !! @Theg – Optional Oct 11 '17 at 11:32