Forum Discussion

mmoser18's avatar
mmoser18
Frequent Contributor
9 years ago
Solved

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?

  • 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

5 Replies

  • rupert_anderson's avatar
    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

    • mmoser18's avatar
      mmoser18
      Frequent Contributor

      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?

       

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        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