header
header
Main Menu
Home
Eviware Store
Downloads
Products
News
Forum
Eviware Blog
Search
FAQs
Customer Area
Support
Documentation
Tutorials
CookBook
Downloads
Forum
Login Form
Welcome, Guest. Please login or register.
December 05, 2008, 12:49:46 am
Username: Password:
Login with username, password and session length

Forgot your password?
 
java.lang.NullPointerException: Cannot get property: value on null object
Welcome, Guest. Please login or register.
December 05, 2008, 12:49:46 am
Home Help Search Login Register
News: The Forums are up! Welcome to eviware.

+  Eviware Forum
|-+  soapUI
| |-+  soapUI
| | |-+  java.lang.NullPointerException: Cannot get property: value on null object
« previous next »
Pages: [1] Print
Author Topic: java.lang.NullPointerException: Cannot get property: value on null object  (Read 675 times)
Venkat
Newbie
*
Posts: 2


« on: November 27, 2007, 11:20:18 pm »

Hi,
      I am running my very first groovy script inside SoapUI. I get the error mentioned in the subject of this message. Here is the code I used ( which I copied from the SoapUI User guide ):
----------------------------------------------------------------------------------------
def request = testRunner.testCase.getTestStepByName( "Groovy Script" );
def property = request.getProperty( "request" );

// parse out textnodes to modify
def node = new groovy.util.XmlParser(false,false).parseText(property.value);
def textNodes = node["soapenv:Body"]["sam:getContactInfo"]["String_1"][0].children()

// modify
textNodes.clear();
textNodes.add( "test" + System.currentTimeMillis() );

// write back to string
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
printer.print( node );

// set property
property.setValue( writer.toString() )
-------------------------------------------------------------------------------------

What am I doing wrong? Should I have to set something before I run my script? I get this error even if I run the load test from the command line.

Also, is there a place I can go to for seeing working examples of groovy scripts inside SoapUI. I want to call different methods inside a Webservice and the inputs to successive webservice calls will be based on the responses to previous webservice calls.

Any help you can provide will be greatly appreciated.

Thanks,

Venkat
« Last Edit: November 27, 2007, 11:25:25 pm by Venkat » Logged
nreimertz
soapui pro users
Full Member
*
Posts: 207


« Reply #1 on: November 27, 2007, 11:38:06 pm »

Just one small question,

Have you run the step the script is referring to (Groovy Script)?

This happends to me a lot; if I don't run the step it is referring to there is nothing for the script to point at at
Code:
def textNodes = node["soapenv:Body"]["sam:getContactInfo"]["String_1"][0].children()
.

Hence the nullPointerException.

/niclas
eviware.com
Logged
nreimertz
soapui pro users
Full Member
*
Posts: 207


« Reply #2 on: November 27, 2007, 11:48:20 pm »

The answer to the other parts.

1) Yes, there are example projects to be downloaded from the Downloads sections in the Customer Area

http://www.eviware.com/content/blogcategory/34/45/

2) If i understand you right you want to take the value of one element in a response and transfer that to an element in another request?

There's easier ways to do this than Groovy, namely PropertyTransfers and PropertyExpansions. Example on how to use both is included in the soapUI installation. Look in the folder that soapUI is installed in, there's a sample project file there containing examples on what you're looking for.

Look at
Code:
Simple Login and Logout w. Properties Steps
for a PropertyTransfer example and
Code:
Simple Login and Logout Property Expansion
for an example of PropertyExpansions. Remember to start the MockService before running the tests. Look at http://www.soapui.org/gettingstarted/sample-project.html for more info on the sample Project, there's even a movie on about how to use it.

/niclas
eviware.com
Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,506


« Reply #3 on: November 28, 2007, 12:36:18 am »

Hi!

just a quick check; which soapUI version are you using?

regards!

/Ole
eviware.com
Logged
Venkat
Newbie
*
Posts: 2


« Reply #4 on: November 28, 2007, 05:49:31 pm »

Hello,
         Thanks for your replies, Niclas and Ole! Appreciate it! I am using Soap UI 2.0-beta1 version.  Your suggestion to first run the step the script is referring to (Groovy Script) helped. But now I want to print out the contents of one of the elements in the response. What is the syntax for referring to that element? I am trying to use the following code and I am not getting it to do what I wanted. Here is my code:
------------------------------------------------------------------
def request = testRunner.testCase.getTestStepByName( "Test Request" );
def property = request.getProperty( "request" );
def writer = new java.io.StringWriter();
def printer = new groovy.util.XmlNodePrinter( new PrintWriter( writer ));
printer.print( "Starting test\n");
def node = new groovy.util.XmlParser(false,false).parseText(property.value);
def entityID = node["SOAP-ENV:Body"]["//ns:getXrefBySSPrefixSourceCompanyIDResponse[1]/ns:getXrefBySSPrefixSourceCompanyIDResult[1]/ns0:CompanyXref[1]/EntityID[1]"];
printer.print( entityID );
printer.print( "Ending test\n");
------------------------------------------------
What am I doing wrong? Why don't I get the values of "EntityID" printed? I can see the value 32074 in the response side of "Test Request" step. Here is my output:
------------------------------------------------
Starting test
[]Ending test
--------------------------------------------------------
« Last Edit: November 28, 2007, 05:53:50 pm by Venkat » Logged
omatzura
Administrator
Hero Member
*****
Posts: 1,506


« Reply #5 on: November 29, 2007, 12:18:00 pm »

Hi Venkat,

please try using the GroovyUtils / XmlHolder classes for accessing the content of a response as described at http://www.soapui.org/userguide/functional/groovystep.html#GroovyUtils. They are much easier to use than the corresponding Groovy classes... (we need to update the examples for this.. sorry..)

Hope this helps!

regards,

/Ole
eviware.com
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
header header
header
header