PDA

View Full Version : JaxRpcPortProxyFactoryBean and threading



johannes
Aug 4th, 2005, 02:00 AM
Hi,

I have an new webapplication running under tomcat that is accessing a webservice with axis (Jax-RPC) and spring. This works nice as long as not more than one request is accessing the service at the same time.
The service is defined in applicationContext.xml:

<bean id="xDslService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean"> .......

Every request calls several functions of the service in successing order. I usually then get an exception like this:
org.xml.sax.SAXException: Bad types (class services.TestRoundTripTimeResult -> class services.TestLineQual
ityResult)

Obviously the function returns the wrong type. It returns the the type of another function of the service that a parallel request is calling (or has called). As I said with no parallel calls to the service everything works fine.

Now my question is if I have to consider something special? Should it work that way generally? Maybe also the service I am calling does something wrong as I am the first client of it. Is this more likley?
Any help and ideas are appreciated.
Regards,
Johannes

johannes
Aug 11th, 2005, 05:37 AM
I now don't access the WebService with JaxRpcPortFactoryBean anymore, but in the "standard" Axis way (with a Locator). And with this the described problems don't occur anymore. So it might be really a problem with JaxRpcPortFactoryBean. Someone else described the same or a very similar problem here:
http://forum.springframework.org/showthread.php?t=16591

By the way I am using Spring 1.2.1

Maybe someone has an idea how I can work around this problem. I would really like to be able to switch between a fake service and the real service via applicationContext.xml. If I have to drop JaxRpcPortFactoryBean then I can't do this anymore.
Thanks,

Johannes

yrgo
Aug 11th, 2005, 08:04 AM
I would suggest to use pool of proxies so that each proxy is used only by single thread at a time. For pooling something like org.sprfr.aop.target.CommonsPoolTargetSource can be used.

isusanin
Aug 11th, 2005, 03:21 PM
I was having the same problem with JaxRpcPortProxyFactoryBean and Axis. As soon as you have more than one thread using the JaxRpcPortProxyFactoryBean, all kinds of weird Exceptions occur. I was getting NullPointer and ClassCast exceptions. I'm not sure how you can pool JaxRpcPortProxyFactoryBean since it can only be declared as a singleton.

My solution was to just make the proxy bean synchronized.



<bean id="xDslService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProx yFactoryBean">

<bean id="synchronizationDecorator" class="SynchronizationDecorator" />

<bean id="xDslServiceSync"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyInterfaces"><value>DslServiceInterface</value></property>
<property name="target"><ref local="xDslService"/></property>
<property name="interceptorNames">
<list>
<value>synchronizationDecorator</value>
</list>
</property>
</bean>

And the SynchronizationDecorator looks like this:


public class SynchronizationDecorator implements MethodInterceptor
&#123;
Semaphore sem;

/** Creates a new instance of SynchronizationDecorator */
public SynchronizationDecorator&#40;&#41;
&#123;
sem = new Semaphore&#40;1&#41;;
&#125;

public Object invoke&#40;MethodInvocation invocation&#41; throws Throwable
&#123;
// System.out.println&#40;"Wait for semaphore queue &#40;" + sem.getQueueLength&#40;&#41; + "&#41;"&#41;;

sem.acquireUninterruptibly&#40;&#41;;

Object retVal = invocation.proceed&#40;&#41;;

sem.release&#40;&#41;;

return retVal;
&#125;
&#125;

Now if you use the xDslServiceSync bean, the concurrency problems go away, at the price of possibly slowing your application down because now only one thread at a time can access the web service.

johannes
Aug 12th, 2005, 04:35 AM
Unfortunatelly the synchronised version is no option for me as this would mean the clients would have to wait even longer for results, which already is problematic.
Anyway thank you very much for your suggestions.

Johannes