Java Axis2客户端在ServiceStub类中获取NullPointerException
我有一个客户端试图调用web服务-Java Axis2客户端在ServiceStub类中获取NullPointerException,java,web-services,axis2,Java,Web Services,Axis2,我有一个客户端试图调用web服务- public static void main(String[] args) throws RemoteException { SimpleServiceStub service = new SimpleServiceStub( "http://localhost:8080/axis2/services/SimpleService"); ConcatRequest request = new Concat
public static void main(String[] args) throws RemoteException {
SimpleServiceStub service = new SimpleServiceStub(
"http://localhost:8080/axis2/services/SimpleService");
ConcatRequest request = new ConcatRequest();
request.setS1("abc");
request.setS2("123");
ConcatResponse response = service.concat(request);
System.out.println(response.getConcatResponse());
}
异常stacktrace来自eclipse is中-
Exception in thread "main" org.apache.axis2.AxisFault
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at com.ttdev.ss.SimpleServiceStub.fromOM(SimpleServiceStub.java:1419)
at com.ttdev.ss.SimpleServiceStub.concat(SimpleServiceStub.java:190)
at com.ttdev.ss.SimpleClient.main(SimpleClient.java:15)
Caused by: java.lang.NullPointerException
at com.ttdev.ss.SimpleServiceStub.fromOM(SimpleServiceStub.java:1413)
... 2 more
*编辑*这是轴的堆栈跟踪
Exception in thread "HttpConnection-8080-1" java.lang.IllegalStateException: Response already committed
at org.apache.axis2.transport.http.server.AxisHttpResponseImpl.assertNotCommitted(AxisHttpResponseImpl.java:75)
at org.apache.axis2.transport.http.server.AxisHttpResponseImpl.sendError(AxisHttpResponseImpl.java:110)
at org.apache.axis2.transport.http.server.AxisHttpService.doService(AxisHttpService.java:315)
at org.apache.axis2.transport.http.server.AxisHttpService.handleRequest(AxisHttpService.java:187)
at org.apache.axis2.transport.http.server.HttpServiceProcessor.run(HttpServiceProcessor.java:82)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
调试代码时,我看到在生成的存根类中传递了null参数(第一个参数)-
private java.lang.Object fromOM(
org.apache.axiom.om.OMElement param,
java.lang.Class type,
java.util.Map extraNamespaces) throws org.apache.axis2.AxisFault{
try {
if (com.ttdev.ss.SimpleServiceStub.ConcatRequest.class.equals(type)){
return com.ttdev.ss.SimpleServiceStub.ConcatRequest.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
if (com.ttdev.ss.SimpleServiceStub.ConcatResponse.class.equals(type)){
return com.ttdev.ss.SimpleServiceStub.ConcatResponse.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
} catch (java.lang.Exception e) {
throw org.apache.axis2.AxisFault.makeFault(e);
}
return null;
}
WSDL2Code.main(new String[] {
"-S", "src/main/java",
"-R", "src/main/resources/META-INF",
"-ns2p", "http://ttdev.com/ss=com.ttdev.ss",
"-uri", "src/main/resources/SimpleService.wsdl" });
我尝试使用axis2版本1.5.1和1.6.2,服务器是本地服务器,版本是1.6.2
我不能在这里发布wsdl代码。它就是不出现强>
但下面是用于生成存根类的代码-
private java.lang.Object fromOM(
org.apache.axiom.om.OMElement param,
java.lang.Class type,
java.util.Map extraNamespaces) throws org.apache.axis2.AxisFault{
try {
if (com.ttdev.ss.SimpleServiceStub.ConcatRequest.class.equals(type)){
return com.ttdev.ss.SimpleServiceStub.ConcatRequest.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
if (com.ttdev.ss.SimpleServiceStub.ConcatResponse.class.equals(type)){
return com.ttdev.ss.SimpleServiceStub.ConcatResponse.Factory.parse(param.getXMLStreamReaderWithoutCaching());
}
} catch (java.lang.Exception e) {
throw org.apache.axis2.AxisFault.makeFault(e);
}
return null;
}
WSDL2Code.main(new String[] {
"-S", "src/main/java",
"-R", "src/main/resources/META-INF",
"-ns2p", "http://ttdev.com/ss=com.ttdev.ss",
"-uri", "src/main/resources/SimpleService.wsdl" });
感谢您的帮助。顺便说一句,当我尝试使用CXF时,它是有效的。这要么是一个bug,要么是我从有效的WSDL生成java代码时出错了。这是1.6.2版的bug!我把服务器版本降到了1.5.1,它可以正常工作了!我希望这能帮助其他在axis2中苦苦寻找答案的人(就像我一样)。即使在1.6.1中,错误仍然存在,但在1.5.1中仍然可以完美地工作。1.5.1是没有出现错误的最新版本吗?这就是我降级到的版本。它可以使用1.5.x+