Forum Discussion

skillsoft's avatar
skillsoft
Frequent Contributor
15 years ago

[RE-OPENED]SoapUI Pro changing response of xml document within xml document

Is there an preference I can set or some other way to have it so SoapUI Pro is not modifying the response when it is interpreting the XML from the raw data? 

We have an API whos response returns an xml document within an xml document.  It looks like SoapUI is attempting to decode that XML and trying to represent a document within a document, which results in non well-formed XML which it puts CDATA tags around. This non well-formed XML ends up looking like this:


   
     
         <?xml version="1.0" encoding="UTF-8"?><SkillPort><BaseSite><WebsiteColors CurrentColor="#FFFFFF" DefaultColor="#FFFFFF" ModifiedByServer="vmhapi" ModifiedByUser="-1" ModifiedDate="2009-09-29 17:34:38.68" Name="COLOR_LOGIN_DIALOG_BUTTON_TEXT"/></BaseSite><AdvancedGroup Name="AGHapi" Orgcode="AGHapi"><WebsiteColors CurrentColor="#FFFFFF" DefaultColor="#FFFFFF" ModifiedByServer="vmhapi" ModifiedByUser="-1" ModifiedDate="2009-10-01 10:03:22.68" Name="COLOR_LOGIN_DIALOG_BUTTON_TEXT"/></AdvancedGroup></SkillPort>
     

   


The raw data that is coming back looks like this (and is well-formed):

<?xml version="1.0" encoding="UTF-8"?><SkillPort><BaseSite><WebsiteColors CurrentColor="#FFFFFF" DefaultColor="#FFFFFF" ModifiedByServer="vmhapi" ModifiedByUser="-1" ModifiedDate="2009-09-29 17:34:38.68" Name="COLOR_LOGIN_DIALOG_BUTTON_TEXT"/></BaseSite><AdvancedGroup Name="AGHapi" Orgcode="AGHapi"><WebsiteColors CurrentColor="#FFFFFF" DefaultColor="#FFFFFF" ModifiedByServer="vmhapi" ModifiedByUser="-1" ModifiedDate="2009-10-01 10:03:22.68" Name="COLOR_LOGIN_DIALOG_BUTTON_TEXT"/></AdvancedGroup></SkillPort>

Thanks,

Mary

40 Replies

  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Hi Ole,

    We are actually having another issue with this method.  It seem that when I restart SoapUI, I get the following error for all the xpath assertions for these "reporting" methods:

    -> [SOAP Response] error: Unexpected element: XML_DOC_OR_TEXT_DECL
    -> [SOAP Response] Unexpected element: XML_DOC_OR_TEXT_DECL
    -> [XPath Match] XPathContains assertion failed for path [declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
    //soapenv:Envelope[1]] : NullPointerException:null

    I can rerun the request and that error goes away, but still get the other error I mentioned, but I must do it for each test request.  Updating the definition seem to help, but not reliably.  Here is the contents when that error occurs:

    Fri Oct 09 13:37:19 EDT 2009:INFO:

    When I run just the request the contents are this:

    Fri Oct 09 13:41:03 EDT 2009:INFO:
     
         
           
         

     


    So it seems to be kind of flaky.  Any ideas why this would be happening?

    Thanks,

    Mary
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Mary,

    please also add the following to your handler:

    content = content.replaceAll( """, "\"" )

    any difference?

    If not, can you show the entire handler as it is now?

    regards!

    /Ole
    eviware.com
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Hi Ole,

    That works much better, thank you!! Before it was flickering red on the "get" responses and then turning green.  Now it's not doing that. I ran through the whole suite of tests we have and it's working great, even if I restart SoapUI or remove suites and bring them in again from SVN and reload the project.

    You've been very helpful. 


    Thanks,

    Mary
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Hi,

    Sorry to bother you again.  If you could point me in the correct direction that would be great. The last thing you had me add to the handler works great for most of the responses, but broke a few responses that were previously working (with issues).  These particular responses have strings with html text in them (title="",style="").  I've tried playing around with the replaceall using different regular expressions but had no luck.  Here is my event handler now:

    if( submit.response == null )
      return
    def content = submit.response.responseContent
         
    content = content.replaceAll( """, "\"" )

    if (content.contains ("=\"<"))
    {
                    // do nothing
    }
    else
    {             
                    content = content.replaceAll( "<", "<" )
                    content = content.replaceAll( ">", ">" )
    }
    content = content.replaceAll("", "" )
    //log.info content 

    submit.response.responseContent =  content

    Here is the error I'm getting:

    com.eviware.soapui.impl.wsdl.teststeps.assertions.soap.SoapResponseAssertion@469d4f
    line -1: error: Unexpected character encountered (lex state 13): '"'
    line 4: Unexpected character encountered (lex state 13): '"'
    com.eviware.soapui.impl.wsdl.teststeps.assertions.ProXPathContainsAssertion@a49c85
    XPathContains assertion failed for path [declare namespace soapenv='http://schemas.xmlsoap.org/soap/envelope/';
    //soapenv:Envelope[1]] : NullPointerException:null

    This is the content:

    Wed Oct 14 01:30:02 EDT 2009:INFO:
     
         
           
         

     


    and here is the raw xml:

    <?xml version="1.0" encoding="UTF-8"?><SkillPort><BaseSite><HomePage EnableGraphic="1" EnableWelcomeText="1" GraphicURL="/resources/default/images/billboard_img_04.jpg" WelcomeText=""/></BaseSite><AdvancedGroup Name="AGHapi" Orgcode="AGHapi"><HomePage EnableGraphic="1" EnableWelcomeText="1" GraphicURL="/resources/default/images/billboard_img_04.jpg" WelcomeText="&lt;div&gt;&lt;div style=&quot;color:#000000; font-size: 8pt;&quot;&gt;&lt;b&gt;Knowledge at your fingertips &amp;mdash; Anytime &amp;mdash; Anywhere&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;color:#000000; font-size: 8pt; margin-top: 5px;&quot;&gt;Welcome to SkillPort, your online learning portal to training and on-the-job support tools that enhance your business and technical skills. Accelerate your career with e-Learning any time of the day or night. Leverage the different features of SkillPort to find the resources you need and to create a customized learning plan:&lt;/div&gt;&lt;div&gt;&lt;ul style=&quot;list-style:disc; margin-left: 15px; margin-top: 5px; font-size: 8pt;&quot;&gt;&lt;li style=&quot;color:#000000; margin-bottom: 5px;&quot;&gt;&lt;b&gt;SEARCH &amp; LEARN&lt;sup&gt;TM&lt;/sup&gt;&lt;/b&gt;&lt;br/&gt;Perform searches across your full library of resources, and be directed to the specific book page, course topic, or other tool you need for instant and relevant answers. A powerful search engine allows you to use complex search expressions. Results are ranked by relevancy so you can quickly find what you need.&lt;br/&gt;&lt;/li&gt;&lt;li style=&quot;color:#000000; margin-bottom: 5px;&quot;&gt;&lt;b&gt;Catalog&lt;/b&gt;&lt;br/&gt;Browse the SkillPort catalog to see what resources are available to you. Add learning assets from the catalog to your learning plan, or launch them directly from the catalog. The catalog is organized by subject matter and by related professional certification for easy navigation.&lt;br/&gt;&lt;/li&gt;&lt;li style=&quot;color:#000000; margin-bottom: 5px;&quot;&gt;&lt;b&gt;My Plan&lt;/b&gt;&lt;br/&gt;Create a customized learning plan to address specific development goals and keep track of frequently accessed learning assets. You can quickly return to them in My Plan with a single click. Organize and view your learning assets according to your preference: by due date, by type of asset, or in custom folders.&lt;/li&gt;&lt;li style=&quot;color:#000000; margin-bottom: 5px;&quot;&gt;&lt;b&gt;My Progress&lt;/b&gt;&lt;br/&gt;Review both completed and in-progress learning assets in My Progress. Quickly create print-friendly reports on your learning history and certificates of completion.&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;"/></AdvancedGroup></SkillPort>

    Thanks,

    Mary
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Hi Ole,

    Any updates to this?  I'm not looking for you to solve it, just point me in the right direction.

    Thanks,

    Mary
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    I'm thinking you don't have a response for this and that's the reason you haven't responded. Or maybe it's the size of the thread, I'm not sure. Acknowledgment that you are looking into the issue would be helpful.  I couldn't see a pattern that I could reliably use in the event handler to get around this issue.  We have 3 methods that will be affected by this.  One of the methods reports on all 34 methods and will be a bit of a pain to verify, but...

    If I wanted to turn off the event handler for those 3 methods, how could I do this in the event handler?  I would just need to live with the CDATA tags or try some other method to verify them.

    Thanks

    Mary
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Mary,

    sorry for the delayed response.. the tricky thing here is that your CDATA has HTML embedded, and whenever we replace some entity or something we will potentially "create" an xml from the html that is not a valid xml document.. In your case you could try replacing "> with '>'  (note the leading quote), just replace > again will probably make the document even more incorrect..

    Exactly what kind of validations are you performing? Could these be done using the standard Contains assertion instead?

    regards!

    /Ole
    eviware.com
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    Each of these reporting methods have a companion method that sets the value.  So basically we are setting the value and  verifying that the contents of the return element are what we just set.  Some of the methods have dates, server info that we have to wildcard, but 2 of these 3 methods don't.  The 3rd method is a "getAll" type method, so it's going to contain the responses of all 34 reporting methods and I'll just have to deal with that when I come to it. 

    The event handler has worked fine for all the other methods we've tried and we already have testcases and assertions built,  so I don't want to change anything with those testcase assertions.

    We changed tools part way through the project as the other one was inadequate (internal tool they tried to make work for verifying web services) so there was no time to plan for this, we've just had to deal with it as it comes.  I have been trying at the same time to make it so anyone, no matter the technical background is, can take this project and run with it relatively quickly.  Of course we would buy more licenses if that occurs... 

    For 2 of the 3 methods we could probably just do an xpath assertion or a simple contains would work as well, but we'd still need to ignore these methods in the event handler.  We could also just turn off the event handler, but in order to run through all the suites at the same time it would be better if we could turn it off in the event handler.

    Thanks,

    Mary
  • skillsoft's avatar
    skillsoft
    Frequent Contributor
    The Target field of the event handler looks like it could be used to ignore stuff.  For an Submit.After Submit event what exactly would this be filtering?  Your example in the user guide gives an example of what it would be doing for the TestRunListener.afterTestStep. 

    for a TestRunListener.afterTestStep script, you could enter "Request.*" to narrow the script down to all steps beginning with the letter "Request".

    Would this work the same way for the Submit.AfterSubmit event?  Would it be filtering the steps?  We can rename the the steps if that's the case.  Also, what is supported for the regex filter expression (ex everything that groovy supports or something like that) so I know what is available to me?

    Mary
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi Mary,

    yes.. that is how it works.. (or should work), the target should contain a regular expression that will be matched against the name of the teststep..

    hope this helps!

    regards,

    /Ole
    eviware.com