Results 1 to 5 of 5

Thread: JaxRpcPortProxyFactoryBean and threading

  1. #1
    Join Date
    Jul 2005
    Posts
    5

    Default JaxRpcPortProxyFactoryBean and threading

    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.JaxRpcP ortProxyFactoryBean"> .......

    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

  2. #2
    Join Date
    Jul 2005
    Posts
    5

    Default maybe really a bug in Spring

    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
    Last edited by robyn; May 15th, 2006 at 05:49 PM.

  3. #3
    Join Date
    Nov 2004
    Posts
    3

    Default pooling of proxies

    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.

  4. #4
    Join Date
    Jul 2005
    Posts
    15

    Default

    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
    &#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.

  5. #5
    Join Date
    Jul 2005
    Posts
    5

    Default

    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

Similar Threads

  1. ApplicationContext and threading.
    By arrow_us_dc in forum Container
    Replies: 2
    Last Post: May 4th, 2005, 02:46 PM
  2. ContextSingletonBeanFactoryLocator threading?
    By shorecode in forum Container
    Replies: 2
    Last Post: Apr 22nd, 2005, 08:16 AM
  3. Threading question
    By dfischer in forum Container
    Replies: 13
    Last Post: Mar 21st, 2005, 08:13 AM
  4. Threading Question
    By java9394 in forum Web
    Replies: 1
    Last Post: Sep 15th, 2004, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •