我在理解如何向我已部署的Web服务发送请求时遇到一些问题。我遵循了以下教程: http://wso2.org/library/1719
我已成功申请,并且运作良好。该教程很简单,我很容易生成一个Web服务客户端。我所做的只是从公开的Web服务方法创建“请求”对象,设置其参数,然后使用Web服务存根,我已将请求对象传递给公开的Web服务方法,并得到响应。
现在,我收到了一个WSDL文件,我也应该从中构建一个Web服务客户端。问题是WSDL生成的文件与我遵循的教程有很大不同。后来我了解到,当使用ADB生成客户端时,有一种称为“扩展模式”的模式,它为每个外部元素和命名的复杂类型生成“一个类”(http://axis.apache.org/axis2/的java /型芯/文档/ ADB / ADB-howto.html#gen_modes)。问题是我无法理解如何创建请求对象并从生成的类中获取Web服务的响应。我最好的镜头如下:
GetMfrInventoryProductItemsListE wrapper = new GetMfrInventoryProductItemsListE();
GetMfrInventoryProductItemsList request = new GetMfrInventoryProductItemsList();
request.setArg0(deviceId);
request.setArg1(macAddresses);
request.setArg2(mfrKey);
wrapper.setGetMfrInventoryProductItemsList(request);
GetMfrInventoryProductItemsListResponseE wrapperResponse = wmService.getMfrInventoryProductItemsList(wrapper);
GetMfrInventoryProductItemsListResponse response = wrapperResponse.getGetMfrInventoryProductItemsListResponse();
return response.get_return();
在上面的代码中, getGetMfrInventoryProductItemsList 是我公开的Web服务方法的名称, wmService 是我的存根。
结果是以下堆栈跟踪:
org.apache.axis2.AxisFault: Read timed out
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at wavemark.wmservice.soap.WMServiceStub.getMfrInventoryProductItemsList(WMServiceStub.java:3275)
at wavemark.linkserver.supplierconnect.controller.WsStub.getMfrInventoryProductItemsList(WsStub.java:107)
at wavemark.linkserver.supplierconnect.controller.WsManager.getProductItems(WsManager.java:384)
at wavemark.linkserver.supplierconnect.webservices.SupplierConnect.getProductItems(SupplierConnect.java:396)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
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.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
... 42 more
在尝试调试问题之后,我发现这是抛出异常的行:
GetMfrInventoryProductItemsListResponseE wrapperResponse = wmService.getMfrInventoryProductItemsList(wrapper);
我只是想让你们告诉我,我使用请求/响应对象的方式是否正确。非常感谢您的帮助。
答案 0 :(得分:0)
最后,我想出了如何解决问题。显然,我正在进行的Web服务调用正在花费大量时间,因为堆栈跟踪显示它已超时。所以我将以下代码添加到我实例化客户端存根的部分:
wmService = new WMServiceStub();
Options options = new Options();
EndpointReference epr = new EndpointReference(url);
options.setTo(epr);
options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(300000));
wmService._getServiceClient().setOptions(options);
这导致Axis 2 Web服务的套接字超时增加到5分钟,这对于大多数Web服务调用来说应该足够了。我希望这对那里的一些开发者有所帮助。