Forum Discussion

ravibabu_it's avatar
ravibabu_it
Occasional Contributor
7 years ago
Solved

Unable to call Java method using groovy script

All,

I have created jar file with name readXML.jar and placed the jar file in bon/ext folder. I have the imported the package and called the required java method as below

 

import readXML.readXMLResponse

def StrXML=context.testCase.testSuite.project.testSuites["Services"].testCases[ServiceName].testSteps[methodname].getPropertyValue("ResponseAsXML").toString();

log.info StrXML;

def tagname=context.testCase.testSuite.getPropertyValue("OUTPUTTAG")

log.info "tag name is :$tagname"

readXMLResponse xml1= new readXMLResponse();

ArrayList alist=new ArrayList();

alist=readXMLResponse.GetData(StrXML,tagname);

 

During execution in soapui, I am getting below error. Note I checked calling this method in eclipse and it worked fine.

 

ERROR:groovy.lang.MissingMethodException: No signature of method: static readXML.readXMLResponse.GetData() is applicable for argument types: (java.lang.String, java.lang.String)

 

Please find the attached document that contains content of the jar file.

 

Thanks,

Ravindra

    1. From the error & attachment, there is not static method in the java class
    2. Create the class object & then call the method
    3. It is directly not relevant, but just providing the feed back on the naming conventions
      • class name should use Init Caps. Say : ReadXmlResponse
      • method name should start with lower case and followed by Init Caps. Say : getData()
      • in this case, the method can be static

     

    If you want to process the xml, you do not have to use java which needs lot of instruction, instead use groovy and is very easy to do it.

     

    You can find some samples below:

    https://github.com/nmrao/soapUIGroovyScripts/search?utf8=%E2%9C%93&q=xml&type=

     

    https://github.com/nmrao/groovyScripts/tree/master/xml

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    1. From the error & attachment, there is not static method in the java class
    2. Create the class object & then call the method
    3. It is directly not relevant, but just providing the feed back on the naming conventions
      • class name should use Init Caps. Say : ReadXmlResponse
      • method name should start with lower case and followed by Init Caps. Say : getData()
      • in this case, the method can be static

     

    If you want to process the xml, you do not have to use java which needs lot of instruction, instead use groovy and is very easy to do it.

     

    You can find some samples below:

    https://github.com/nmrao/soapUIGroovyScripts/search?utf8=%E2%9C%93&q=xml&type=

     

    https://github.com/nmrao/groovyScripts/tree/master/xml

    • ravibabu_it's avatar
      ravibabu_it
      Occasional Contributor

      Thank you Rao. After adding static keyword , it worked. We are so blessed to have guys like you in the forums who always comes forward to share the knowledge. Truly appreciate your support and commitment.

       

      I will also look into your suggestion of using of groovy instead of Java . I was working on existing framework that was created few years back to make it work again.

       

      Thanks,

      Ravindra.Ch

      • nmrao's avatar
        nmrao
        Champion Level 3
        Thank you for the kind words and glad that the provided info is helpful.