Ask a Question

How to call Java code from soapUI?

SOLVED
mmoser18
Frequent Contributor

How to call Java code from soapUI?

Hi - this may be a Groovy question rather than a real soapUI question, but soapUI is the reason I am now digging into Groovy, so please bear with me:

 

I am trying to get a bit more information why one of my regular expressions doesn't match. Unfortunately, a statement like "assert response =~ pattern" returns essentially just yields a thumbs up/down result without any indication whatsoever why something didn't match.

 

I was thus trying to use some good, ol' Java code to get a bit more feedback. The PatternSyntaxException that Pattern throws if a match fails would allow to get a bit more details (error index, etc.). So I was trying a code snippet like the below:

 

def matches = false 

try {
   log.info('1')
   matches = java.util.regex.Pattern.matches(pattern, response)
   log.info('2: ' + matches)
} catch (java.util.regex.PatternSyntaxException psx) {
   log.info(psx.getMessage()) 
} catch (Exception ex) {
   log.info(ex)
}

assert matches

 

Why does this always only reach the "log.info('1')" statement and then ends in an "Error: null" popup?

I though, one of the big advantages of Groovy is that I can use plain Java code whenever I want or need to. Why does this not work here? What am I missing?

5 REPLIES 5
rupert_anderson
Valued Contributor

Hi,

 

I would say that your code works rather well? See below:

 

Screen Shot 2015-08-24 at 17.16.34.png

If I change response to a valid IP address it passes.

 

I am using SoapUI 5.2 Beta, could it be that your response or pattern variables contain something problematic?

 

Cheers,

Rupert

Author of SoapUI Cookbook

Hi Rupert and thanks for responding! Very appreciated!

 

I am pretty sure that my pattern and response variables don't contain anything "problematic". In fact, meanwhile I wrote myself a little Java test-program that essentially does that very same regex-matching in pure Java and that works perfectly and matches fine.

HOWEVER, I got that Java program only working after increasing the default stack space (before doing so I always got stack-overflows) which together with your hint points me into the direction, that my regular expression may be "problematic" in the sense that it is simply too long and complex and thus causes stack overflows. This would also explain, why some tests run fine while others don't.

 

How do I increase soapUI's default thread stack space?

 

Hi,

 

No problem, happy if I can help, but it sounds like there may be a deeper problem as you are pointing out...

 

What you are saying does sound reasonable in that possibly the SoapUI Java memory usage is an area that may be affecting the ability to run your regex... don't expect the response is the problem...

 

As you may be aware to change the Java options for SoapUI you can alter the soapui.sh (or .bat) script - refer to http://www.soapui.org/working-with-soapui/improving-memory-usage.html for more details.

 

Guess you may try increasing the -Xss stack space parameter as you said...

 

Let us know how you get on please, possibly it would be good to share your regex if you're happy too, just incase that helps or attracts other useful advice...

 

Cheers,

Rupert

Author of SoapUI Cookbook

Thanks for helping!

I meanwhile found the SoapUI-5.2.0.vmoptions file, added a "-Xss3m" to it and - BINGO! - things are working perfectly now!

 

Gee, this has cost me almost 2 days of work because I searched each and every corner but couldn't find any reason why this didn't work! The fact that Groovy/soapUIs silently swallows all exceptions without giving any clue or feedback wasn't exactly very helpful in this journey...

 

BTW: my rationale for choosing 3m (3 MByte) were:

with 1m I still got stack overflows.

with 2m they were gone - things worked!

So I decided to use 3m to leave some headroom for really large messages. But I didn't want to set this to 5m or more since soapUI presumably creates LOTs of threads and setting this too high may quickly lead to other memory issues.

 

So, I am a happy camper now!

 

Cheers and thanks again,

Michael

 

Hi Michael,

 

Nice one! Well done on fixing it and sharing the details, you never know, it could save someone else 2 days! Quite an intereseting learning really, the demands of complex regexes etc! 🙂

 

One last thing, if you're happy to, please mark the post as solved so that others know its fixed.

 

Thanks,

 

Rup

Author of SoapUI Cookbook
cancel
Showing results for 
Search instead for 
Did you mean: