请教:客户端调用web service服务异常!

sxjida 2008-05-22 12:16:49
使用web services explorer的WSDL页面直接调用web service服务,
或者使用axis2自动生成客户端stub类代理和JUnit测试类调用web service服务时:
1、客户端报错空指针异常:
[ERROR] Exception occurred while trying to invoke service method getTermInfoById
java.lang.reflect.InvocationTargetException
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.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:194)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:98)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:96)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:145)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:275)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:120)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at dataAccess.TermInfo.getTermInfoById(TermInfo.java:450)
... 25 more




2、debug跟踪后得知,是调用getStatement()未成功,返回空指针导常
但在服务器端用main()方法测试数据库连接成功,可以正确查询数据库
而客户端调用web service,调用到getStatement()时,报错连接超时,
请大虾们指点啊!
[INFO] Unable to sendViaPost to url[http://localhost:8080/axis2/services/TermInfo]
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:346)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:542)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:189)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:364)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:208)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:448)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:401)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:228)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:163)
at dataaccess.TermInfoStub.ifTheTermIsExistByLabelCh(TermInfoStub.java:5900)
at dataaccess.TermInfoTest.testifTheTermIsExistByLabelCh(TermInfoTest.java:791)
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 junit.framework.TestCase.runTest(TestCase.java:164)
at junit.framework.TestCase.runBare(TestCase.java:130)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:120)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
...全文
11484 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangchh1988 2012-03-01
  • 打赏
  • 举报
回复
按照3楼的答案 我的问题也解决啦
qinqin32 2011-04-13
  • 打赏
  • 举报
回复
有不有不同的答案?
hit_guyuexinyuan 2010-12-23
  • 打赏
  • 举报
回复
楼主,太感谢你了,我也碰到你的问题,改了后好使了!
nixjojo 2010-03-11
  • 打赏
  • 举报
回复
3楼的,具体是怎么解决的?我也遇到同样的问题
wuly505 2009-12-31
  • 打赏
  • 举报
回复
options.setTimeOutInMilliSeconds(600000L);
span_sky 2009-04-15
  • 打赏
  • 举报
回复
请问,你是在哪修改的响应时间的,我也出现了这个错误,搞了两天了也没搞出来,把你解决这个问题的全部过程告诉我可以吗?谢谢,如果可以的话,请发我邮箱471957318@qq.com
sxjida 2008-05-25
  • 打赏
  • 举报
回复
问题已解决,一方面是数据库驱动没有放到%TOMCAT_HOME%\webapps\axis2\WEB-INF\lib下面,
另一方面有服务调用超时问题,自定义设置了调用响应时间
sxjida 2008-05-23
  • 打赏
  • 举报
回复
多谢楼上支持!
服务应该是已经启动了,
http://localhost:8080/axis2/services/TermInfo不能直接访问,
但wsdl可以访问,即http://localhost:8080/axis2/services/TermInfo?wsdl可以访问,
而且, 用MyEclipse 的web services explorer浏览器的WSDL页面
可以看到Invoke a WSDL Operation,Enter the parameters of this WSDL operation and click Go to invoke. Endpoints http://localhost:8080/axis2/services/TermInfo
Body ifTheTermIsExistById ....等页面操作
但加参数,调用执行后报上面的空指针错误。
另外,如果使用axis2自动生成Client端的代理类TermInfoStub和JUnit Test类TermInfoTest,调用web service服务时,debug跟踪,执行到_operationClient.execute(true);时出现上面的空指针异常(详细代码如下),如果debug跟进去的话,
会执行调用,连接数据库调用到getStatement()时,报错连接超时,[INFO] Unable to sendViaPost to url[http://localhost:8080/axis2/services/TermInfo]
java.net.SocketTimeoutException: Read timed out
我怀疑是不是和客户端调用模式有关系啊?

/**
* Auto generated method signature
*
* @see dataaccess.TermInfo#ifTheTermIsExistById
* @param ifTheTermIsExistById23
*
* @throws dataaccess.ExceptionException0 :
*/

public dataaccess.TermInfoStub.IfTheTermIsExistByIdResponse ifTheTermIsExistById(

dataaccess.TermInfoStub.IfTheTermIsExistById ifTheTermIsExistById23)

throws java.rmi.RemoteException

, dataaccess.ExceptionException0 {
org.apache.axis2.context.MessageContext _messageContext = null;
try {
org.apache.axis2.client.OperationClient _operationClient = _serviceClient
.createClient(_operations[12].getName());
_operationClient.getOptions().setAction("urn:ifTheTermIsExistById");
_operationClient.getOptions().setExceptionToBeThrownOnSOAPFault(
true);

addPropertyToOperationClient(
_operationClient,
org.apache.axis2.description.WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR,
"&");

// create a message context
_messageContext = new org.apache.axis2.context.MessageContext();

// create SOAP envelope with that payload
org.apache.axiom.soap.SOAPEnvelope env = null;

env = toEnvelope(getFactory(_operationClient.getOptions()
.getSoapVersionURI()), ifTheTermIsExistById23,
optimizeContent(new javax.xml.namespace.QName(
"http://dataAccess", "ifTheTermIsExistById")));

// adding SOAP soap_headers
_serviceClient.addHeadersToEnvelope(env);
// set the message context with that soap envelope
_messageContext.setEnvelope(env);

// add the message contxt to the operation client
_operationClient.addMessageContext(_messageContext);

_serviceClient.getOptions().setProperty(HTTPConstants.SO_TIMEOUT,new Integer(600000));
_serviceClient.getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT,new Integer(600000));


// execute the operation client
_operationClient.execute(true); /*
执行到此处时停止,捕捉到上面的空指针异常,
但如果跟进去的话,会继续,后面执行连接数据库操作时,
出现问题:[INFO] Unable to sendViaPost to url[http://localhost:8080/axis2/services/TermInfo]
java.net.SocketTimeoutException: Read timed out
*/


org.apache.axis2.context.MessageContext _returnMessageContext = _operationClient
.getMessageContext(org.apache.axis2.wsdl.WSDLConstants.MESSAGE_LABEL_IN_VALUE);
org.apache.axiom.soap.SOAPEnvelope _returnEnv = _returnMessageContext
.getEnvelope();

java.lang.Object object = fromOM(_returnEnv.getBody()
.getFirstElement(),
dataaccess.TermInfoStub.IfTheTermIsExistByIdResponse.class,
getEnvelopeNamespaces(_returnEnv));

return (dataaccess.TermInfoStub.IfTheTermIsExistByIdResponse) object;

} catch (org.apache.axis2.AxisFault f) {

org.apache.axiom.om.OMElement faultElt = f.getDetail();
if (faultElt != null) {
if (faultExceptionNameMap.containsKey(faultElt.getQName())) {
// make the fault by reflection
try {
java.lang.String exceptionClassName = (java.lang.String) faultExceptionClassNameMap
.get(faultElt.getQName());
java.lang.Class exceptionClass = java.lang.Class
.forName(exceptionClassName);
java.lang.Exception ex = (java.lang.Exception) exceptionClass
.newInstance();
// message class
java.lang.String messageClassName = (java.lang.String) faultMessageMap
.get(faultElt.getQName());
java.lang.Class messageClass = java.lang.Class
.forName(messageClassName);
java.lang.Object messageObject = fromOM(faultElt,
messageClass, null);
java.lang.reflect.Method m = exceptionClass.getMethod(
"setFaultMessage",
new java.lang.Class[] { messageClass });
m.invoke(ex, new java.lang.Object[] { messageObject });

if (ex instanceof dataaccess.ExceptionException0) {
throw (dataaccess.ExceptionException0) ex;
}

throw new java.rmi.RemoteException(ex.getMessage(), ex);
} catch (java.lang.ClassCastException e) {
// we cannot intantiate the class - throw the original
// Axis fault
throw f;
} catch (java.lang.ClassNotFoundException e) {
// we cannot intantiate the class - throw the original
// Axis fault
throw f;
} catch (java.lang.NoSuchMethodException e) {
// we cannot intantiate the class - throw the original
// Axis fault
throw f;
} catch (java.lang.reflect.InvocationTargetException e) {
// we cannot intantiate the class - throw the original
// Axis fault
throw f;
} catch (java.lang.IllegalAccessException e) {
// we cannot intantiate the class - throw the original
// Axis fault
throw f;
} catch (java.lang.InstantiationException e) {
// we cannot intantiate the class - throw the original
// Axis fault
throw f;
}
} else {
throw f;
}
} else {
throw f;
}
} finally {
_messageContext.getTransportOut().getSender().cleanup(
_messageContext);
}
}
老紫竹 2008-05-22
  • 打赏
  • 举报
回复
Caused by: java.lang.NullPointerException
at dataAccess.TermInfo.getTermInfoById(TermInfo.java:450)

第450行出现了空指针


java.net.SocketTimeoutException: Read timed out

你根本没有启动这个服务吧!
在浏览器里面输入
http://localhost:8080/axis2/services/TermInfo
看看有东西吗??

8,909

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧