简体   繁体   English

Java Axis2 Web Service调用JAX-WS客户端jar

[英]Java Axis2 Web Service calling JAX-WS client jar

I have an Axis2 (1.5.1) Web Service deployed on Tomcat 6, and I am trying to call the VMware Web Services SDK (JAX-WS service). 我在Tomcat 6上部署了Axis2(1.5.1)Web服务,我正在尝试调用VMware Web Services SDK(JAX-WS服务)。 This fails since the I need to maintain sessions (SESSION_MAINTAIN_PROPERTY = true). 由于我需要维护会话(SESSION_MAINTAIN_PROPERTY = true),因此失败。 Is there any way to circumvent Axis2 when calling the JAX-WS client jar? 调用JAX-WS客户端jar时有没有办法绕过Axis2?

Here is the stack trace: 这是堆栈跟踪:

javax.xml.ws.WebServiceException: Error: Maintain Session is enabled but none of the session properties (Cookies, Over-written URL) are returned.
    at org.apache.axis2.jaxws.ExceptionFactory.createWebServiceException(ExceptionFactory.java:173)
    at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:70)
    at org.apache.axis2.jaxws.ExceptionFactory.makeWebServiceException(ExceptionFactory.java:118)
    at org.apache.axis2.jaxws.BindingProvider.setupSessionContext(BindingProvider.java:242)
    at org.apache.axis2.jaxws.BindingProvider.checkMaintainSessionState(BindingProvider.java:209)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invokeSEIMethod(JAXWSProxyHandler.java:320)
    at org.apache.axis2.jaxws.client.proxy.JAXWSProxyHandler.invoke(JAXWSProxyHandler.java:159)
    at com.sun.proxy.$Proxy12.retrieveServiceContent(Unknown Source)
    at com.company.product.CredAuthHostSkeleton.getAuthKey(Unknown Source)
    at com.company.product.CredAuthHostMessageReceiverInOut.invokeBusinessLogic(Unknown Source)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:173)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:167)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:142)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    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:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    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:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)

Problem 问题

The problem turned out to be threefold. 问题结果是三重的。 The first issue was an out-of-date Axis2 version (1.5.1), and the other two issues were code based. 第一个问题是过时的Axis2版本(1.5.1),另外两个问题是基于代码的。

Solution

After upgrading the Axis version to the latest version (went from 1.5.1 to 1.7.4), the following code changes fixed the issue: 将Axis版本升级到最新版本(从1.5.1升级到1.7.4)后,以下代码更改修复了此问题:

  1. Since Axis2 expects the name of the session cookie to be JSESSIONID and VMware returns vmware_soap_session, the CUSTOM_COOKIE_ID property need to be set so that Axis2 detects that the session cookie is set. 由于Axis2期望会话cookie的名称为JSESSIONID,而VMware返回vmware_soap_session,因此需要设置CUSTOM_COOKIE_ID属性,以便Axis2检测到会话cookie已设置。

     VimService vimService = new VimService(); VimPortType vimPort = vimService.getVimPort(); Map<String, Object> ctxt = ((BindingProvider)vimPort).getRequestContext(); ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString()); ctxt.put(org.apache.axis2.Constants.CUSTOM_COOKIE_ID, "vmware_soap_session"); ctxt.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true); 
  2. When Axis2 maintains sessions, it expects the first call to set the session cookie. 当Axis2维护会话时,它需要第一次调用来设置会话cookie。 The first call to the VMware API to retrieve the service content does not need a session, so it doesn't return a cookie. 第一次调用VMware API来检索服务内容不需要会话,因此它不会返回cookie。 The solution here was to add another VimService and VimPortType to be used exclusively for retrieving the service content. 这里的解决方案是添加另一个VimService和VimPortType,专门用于检索服务内容。 After these changes the login call will work. 完成这些更改后,登录调用将起作用。

     VimService vimServiceRSC = new VimService(); VimPortType vimPortRSC = vimService.getVimPort(); Map<String, Object> ctxtRSC = ((BindingProvider)vimPortRSC).getRequestContext(); ctxtRSC.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url.toString()); ServiceContent serviceContent = vimPortRSC.retrieveServiceContent(this.getServiceInstanceRef()); vimPort.login(serviceContent.getSessionManager(), "user", "password", null); 

The code changes are shown using snippets of the sample code provided with the VMware SDK. 使用VMware SDK提供的示例代码片段显示代码更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM