Out handlers called twice
-------------------------
Key: XFIRE-747
URL: http://jira.codehaus.org/browse/XFIRE-747
Project: XFire
Issue Type: Bug
Components: Core
Affects Versions: 1.2.2
Environment: Linux, JDK 1.5.0_06
Reporter: PJ
Assigned To: Dan Diephouse
Priority: Critical
Out handlers are called twice if webservice method calls another webservice via
Client API.
Service interface:
@WebService
public interface ITestService
{
public void a();
public void b();
}
Service implementation:
@WebService (endpointInterface="test.ITestService")
public class TestService implements ITestService
{
public void a()
{
AnnotationServiceFactory factory = new
AnnotationServiceFactory();
Service service = factory.create(TestService.class);
try
{
ITestService test = (ITestService) new
XFireProxyFactory().create(service,
"http://localhost:8080/test/services/TestService");
test.b(); // while invoking b() out handler
pipeline is called, why???
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
}
public void b()
{
}
}
Example in handler:
public class TransactionBeginHandler extends AbstractHandler
{
public void invoke(MessageContext context) throws Exception
{
Context ctx = new InitialContext();
UserTransaction ut = (UserTransaction)
ctx.lookup("java:comp/UserTransaction");
ut.begin();
}
}
Example out handler:
public class TransactionCommitHandler extends AbstractHandler
{
public void invoke(MessageContext context) throws Exception
{
InitialContext ctx = new InitialContext();
UserTransaction ut = (UserTransaction)
ctx.lookup("java:comp/UserTransaction");
ut.commit();
}
}
services.xml:
<beans xmlns="http://xfire.codehaus.org/config/1.0">
<xfire>
<inHandlers>
<handler handlerClass="test.TransactionBeginHandler" />
</inHandlers>
<outHandlers>
<handler handlerClass="test.TransactionCommitHandler" />
</outHandlers>
</xfire>
<service>
<serviceClass>test.TestService</serviceClass>
<serviceFactory>jsr181</serviceFactory>
</service>
</beans>
Test client:
public class Test
{
public static void main(String[] args) throws MalformedURLException
{
AnnotationServiceFactory factory = new
AnnotationServiceFactory();
Service service = factory.create(TestService.class);
ITestService test = (ITestService) new
XFireProxyFactory().create(service,
"http://localhost:8080/test/services/TestService");
test.a();
}
}
When test client calls method a() below sequence happens:
1. TransactionBeginHandler is executed on thread one (T1)
2. Method a() is executed on T1
2a. Another webservice is called from inside a() method, and for
unknown reason whole out handlers pipeline is invoked, so...
2b. TransactionCommitHandler is executed on T1
3. TransactionBeginHandler is executed on thread two (T2)
4. Method b() is executed on T2
5. TransactionCommitHandler is executed on T2
6. TransactionCommitHandler is executed on T1
Exception occurs, because second execution of TransactionCommitHandler on T1
tries to commit already commited transaction. Besides, if after calling b()
some database operations occurs in method a() exception will be thrown because
there is no active transaction.
In my test I've called another webservice on the same server (thus notation of
two threads, T1 handles a() invocation, T2 handles b() invocation), but it
doesn't matter - calling whatever webservice results in invoking handlers
pipeline.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email