cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not working

Contributor

Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not working

I have a SOAP request which returns the complete response in CDATA. I am trying to convert it to XML using the RequestFilter.filterRequest event handler. But it is not working. The response is still coming back as CDATA. I am using the following help document (which is no help at all obviously)...

 

http://readyapi.smartbear.com/readyapi/events/handlers

 

My code:

def content = context.httpResponse.responseContent
content = content.replaceAll("<![CDATA[<QuoteObject>", "")
content = content.replaceAll( "]]>", "")

log.info( content )

context.httpResponse.responseContent = content

 

Please help.

7 REPLIES 7
Community Hero

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

RequestFilter itself conveys that it is applied for request not for response.


Regards,
Rao.
Contributor

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

Hi,

That does not help in any way.

Thanks.

Community Hero

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

Well, you are applying wrong one.
Why do not you show the raw response? And what you want out of it?


Regards,
Rao.
Contributor

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

So, here is part of my request and response in the CData format ...

I would like the response to be displayed in the xml format.

If not possible, is there an easy way to write assertions for the data returning in the CData format?

I couldn't find anything except 'Contains' assertion. I would like to use XPath.

 

Request:

<soapenv:Body>
<web:CalculateQuote>
<!--Optional:-->
<web:QuoteXML><![CDATA[<QuoteObject>
<Insured>
<Quote>
<EffectiveDate>08/10/2011</EffectiveDate>
<OriginalEffectiveDate>08/10/2011</OriginalEffectiveDate>

 

 

Response:

<CalculateQuoteResult><![CDATA[<QuoteObject><Insured UnitNumber=""><Quote UnitNumber=""><EffectiveDate>08/10/2011</EffectiveDate>

 

Thanks.

Community Hero

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

As per below link, you can't directly apply xpath on the data that is inside cdata.
http://stackoverflow.com/questions/19745210/what-xpath-to-select-cdata-content-when-some-childs-exis...

So first extract value that is in cdata, then use xmlslurper to parse that data and apply xpath on it.


Regards,
Rao.
Contributor

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

Thanks! I will try that out.

Contributor

Re: Trying to use RequestFilter.filterRequest event to convert CDATA SOAP Response to XML. Not worki

Thanks for the information Rao.

The script was really simple, and works fine!

 

def rootNode = new XmlSlurper().parseText('My CData Text')

assert rootNode.name() == 'The Root node in my CData'

assert rootNode.State.text() == AZ (State being one of the nodes in the CData).

 

Thanks!

New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors