File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Services and the fly likes Null Pointer Exception encountered when accessing a simple Hello webservice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Null Pointer Exception encountered when accessing a simple Hello webservice" Watch "Null Pointer Exception encountered when accessing a simple Hello webservice" New topic
Author

Null Pointer Exception encountered when accessing a simple Hello webservice

kumari Jain
Ranch Hand

Joined: Jul 28, 2004
Posts: 44
Hi all,
I have installed Axis 1.4 ,Tomcat-4.1.34 ,jdk 1.4 to try out web services examples.
I'm trying to deploy and test a simple HelloService program.
This program has a method sayHello that takes a string parameter and returns a string result.

This is the web service
public class HelloService
{
public String sayHello(String name)
{
System.out.println("sayHelloTo(String name)");
return "Hello " + name + ", How are you doing?";
}
}

This is the client
public class TestClient
{
public static void main(String [] args)
{
String endpoint = "http://localhost:8080/axis/HelloService.jws";

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setOperationName("sayHello");


call.addParameter( "op1", org.apache.axis.Constants.XSD_STRING, ParameterMode.IN );
call.setReturnType( org.apache.axis.Constants.XSD_STRING );

String ret = (String) call.invoke( new Object[] { "Hello!" } ); /* Line 52 : exception is thrown */

System.out.println("Sent 'Hello!', got '" + ret + "'");

}

When i run the client file which invokes the web service,i get the following NullPointerException.

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.lang.NullPointerException
at org.apache.axis.message.MessageElement.addTextNode(MessageElement.java:1396)
at org.apache.axis.message.SOAPHandler.addTextNode(SOAPHandler.java:148)
at org.apache.axis.message.SOAPHandler.endElement(SOAPHandler.java:112)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at weblogic.apache.xerces.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:585)
at weblogic.apache.xerces.impl.XMLNamespaceBinder.handleEndElement(XMLNamespaceBinder.java:898)
at weblogic.apache.xerces.impl.XMLNamespaceBinder.endElement(XMLNamespaceBinder.java:644)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanEndEle
ment(XMLDocumentFragmentScannerImpl.java:1008)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentCo
ntentDispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1469)
at weblogic.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocume
nt(XMLDocumentFragmentScannerImpl.java:329)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:525)
at weblogic.apache.xerces.parsers.DTDConfiguration.parse(DTDConfiguration.java:581)
at weblogic.apache.xerces.parsers.XMLParser.parse(XMLParser.java:152)
at weblogic.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1175)
at weblogic.xml.jaxp.WebLogicXMLReader.parse(WebLogicXMLReader.java:135)
at weblogic.xml.jaxp.RegistryXMLReader.parse(RegistryXMLReader.java:138)

java.lang.NullPointerException
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)

at samples.userguide.example1.TestClient.main(TestClient.java:52)

Caused by: java.lang.NullPointerException
at org.apache.axis.message.MessageElement.addTextNode(MessageElement.java:1396)
at org.apache.axis.message.SOAPHandler.addTextNode(SOAPHandler.java:148)



I checked the TCP monitor.It shows the string sent in the request soap message and the result string sent in the SOAP response.

If however i write another method that takes an integer as a parameter and returns an integer,there is no problem.The method successfully returns the integer result.

Can somebody give me a solution to this problem.
regards,
kumari
kumari Jain
Ranch Hand

Joined: Jul 28, 2004
Posts: 44
hi all

I have found out the cause of the problem.The classpath included webservices.jar.This was the jar file required for running webservices on weblogic.The problem was the presence of duplicate classes possibly of different versions in webservices.jar and axis jar files.

Hence once when webservices.jar was removed from classpath everything worked fine.I have found that many people had faced same problem but the solution was not put anywhere.Hope this post is useful for others.

regards,
kumari
Zoltan Gombosi
Greenhorn

Joined: Oct 03, 2006
Posts: 1
I also found this same problem to occur if you are using the jrockit 1.4 JVM. Instead I switched to used the standard sun 1.4 JVM and this resolved the problem.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Thanks for the update.

So many people post problems, discover a solution, but don't update the post.

I have seen many, many people deal with this issue. Trust me, you've just helped out alot of people, and that's what a board like this is all about.

Cheers!

-Cameron
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer Exception encountered when accessing a simple Hello webservice
 
Similar Threads
Error while running client code on axis webservice
Server.userException
Currency Web Service almost there
problem in Axis sample application
Axis - Connection refused: connect