AXIS的Server.userException,刚学就受这么大的打击!
服务端:
-------------------
HelloWorld.java
public class HelloWorld {
public String sayHello()
{
return "HELLO WORLD!";
}
}
改名为HelloWorld.jws,放到TOMCAT目录里。
用IE访问http://127.0.0.1:8080/axis/HelloWorld.jws?WSDL
可以看到XML文档。
客户端:
-----------------------
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.rpc.ParameterMode;
public class TestClient {
public static void main(String[] args) throws Exception {
String endpoint = "http://127.0.0.1:8080/axis/HelloWorld.jws";// 指明服务所在位置
Service service = new Service(); // 创建一个Service实例,注意是必须的!
Call call = (Call) service.createCall();// 创建Call实例,也是必须的!
call.setTargetEndpointAddress(new java.net.URL(endpoint));// 为Call设置服务的位置
System.out.println(endpoint);//这里可以输出
//call.setOperationName("sayHello");// 注意方法名与HelloWorld.java中一样!!
String res = (String)call.invoke("sayHello",new Object[] {});// 返回String,没有传入参数
System.out.println(res);
}
}
错误:
-------------------
Exception in thread "main" 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 java.util.Hashtable.put(Hashtable.java:396)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:395)
at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:246)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:377)
at org.apache.axis.client.Call.invokeEngine(Call.java:2545)
at org.apache.axis.client.Call.invoke(Call.java:2515)
at org.apache.axis.client.Call.invoke(Call.java:2210)
at org.apache.axis.client.Call.invoke(Call.java:2133)
at org.apache.axis.client.Call.invoke(Call.java:2158)
at TestClient.main(TestClient.java:20)
java.lang.NullPointerException
at org.apache.axis.AxisFault.makeFault(AxisFault.java:129)
at org.apache.axis.client.Call.invoke(Call.java:2213)
at org.apache.axis.client.Call.invoke(Call.java:2133)
at org.apache.axis.client.Call.invoke(Call.java:2158)
at TestClient.main(TestClient.java:20)
Caused by: java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:396)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:395)
at org.apache.axis.encoding.DeserializationContextImpl.parse(DeserializationContextImpl.java:246)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:377)
at org.apache.axis.client.Call.invokeEngine(Call.java:2545)
at org.apache.axis.client.Call.invoke(Call.java:2515)
at org.apache.axis.client.Call.invoke(Call.java:2210)
... 3 more