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.
Code:
<bean id="xDslService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean">
<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:
Code:
public class SynchronizationDecorator implements MethodInterceptor
{
Semaphore sem;
/** Creates a new instance of SynchronizationDecorator */
public SynchronizationDecorator()
{
sem = new Semaphore(1);
}
public Object invoke(MethodInvocation invocation) throws Throwable
{
// System.out.println("Wait for semaphore queue (" + sem.getQueueLength() + ")");
sem.acquireUninterruptibly();
Object retVal = invocation.proceed();
sem.release();
return retVal;
}
}
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.