Axis2 problem with concurrent requests mismatch response object
I'm facing a problem on my production server for a Web Service with concurrent requests.
The problem is that when the Web Service receives (for instance) two requests for two different methods (each method returning a different object) in the same service, the Web Service will return the object type of the second request.
To replicate and simply the problem I create a simple Web Service with only one service and two methods with the same environment of the production server.
Code (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;
}
}
Configurations (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="Ser开发者_运维技巧viceClass" locked="false">test.RequestMethods</parameter>
</service>
Test
I've made a request for request1 and before this one returns, made another request for request2.
Result for request1 (the first request but the second obtained response):
<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>
Result for request2 (the second request but the first obtained response):
<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>
As you can see above, the response for request1 it should be of type request1Response but it's from request2Response instead.
The environment I'm using is:
- Tomcat 5.5.25 for the application server
- Axis2 1.2 for the Web Service
- Java version 1.5.0_11
Is anyone also facing this problem or knows how to solve it? I already tried to change the Axis2 version to 1.6 but the problem persists.
Any help is well appreciated.
Regards, João
Found the solution for this problem.
When you have a service (RequestMethods) with more than one method defined (request1 and request2), it's necessary to set one RPCMessageReceiver for each method to avoid concurrency problems.
You can define one MessageReceiver for each method on file services.xml.
In the example I post, the file services.xml should be like this:
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>
精彩评论