cancel
Showing results for 
Search instead for 
Did you mean: 

XML declaration in request disappears after property transfer

SOLVED
Highlighted
Occasional Contributor

XML declaration in request disappears after property transfer

I am using application/xml requests in http test steps. At the beginnig of each request a xml declariation is needed <?xml version="1.0" encoding="ISO-8859-15"?>. It works fine as long as I run the request stand alone. But when run a property transfer before, the xml declaration will be removed an the test step fails. What can I do?

 

By the way - I found a similar question here. But the link to the answer does not work!

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: XML declaration in request disappears after property transfer

So, alt least I got a way that worked for me - than you for you help!

 

//next line parses the Properties step and gets the value of the declaration
def declaration = testRunner.testCase.testSuite.getPropertyValue("prexml")
log.info(declaration)

 

//next line parses the Properties step and gets the value of the XML without the declaration
def XML = context.expand('${UC1.116_init#Request}')
log.info(XML)

 

//concatenate the values together adding a <br> between them
def wellFormedXML = declaration +" \n" + XML
log.info(wellFormedXML)

 

testRunner.getTestCase().getTestStepByName("UC1.116_init").getProperty('Request').setValue(wellFormedXML)

12 REPLIES 12
Community Hero

Re: XML declaration in request disappears after property transfer

Hi,

 

 

I haven't seen issues for a missing prolog/declaration for a looooooooooong time. 

 

I believe way back (early 2000s) the presence of the declaration in the file content was one of the wellformed rule requirements and if it wasn't present, the xml was considered malformed.  It's been awhile since XMLparsers actually enforced this so Im a bit surprised you have this issue.

 

Anyway - Im going off on one.

 

When you say "the test step fails" - what do you actually mean?  Are you getting a 400 type response from your app server or do you include an assertion verifying the presence of the declaration?  

 

If its just an assertion I'd say remove - cos asserting on the declaration really doesn't add any value to your tests.  If your app server's xml parser is throwing a 400 or similar then I was wondering if you could use an event handler to insert the declaration back into the step's payload content before the step is executed?

I was wondering if you could use an event handler to insert the declaration back into the payload content after property transfer but before the step has executed?

 

Cheers,

 

richie

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Occasional Contributor

Re: XML declaration in request disappears after property transfer

Thank you for your answer! Unfortunately things are more complicated:

 

1. It's possible that the XML request is not well formed. Unfortunatele I cannot correct this, because I have to deal with a server which cannot handle standard XML.

 

2. The test step fails because the request is not even accepted by the server (because of the missing declaration) - Error 500.

 

3. You suggest to use an event handler to add the declaration again. But how exatly do I have to do that? Do I need a groovy skript or how can the be accomplished?

 

Regards

Marcus

Community Hero

Re: XML declaration in request disappears after property transfer

Hey @Meisinotti 

 

Firstly unless you've got tailored responses that have altered how the app server handles error responses, I wouldn't expect a 500 response from a malformed xml request - 5xx http status codes are server errors - not client errors.   I'd expect something like a 400 (bad request) if you were injecting malformed xml - so I'd suggest you double check the server is working fine, cos it doesnt matter how wellformed/malformed your xml is if the app server's busted Smiley Happy

 

Also - can you please describe clearly (maybe a screenshot as well) as what you have in your test right now - you say you pass the XML content via a property transfer and the xfer is actually removing the declaration?  I'm just wondering how the content/payload of your requests are setup.

 

I've thought about it a bit more and it's probably feasible to do this without bothering with the event handler - all you need to do is to concatenate the xml declaration and a line break before the parent tag in your xml. 

One of the coders on the forum will probably whip out some 3 lines of cool code that does the job - but in the meantime....

 

I've only used a couple of event handlers before - so I'm not sure - but I'm guessing it would be something like 'TestRunListener.beforeStep' or 'TestRunListener.beforeRun'  - essentially depending on your testcase object (teststep) hierarchy, I'm thinking for this to work, you'd want the event to fire before the specific test step is submitted to the endpoint.

 

UPDATE to ticket:  I had another look at the event handlers help page - it says you'll know which event handlers to pick if you know the soapUI API (which I dont) - it mentions the SubmitListener (relates to submitting a request) and RequestFilter (relates to sending a request) - unsure what the difference between submitting and sending is here - but anyway - I'll play around with it later

 

The 'Target' value you'd specify would be the relevant test step name.

 

In the field below after the correct event handler is selected you'd need a bit of groovy to grab the content request, concatenate the declaration to the request content and publish the concatenated whole to the endpointn - so something LIKE the following (Im not a groovy coder - -this is a guess on my part)

 

def extractedRequest = context.expand( '${REST Request#Request}' ).toString();

def wellFormedXML = "<?xml version="1.0" encoding="ISO-8859-15"?> \n" + extractedRequest

//bit unsure how to finish it off cos Im not very au fait with event handlers nor groovy - but....
//....Im guessing you'd want to publish the the wellFormedXML variable as the content of the request, but I'm...
//....wondering how the event handler deals with this - so I'll look at this later tonight

I need to do a little investigation as to how to publish the concatenated xml content to the endpoint after the event handler has fired - like I say above - I've only used 2 different types of event handler and both times it was on a response not a request - I'll play with it tonight and try and give you an answer by tomorrow - but quite possibly one of the coders will answer this too.

 

Cheers,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

Re: XML declaration in request disappears after property transfer

Hey,

Ive just thought of an easier way of doing it without using the event handlers...you'll still need a bit of groovy, but even my poor groovy skills are good enough to do this. The approach im thinking about means youll need to xfer the xml content to a properties step (rather than directly to the next request step) append the declaration to the content and pass to the step that is currently failing.

Im travelling now, but i'll respond when im home

Ta

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Community Hero

Re: XML declaration in request disappears after property transfer

Hey @Meisinotti 

 

Ok - this is how I'd do it - if I understand correctly you said when you xfer the payload to your request, the xfer process drops the declaration?

 

Ok - to use the process I put together you need a Properties step - within the Properties step you have 3 attributes - XML (value is the payload without the XML), declaration (value is the declaration value) and a blank wellFormedXML property

 

The following groovy concatenates the appends the XML to the end of the declaration and writes the amalgamated value to the wellFormedXML property so you can pick that up and use it as you need.

 

Im sure the other lads would like have this in one line - but it gets the job done (which is the nicest thing you can say about it) - groovy is below:

 

//next line parses the Properties step and gets the value of the XML without the declaration
def XML = testRunner.testCase.getTestStepByName("Properties").getPropertyValue("XML")
log.info(XML)

//next line parses the Properties step and gets the value of the declaration
def declaration = testRunner.testCase.getTestStepByName("Properties").getPropertyValue("declaration")
log.info(declaration)

//concatenate the values together adding a <br> between them
def wellFormedXML = declaration +" \n" + XML
log.info(wellFormedXML)

//define the properties step and write the merged XML to the Properties step
def propertiesStep = context.testCase.testSteps["Properties"] 
propertiesStep.setPropertyValue("wellFormedXML", wellFormedXML)

Then in the payload of your request  you can just specify '${Properties#wellFormedXML}' to grab the value you need.

 

 

Does that work for you?  Starting to think I may have totally gone off track there....

 

cheers,

 

rich

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Moderator

Re: XML declaration in request disappears after property transfer

Hi all,

Thank you for all the detailed instructions, @richie !

 

@Meisinotti, did the above suggestions help you? 

 


Olga Terentieva
SmartBear Assistant Community Manager

Occasional Contributor

Re: XML declaration in request disappears after property transfer

Thank you for all your support! Unfortenately none of your suggestion helped me so far. Maybe I just have a general understanding problem and don't really understand the concept of SoapUI yet. This is my current approach:

 

This is my Request after the troperty transfer step

<prometheuss schema_version="1.0.0" fachkomponente="UC1116" fachmethode="init"><ParameterListe><Parameter name="UEBERGEORDNETERVORGANGID" value="3265"/></ParameterListe></prometheuss>

 

This is the needed Full-Request (incl. the necessary declaration):

<?xml version="1.0" encoding="ISO-8859-15"?><prometheuss schema_version="1.0.0" fachkomponente="UC1116" fachmethode="init"><ParameterListe><Parameter name="UEBERGEORDNETERVORGANGID" value="3265"/></ParameterListe></prometheuss>

 

So this is what I tried so far:

After the property transfer I inserte a groovy step with the following content:


def declaration = testRunner.testCase.testSuite.getPropertyValue("prexml")
log.info(declaration)
// Output: <?xml version="1.0" encoding="ISO-8859-15"?>

 

def XML = context.expand('${UC1.116_init#Request}')
log.info(XML)
// Output: <prometheuss schema_version="1.0.0" fachkomponente="UC1116" fachmethode="init"><ParameterListe><Parameter name="UEBERGEORDNETERVORGANGID" value="3265"/></ParameterListe></prometheuss>

 

//concatenate the values together adding a <br> between them
def wellFormedXML = declaration +" \n" + XML
log.info(wellFormedXML)
// Output: <?xml version="1.0" encoding="ISO-8859-15"?><prometheuss schema_version="1.0.0" fachkomponente="UC1116" fachmethode="init"><ParameterListe><Parameter name="UEBERGEORDNETERVORGANGID" value="3265"/></ParameterListe></prometheuss>

 

So, how can I use wellFormedXML as the REQUEST in my following HTTP-Request-Step?

Community Hero

Re: XML declaration in request disappears after property transfer

Hi @Meisinotti  

 

The snippet of groovy at the bottom of the code I gave you writes out the concatenated string to the Properties step in the wellFormedXML property - e.g.

 

//define the properties step and write the merged/concatenated XML to the Properties step
def propertiesStep = context.testCase.testSteps["Properties"] 
propertiesStep.setPropertyValue("wellFormedXML", wellFormedXML)

So in the payload of your HTTP step, insert the value ${Properties#wellFormedXML} and don't forget to change the 'MediaType' dropdown to 'application/xml'.

 

Adding the string '${Properties#wellFormedXML}' to the payload means that when you run the script your HTTP request's payload will be populated with the concatenated XML string you need.

 

don't forget the processing within a testcase is sequential - so you need the Properties Step BEFORE your HTTP step.

 

I've added a screenshot just to clarify -hope this is helps!

 

Cheers,

 

rich

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Occasional Contributor

Re: XML declaration in request disappears after property transfer

Well, this cannot work:

 

In my groovy I read the XML request from the following http request (UC1.116_ini). When I replace this request with ${Properties#wellFormedXML} I cannot concate the wellformed XML, because there is no XML for concatination anymore. Look at the attached picture to see the order of my steps so far!

 

UC1.118 - the Response of this Step will bei validatet and used by ...

1.118_to_1.116_ini ... this Property Transfer Step (this Step causes the disapperance of the XML declaration in the next HTTP Request (UC1.116_ini)

CompleteXML is the groovy script which is supposed complete the request of UC1.116_ini.

UC1.116_ini at least is suppost to run wirh the XML declaration + XML Request

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2