【问题标题】:Axis2 problem with concurrent requests mismatch response object并发请求不匹配响应对象的 Axis2 问题
【发布时间】:2011-07-30 01:08:57
【问题描述】:

我在生产服务器上遇到了一个带有并发请求的 Web 服务的问题。

问题在于,当 Web Service 收到(例如)针对同一服务中两个不同方法的两个请求(每个方法返回不同的对象)时,Web Service 将返回第二个请求的对象类型。

为了复制和简化问题,我创建了一个简单的 Web 服务,它只有一个服务和两种方法,与生产服务器的环境相同。

代码(RequestMethods.class

package test;

import beans.Request1Response;
import beans.Request2Response;

public class RequestMethods {

    public Request1Response request1() {
        Request1Response output = new Request1Response();

        try {
            Thread.sleep(10 * 1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        output.setError_code(1);
        output.setError_msg("message1");

        return output;
    }

    public Request2Response request2() {
        Request2Response output = new Request2Response();

        output.setError_code(2);
        output.setError_msg("message2");

        return output;
    }

}

配置(services.xml

<service name="RequestMethods">
    <Description>
        Concurrent Requests test
    </Description>
    <messageReceivers>
        <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
        <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"  class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    </messageReceivers>
    <parameter name="ServiceClass" locked="false">test.RequestMethods</parameter>
</service>

测试

我已经对 request1 提出了一个请求,在此请求返回之前,我又对 request2 提出了另一个请求。

request1 的结果(第一个请求但第二个获得响应):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:request2Response xmlns:ns="http://test/xsd">
         <ns:return>
            <error_code xmlns="http://beans/xsd">1</error_code>
            <error_msg xmlns="http://beans/xsd">message1</error_msg>
         </ns:return>
      </ns:request2Response>
   </soapenv:Body>
</soapenv:Envelope>

request2 的结果(第二个请求但第一个获得响应):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <ns:request2Response xmlns:ns="http://test/xsd">
         <ns:return>
            <error_code xmlns="http://beans/xsd">2</error_code>
            <error_msg xmlns="http://beans/xsd">message2</error_msg>
         </ns:return>
      </ns:request2Response>
   </soapenv:Body>
</soapenv:Envelope>

正如您在上面看到的,request1 的响应应该是 request1Response 类型,但它来自 request2Response

我使用的环境是:

  • Tomcat 5.5.25 用于应用服务器
  • 用于 Web 服务的 Axis2 1.2
  • Java 版本 1.5.0_11

是否有人也面临这个问题或知道如何解决? 我已经尝试将 Axis2 版本更改为 1.6,但问题仍然存在。

非常感谢任何帮助。

问候, 若昂

【问题讨论】:

    标签: java axis2


    【解决方案1】:

    找到了解决这个问题的办法。

    当您的服务 (RequestMethods) 定义了多个方法(request1request2)时,有必要设置一个 RPCMessageReceiver 为每个方法避免并发问题。

    您可以为文件services.xml中的每个方法定义一个MessageReceiver

    在我发布的示例中,文件 services.xml 应该是这样的:

    services.xml

    <service name="RequestMethods">
        <Description>
            Concurrent Requests test
        </Description>
        <operation name="request1"> 
            <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> 
        </operation>
        <operation name="request2"> 
            <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> 
        </operation> 
        <parameter name="ServiceClass" locked="false">test.RequestMethods</parameter>
    </service>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-03
      相关资源
      最近更新 更多