-- 作者:sxjida
-- 发布时间:5/23/2008 9:31:00 AM
-- 请教客户端调用web service服务异常!
菜鸟初学,请大虾指点啊! 使用MyEclipse的web services explorer浏览器的WSDL页面直接调用web service服务, 或者使用axis2自动生成客户端stub类代理TermInfoStub和JUnit Test类TermInfoTest,调用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、如果使用axis2自动生成Client端的代理类TermInfoStub和JUnit Test类TermInfoTest,调用web service服务时,(详细代码见3), debug跟踪,执行到_operationClient.execute(true);时出现上面的空指针异常, 如果debug跟进去的话,会执行调用,连接数据库调用到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) 3./** * 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 [color=#FF0000] _operationClient.execute(true); /*执行到此处时停止,捕捉到异常,如果跟进去的话,会执行连接数据库操作,但出现问题:[INFO] Unable to sendViaPost to url[http://localhost:8080/axis2/services/TermInfo] java.net.SocketTimeoutException: Read timed out */[/color] 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); } }
|