Forum Discussion

Novosib's avatar
Novosib
Occasional Contributor
14 years ago

java.lang.NullPointerException error when using XmlHolder in Groovy script

I'm getting the following error when using groovy script step:

  java.lang.NullPointerException
  at com.eviware.soapui.support.XmlHolder.(XmlHolder.java:52)
  at com.eviware.soapui.support.GroovyUtils.getXmlHolder(GroovyUtils.java:54)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
  at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
  at Script1.run(Script1.groovy:4)
  at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:93)
  at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:148)
  at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:274)
  at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)

All I'm doing is using the following lines of code:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
log.info( groovyUtils.projectPath )
def holder = groovyUtils.getXmlHolder( "ListColors#Response" )
My response looks like the following:


 

 
     
       
            22
            amber
       

       
            1
            beige
       

Am I doing something wrong or is this a SOAPUI bug ?

Thanks

10 Replies

  • Novosib's avatar
    Novosib
    Occasional Contributor
    No response. Anybody might know what the problem is ? I'm evaluating SOAP UI Pro and if I'm not able to extract individual XML items I will not be able to use SOAP UI.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    I get that error if the request step is not found... add some logging to make sure you are getting the response:

    log.info context.expand('${ListColors#Response}')
  • Novosib's avatar
    Novosib
    Occasional Contributor
    I'm getting an empty Log after this line:

    log.info context.expand('${ListColors#Response}')

    does it mean I'm missing a step somewhere ?
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    It means it can't find the response... are you sure you have the correct name for the Request step?
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    yes.. check that there are no leading or trailing spaces in the actual name of the TestStep.. does this help you forward?

    If not, can you attach the soapUI project so we can check this out?

    regards!

    /Ole
    eviware.com
  • Novosib's avatar
    Novosib
    Occasional Contributor
    Project is attached to this post. TestSuite 1 TestCase 1. You will not be able to get the response though because the service runs localy on my macine. Full response XML file is this:


     

     
         
           
                22
                amber
           

           
                1
                beige
           

           
                2
                black
           

           
                3
                blue
           

           
                4
                blue-green
           

           
                5
                brown
           

           
                6
                clear
           

           
                7
                gray
           

           
                8
                green
           

           
                25
                green-yellow
           

           
                9
                maroon
           

           
                27
                opalescent
           

           
                20
                opaque
           

           
                10
                orange
           

           
                28
                orange-brown
           

           
                11
                peach
           

           
                12
                pink
           

           
                23
                pink-orange
           

           
                13
                purple
           

           
                14
                red
           

           
                21
                red-brown
           

           
                19
                red-orange
           

           
                24
                red-pink
           

           
                15
                rust
           

           
                26
                tan
           

           
                16
                white
           

           
                17
                yellow
           

           
                18
                yellow-orange
           

         

     


    Thanks guys.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    the name of the request step is "ListColors - Request 1", so the context.expand should be

    context.expand( '${ListColors - Request 1#Response}' )

    does that help?

    regards!

    /Ole
    eviware.com
  • Novosib's avatar
    Novosib
    Occasional Contributor
    Thank you guys. here is the synthax that I had to use:

    def holder = groovyUtils.getXmlHolder(context.expand('${ListColors - Request 1#Response}'))

    Before all I had to use is :
    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "ListColors#Response" )

    and it worked. Did the synthax changed in the new version ? 
    • sathish_win's avatar
      sathish_win
      Senior Member

      Could you please share the full code.... I want to remove empty parent tags in my request XML. Please help

      I tried these 2 not working

       

      1)

      def holder = groovyUtils.getXmlHolder(context.expand('${Request 1#Request}'))
      for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" ))
      {
       item.removeXobj()
      }
       holder.updateProperty()
      context.requestContent = holder.xml

       

       

      2)


      testRunner.testCase.testSteps.each
      {
       it->
       if (it.getValue().config.type.equals("restrequest"))
       {
        def x = it.getValue().getName();
       //def groovyUtils = new com.eviware.soapui.support.GroovyUtils

       def holder = groovyUtils.getXmlHolder(context.expand('${x#Request}'))

      // find end nodes that also only consist of whitespace
      for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" ))
      {
       item.removeXobj()
      }
       holder.updateProperty()
      context.requestContent = holder.xml


       }
      }

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi!

    ok.. you should still get away with

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
    def holder = groovyUtils.getXmlHolder( "ListColors - Request 1#Response" )

    doesn't that work?

    regards!

    /Ole
    eviware.com