Forum Discussion

electric_Insura's avatar
electric_Insura
Contributor
11 years ago

[Resolved] Get rid of unwanted CDATA in request

Hi,

I have a SOAP request test step to which I'm feeding escaped XML as one of the parameters.

The UI automatically puts the XML into CDATA brackets.

The Web service that I'm testing fails with the CDATA brackets present. If I remove the CDATA enclosure manually, the request goes through.

I tried putting the following as a top level RequestFilter.filterRequest event in my project:

context.requestContent = context.requestContent.replaceAll('"<!\\[CDATA\\[", "" , '')
context.requestContent = context.requestContent.replaceAll(']]>', '')

No luck. It doesn't even touch it.

I need this solved in order to be able to test this Web service at all.

Thanks for any advice.

4 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    What is happening now?

    Are you setting back the request after replacing?
  • I developed the answer to my question after reviewing a fair amount of Groovy documentation.

    The replaceAll method takes a regexp as an argument. The special characters require different handling than if you were using the find method.

    There are probably more elegant ways to write this but the code scrubs the CDATA enclosure from outgoing requests just fine.

    matcher = (context.requestContent =~ /<!\[CDATA\[/)

    context.requestContent = matcher.replaceAll("")

    matcherdeux = (context.requestContent =~ /\]\]>/)

    context.requestContent = matcherdeux.replaceAll("")


    The solution given here on how to strip a CDATA enclosure http://www.soapui.org/Functional-Testing/working-with-cdata.html#6-an-event-handler-to-the-rescue is the one I used in my initial post - the one that didn't work. It would be great if the docs could be updated.
  • nmrao's avatar
    nmrao
    Champion Level 3
    Understand that you could proceed.
    Hoping that SmartBear team can take are of your suggession.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    I am glad that you were able to fix your problem and thanks for sharing the solution!

    However, I have reviewed and tested the code in the documentation and it should really work. Both solutions should give the same result so I suspect that you also fixed something else in your code at the same time.

    Best regards,
    Anders
    SmartBear Sweden