IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Spring Java Discussion :

Problème bean exposé via RMI [Integration]


Sujet :

Spring Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Mai 2002
    Messages
    94
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Mai 2002
    Messages : 94
    Par défaut Problème bean exposé via RMI
    Bonjour,

    J'ai posté un message hier au sujet de ce problème sur le forum Spring (http://forum.springframework.org/showthread.php?t=54163). N'ayant eu aucune réponse je viens vous demander un peu d'aide.

    Je développe un petit serveur qui expose ses services via RMI. Les services pourront ainsi être appelés à distance.

    L'inteface (simplifée) de ce service est la suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    public interface ServerService {
        long countAnalysisEngines();
    }
    L'implémentation du service :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    @Service("serverService")
    public class ServerServiceImpl implements ServerService 
    {
        @Autowired
        private UimaComponentService uimaComponentService;
     
        public long countAnalysisEngines() {
            return this.uimaComponentService.countAnalysisEngines();
        }
    }
    countAnalysisEngines() exécute une requête via Hibernate et retourne un nombre.
    Le test de cette fonction se comporte correctement:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    ...
    public class ServerServiceTest  {
     
      @Autowired
      @Qualifier("serverService")
    //  @Qualifier("serverServiceClient")
      private ServerService serverService;
     
     @Test
     public void testCountAnalysisEngines() throws Exception {
      assertThat(super.serverService.countAnalysisEngines()).isEqualTo(0);
      ...
     }
    }
    Mon problème intervient lorsque je souhaite exporter ce service via RMI. Ma configuration Spring permettant cette exportation est la suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
      <property name="serviceName" value="ServerService" />
      <property name="service" ref="serverService" />
      <property name="serviceInterface" value="com.thales.imp.secondaryserver.services.ServerService" />
      <property name="registryPort" value="1099" />
    </bean>
    Pour rendre l'appel à ce service possible sur les clients j'utilise la configuration suivante:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    <bean id="serverServiceClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
      <property name="serviceUrl" value="rmi://localhost:1099/ServerService" />
      <property name="serviceInterface" value="com.thales.imp.secondaryserver.services.ServerService" />
    </bean>
    Maintenant je réeffectue mon test sauf que cette fois-ci je n'utilise pas le service "directement" mais j'injecte je proxy RMI (stub):
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     
    ...
    public class ServerServiceTest  {
     
      @Autowired
    //  @Qualifier("serverService") 
      @Qualifier("serverServiceClient")   // Injection du proxy via RmiProxyFactoryBean
      private ServerService serverService;
     
     @Test
     public void testCountAnalysisEngines() throws Exception {
      assertThat(super.serverService.countAnalysisEngines()).isEqualTo(0); // Plante ici 
      ...
     }
    }
    A l'exécution de ce test l'erreur suivante apparaît:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    INFO 2008-05-13 18:54:59,078 (RmiServiceExporter.java:271) - Binding service 'ServerService' to RMI registry: RegistryImpl[UnicastServerRef [liveRef: [endpoint:[139.40.210.19:1099](local),objID:[0:0:0, 0]]]]
    DEBUG 18:54:59.234 - c.t.i.s.s.i.UimaComponentServiceImpl:114 - Counting Analysis Engines components.
    DEBUG 18:54:59.250 - c.t.i.s.d.c.h.HbmUimaComponentDao:61 - Counting Analysis Engines components.
    WARN 2008-05-13 18:54:59,265 (RemoteInvocationTraceInterceptor.java:80) - Processing of RmiServiceExporter remote call resulted in fatal exception: com.thales.imp.secondaryserver.services.ServerServ ice.countAnalysisEngines
    org.springframework.orm.hibernate3.HibernateSystem Exception: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here; nested exception is org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    at org.springframework.orm.hibernate3.SessionFactoryU tils.convertHibernateAccessException(SessionFactor yUtils.java:661)
    at org.springframework.orm.hibernate3.AbstractSession FactoryBean.convertHibernateAccessException(Abstra ctSessionFactoryBean.java:303)
    at org.springframework.orm.hibernate3.AbstractSession FactoryBean.translateExceptionIfPossible(AbstractS essionFactoryBean.java:282)
    at org.springframework.dao.support.ChainedPersistence ExceptionTranslator.translateExceptionIfPossible(C hainedPersistenceExceptionTranslator.java:62)
    at org.springframework.dao.support.DataAccessUtils.tr anslateIfNecessary(DataAccessUtils.java:212)
    at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:146)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy30.countAnalysisEngines(Unknown Source)
    at com.thales.imp.secondaryserver.services.impl.UimaC omponentServiceImpl.countAnalysisEngines(UimaCompo nentServiceImpl.java:116)
    at com.thales.imp.secondaryserver.services.impl.Serve rServiceImpl.countAnalysisEngines(ServerServiceImp l.java:53)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:310)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149)
    at org.springframework.remoting.support.RemoteInvocat ionTraceInterceptor.invoke(RemoteInvocationTraceIn terceptor.java:70)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy33.countAnalysisEngines(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.remoting.support.RemoteInvocat ion.invoke(RemoteInvocation.java:205)
    at org.springframework.remoting.support.DefaultRemote InvocationExecutor.invoke(DefaultRemoteInvocationE xecutor.java:38)
    at org.springframework.remoting.support.RemoteInvocat ionBasedExporter.invoke(RemoteInvocationBasedExpor ter.java:78)
    at org.springframework.remoting.rmi.RmiBasedExporter. invoke(RmiBasedExporter.java:72)
    at org.springframework.remoting.rmi.RmiInvocationWrap per.invoke(RmiInvocationWrapper.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastSe rverRef.java:305)
    at sun.rmi.transport.Transport$1.run(Transport.java:1 59)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport. java:155)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages( TCPTransport.java:535)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run0(TCPTransport.java:790)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandl er.run(TCPTransport.java:649)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:885)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:907)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
    at org.springframework.orm.hibernate3.SpringSessionCo ntext.currentSession(SpringSessionContext.java:63)
    at org.hibernate.impl.SessionFactoryImpl.getCurrentSe ssion(SessionFactoryImpl.java:544)
    at com.thales.imp.server.dao.hbm.AbstractHbmImpDao.cr eateQuery(AbstractHbmImpDao.java:185)
    at com.thales.imp.secondaryserver.dao.component.hbm.H bmUimaComponentDao.countAnalysisEngines(HbmUimaCom ponentDao.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:310)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.invokeJoinpoint(ReflectiveMethodInvocat ion.java:182)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :149)
    at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:138)
    ... 39 more
    Il semble qu'il y ait un problème avec Hibernate mais je n'arrive pas à comprendre pourquoi !!!

    Peut-être que ceci vient du fait que lorsque j'utilise le proxy RMI le code client ne s'exécute pas dans le même Thread que le code serveur (le code du service exporté) ???

    Comment résoudre ce problème ???

    Merci.

  2. #2
    Membre confirmé
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Mai 2002
    Messages
    94
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : France, Val de Marne (Île de France)

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Mai 2002
    Messages : 94
    Par défaut
    J'ai finalement résolu mon problème, si quelqu'un rencontre le même voici ce que j'ai modifié.

    J'ai ajouté ceci àma conf XML afin d'activer les transactions:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <tx:annotation-driven transaction-manager="transactionManager"/>
    et ceci à ma classe de service:
    Avant je réalisait un test en utilisant la configuration suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    @RunWith(SpringJUnit4ClassRunner.class)
    @TransactionConfiguration(transactionManager = "transactionManager")
    @Transactional
    public class ServerServiceTest  {
    ...
    }
    Mes fonctions de test était donc transactionnelles, mon test marchait en utilisant directement mon service.

    Je pense qu'en utilisant le proxy RMI (à la place du service directement) Spring devait exposer mon service "dans un context non transactionnel" avant d'initialiser le context de test (TestContext ou quelque chose comme ça il me semble), donc le service ne s'exécutait plus dans une transaction.

    L'ajout de l'annotation @Transactionnal était donc indispensable, surtout qu'en dehors des tests il fallait bien qu'il s'exécute dans une transaction.

    Voilà, merci .

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 6
    Par défaut
    Merci, très clair et très utile.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [LDAP] Problème d'authentification via PHP
    Par navis84 dans le forum Bibliothèques et frameworks
    Réponses: 4
    Dernier message: 21/07/2006, 09h45
  2. [C#] Problème requête update via OdbcDataAdpter
    Par LE NEINDRE dans le forum ASP.NET
    Réponses: 12
    Dernier message: 16/06/2006, 11h52
  3. Probléme de connexion via un reseau local
    Par aurelien083 dans le forum SQL Procédural
    Réponses: 4
    Dernier message: 15/03/2006, 17h07
  4. probléme avec include() via HTTP
    Par schlitters dans le forum Langage
    Réponses: 11
    Dernier message: 07/02/2006, 17h19
  5. [XSL]problème de liens via feuille de style, images....
    Par snoop dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 29/06/2005, 10h57

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo