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

Weblogic Java Discussion :

Test d'intégration EJB 3.1, JPA 2, Weblogic 12.1.2, No EJBContainer provider available


Sujet :

Weblogic Java

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 44
    Points : 31
    Points
    31
    Par défaut Test d'intégration EJB 3.1, JPA 2, Weblogic 12.1.2, No EJBContainer provider available
    Bonjour tout le monde,
    Je suis en traine de développer une petite application en utilisant EJB 3.1, JPA 2.0.
    Le serveur est Weblogic 12.1.2, et je dispose d'une petite base de données Oracle.

    Voici l'EJB à tester :

    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
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
     
    @Stateless
    public class DashboardEJB {
        private final Logger logger = Logger.getLogger(getClass());
        @PersistenceContext(unitName="MyPersistenceUnit")
        private EntityManager entityManager;
        public List<Indicator> findIndicators() {
            TypedQuery<Indicator> allIndicators = entityManager.createNamedQuery("findAllIndicators",
                    Indicator.class);
            return allIndicators.getResultList();
        }   
        public User updateUser(User user) {
            entityManager.merge(user);
            return user;
        }   
        public User save(User user) {
            entityManager.persist(user);
            return user;
        }   
        public User findUserById(String userId) {
            Query query = entityManager.createNamedQuery(User.FIND_USER_BY_ID);
            query.setParameter("userId", userId);
            User user = null;
            try{
                user = (User) query.getSingleResult();
            }catch(NoResultException nre){
                getLogger().info("no result found");
                return null;
            }
            return user;    
        }   
        public List<Abonnement> findAbonnementByUserId(String userId) {
            Query query = entityManager.createNamedQuery(Abonnement.FIND_BY_USER_ID);
            query.setParameter("userId", userId);
            List<Abonnement> abonnements = new ArrayList<Abonnement>();
            try {
                abonnements = query.getResultList();
            } catch (NoResultException nre) {
                getLogger().info("no result found");
                return null;
            }catch(Exception exc){
                getLogger().info("erreur !");
                exc.printStackTrace();
                return null;
            }
            return abonnements;
        }   
        public Indicator findByLabel(String label) {
            CriteriaBuilder cb = entityManager.getCriteriaBuilder();
            CriteriaQuery<Indicator> criteriaQuery = cb.createQuery(Indicator.class);
            Root<Indicator> ind = criteriaQuery.from(Indicator.class);
            criteriaQuery.where(cb.like(ind.<String> get("label"), cb.parameter(String.class, "label")));
            TypedQuery<Indicator> tq = entityManager.createQuery(criteriaQuery);
            tq.setParameter("label", label);
            Indicator indicator = null;     
            try{
                indicator = tq.getSingleResult();
            }catch(NoResultException nre){
                getLogger().info("no result found");
            }
            return indicator;
        }
        public DefaultDashboardModel findModel(int userPrefId) {
            TypedQuery<UserPreferences> query = entityManager.createNamedQuery("findUserPreferencesById", UserPreferences.class);
                query.setParameter("recipeId", userPrefId);
     
            UserPreferences userPref = null;
            DefaultDashboardModel model;
            try {
                userPref = (UserPreferences) query.getSingleResult();
                model = userPref.getSerializableModel();
                if (model == null) {
                    model = new DefaultDashboardModel();
                }
            } catch (NoResultException nre) {
                getLogger().info("no result found");
                return new DefaultDashboardModel();
            }
            return model;
        }
        public void updateAbonnement(Abonnement abonnement) {
            entityManager.merge(abonnement);
        }
        public void deleteAbonnement(Abonnement abonnement){
            entityManager.remove(abonnement);
        }
        public Logger getLogger() {
            return logger;
        }
    }
    et voici le fichier persistence.xml utilisé pour le teste:

    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
        version="2.0">
     
        <persistence-unit name="MyPersistenceUnit" transaction-type="RESOURCE_LOCAL">
            <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
            <properties>
                <property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
                <property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@myhost:1521:MyPersistenceUnit"/>
                <property name="javax.persistence.jdbc.user" value="toto"/>
                <property name="javax.persistence.jdbc.password" value="tata"/>
                <property name="eclipselink.logging.level" value="FINEST"/> 
            </properties>
        </persistence-unit>
    </persistence>
    Je dispose également d'un fichier beans.xml vide.
    Voici la classe de test:

    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
     
    public class AbonnementDAOImplTest {
        @Inject
        private static DashboardEJB dashboardEJB;
        private static EJBContainer ejbC;
        private static Context ctx;
        public AbonnementDAOImplTest() {
        }
        @BeforeClass
        public static void initEntityManager() throws Exception {
            // initialisation environnement JNDI
            ejbC = javax.ejb.embeddable.EJBContainer.createEJBContainer();
            ctx = ejbC.getContext();
     
    //      Properties properties = new Properties();
    //      properties.setProperty(EJBContainer.MODULES, "classes");
    //      
            // instanciation de l'EJB
         //  dashboardEJB = (DashboardEJB) ctx.lookup("java:global/aggregatordashboard/DashboardEJB");
        }
     
         @Before
         public void setUp()throws Exception {
            // instanciation de l'EJB
             //ctx.lookup("java:global/classes/GreeterBean");
             dashboardEJB = (DashboardEJB) ctx.lookup("java:global/aggregatordashboard/DashboardEJB");
         }
     
        @Test
        public void testFindAbonnementByUserId() {
            List<Abonnement> abonnemnts = dashboardEJB
                    .findAbonnementByUserId("userID");
            assertNotNull(abonnemnts.get(0).getUser().getUserId());
            assertEquals("userID", abonnemnts.get(0).getUser().getUserId());
            assertEquals("Kim", abonnemnts.get(0).getUser().getNom());
            assertEquals("Kam", abonnemnts.get(0).getUser().getPrenom());
        }
     
        @Test
        public void testUpdate() {
            List<Abonnement> abonnemnts = dashboardEJB
                    .findAbonnementByUserId("userID");
            Abonnement abnmt = abonnemnts.get(0);
            abnmt.setLastUpdateDate(new Date());
            dashboardEJB.updateAbonnement(abnmt);
        }
     
        @Test
        public void testDelete() {
            Abonnement abnmt = dashboardEJB.findAbonnementByUserId("userID").get(
                    0);
            dashboardEJB.deleteAbonnement(abnmt);
        }
    pour le embedded EJB container j'ai ajouté le jar weblogic.jar au classpath de l'application.

    Après exécution j'obtiens l'erreur suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
      <error message="No EJBContainer provider available: no provider names had been found." type="javax.ejb.EJBException">javax.ejb.EJBException: No EJBContainer provider available: no provider names had been found.
        at javax.ejb.embeddable.EJBContainer.reportError(EJBContainer.java:186)
        at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:121)
        at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:78)
        at fr.edf.sei.aggregator.dashboard.dao.test.AbonnementDAOImplTest.initEntityManager(AbonnementDAOImplTest.java:33)
    </error>
    Merci de votre aide.

  2. #2
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    l´erreur est tres clair, tu n´as pas d´objet EJB dans ton Projet:

    tu as sans doute oublié:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    @managedBean
    public class AbonnementDAOImplTest {

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Salut,
    D'abord merci pour ton retour.
    La classe DashboardEJB est bien un EJB vu qu'elle est annoté avec @Stateless.
    Suite à ton retour j'ai annoté la classe de test avec @Named, il me semble que c'est l'équivalent de @ManagedBean ?
    J'obtiens une autre erreur :

    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
     
    24 mars 2014 14 h 12 CET> <Info> <EmbeddedServer> <BEA-000000> <Embedded WebLogic Server 12.1.2.0.0  Fri Jun 7 15:16:15 PDT 2013 1530982 WLS_12.1.2.0.0_GENERIC_130607.1100> 
    <24 mars 2014 14 h 12 CET> <Info> <EmbeddedServer> <BEA-000000> <Embedded domain home C:\Users\MO0F487N\AppData\Local\Temp\domain-2014.03.24_14.12.45> 
    <24 mars 2014 14 h 12 CET> <Info> <EmbeddedServer> <BEA-000000> <Server starting. Waiting for RUNNING Status> 
    <24 mars 2014 14 h 12 CET> <Error> <EmbeddedServer> <BEA-000000> <FIXME - subject manager initialization invalid in class weblogic.server.embed.internal.ServerRunner> 
    <24 mars 2014 14 h 13 CET> <Info> <EmbeddedServer> <BEA-000000> <Server started.> 
    Exception in thread "[ACTIVE] ExecuteThread: '2' for queue: 'weblogic.kernel.Default (self-tuning)'" java.lang.OutOfMemoryError: PermGen space
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    	at weblogic.work.ExecuteThread.execute(ExecuteThread.java:303)
    	at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
    Exception in thread "Timer-1" java.lang.OutOfMemoryError: PermGen space
    	at java.lang.ClassLoader.defineClass1(Native Method)
    	at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
    	at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    	at weblogic.work.ServerWorkManagerImpl$1.debugEnabled(ServerWorkManagerImpl.java:41)
    	at weblogic.work.SelfTuningWorkManagerImpl.debugEnabled(SelfTuningWorkManagerImpl.java:605)
    	at weblogic.work.IncrementAdvisor.debugEnabled(IncrementAdvisor.java:653)
    	at weblogic.work.IncrementAdvisor.run(IncrementAdvisor.java:272)
    	at java.util.TimerThread.mainLoop(Timer.java:555)
    	at java.util.TimerThread.run(Timer.java:505)
    java.lang.OutOfMemoryError: PermGen space
    Exception in thread "Thread-3" java.lang.OutOfMemoryError: PermGen space

  4. #4
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    salut,
    merci, quelle version de Java utilises tu?
    c´est avec Eclipse ou NetBeans que vous programmer?

    je crois que c´est ici que ce trouve ton probleme:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
      ejbC = javax.ejb.embeddable.EJBContainer.createEJBContainer();
      ctx = ejbC.getContext();
    essaies ceci:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
      Map<String, Object> p = new HashMap<String, Object>();
                p.put(EJBContainer.APP_NAME, "TON_APP_NAME");
     
                p.put(EJBContainer.MODULES, new File("build/jar"));
     
     
                ejbC = EJBContainer.createEJBContainer(p);
                ctx = ejbC.getContext();
                System.out.println("pret pour chercher un EJB...");
    et donne nous le resultat.
    Eric

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    Bonjour,
    Désolé du retard, j'était un peu malade.
    J'utilise la version 7 de java, et j'utilise eclipse kepler.
    En fait depuis les EJB 3.1 ceux-ci peuvent être deployer directement dans un war.
    Donc je me suis permis de faire ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    Map<String, Object> p = new HashMap<String, Object>();
                p.put(EJBContainer.APP_NAME, "Appli_Name");
     
                p.put(EJBContainer.MODULES, new File("target/war"));
     
     
                ejbC = EJBContainer.createEJBContainer(p);
                ctx = ejbC.getContext();
                System.out.println("pret pour chercher un EJB...");
    J'obtiens l'erreur suivante :
    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
     
    javax.ejb.EJBException: Failed to deploy EJB modules - see log for details
    	at org.glassfish.ejb.embedded.EJBContainerImpl.deploy(EJBContainerImpl.java:150)
    	at org.glassfish.ejb.embedded.EJBContainerProviderImpl.createEJBContainer(EJBContainerProviderImpl.java:134)
    	at javax.ejb.embeddable.EJBContainer.createEJBContainer(EJBContainer.java:102)
    	at fr.edf.sei.aggregator.dashboard.test.AbonnementDAOImplTest.initEntityManager(AbonnementDAOImplTest.java:47)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
    	at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    	at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.lang.reflect.Method.invoke(Method.java:606)
    	at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    	at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    	at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
    Merci d'avance pour vos retours.

  6. #6
    Membre chevronné Avatar de jeffray03
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juillet 2008
    Messages
    1 501
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Allemagne

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Juillet 2008
    Messages : 1 501
    Points : 2 120
    Points
    2 120
    Par défaut
    Salut
    ou se trouve la ligne 47 du
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    AbonnementDAOImplTest.java:47

  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2008
    Messages
    44
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2008
    Messages : 44
    Points : 31
    Points
    31
    Par défaut
    la ligne 47 correspond à cette instruction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     ejbC = EJBContainer.createEJBContainer(p);

Discussions similaires

  1. Réponses: 0
    Dernier message: 24/06/2014, 08h34
  2. Tests d'intégration EJB avec Weblogic
    Par Pignoufy dans le forum Maven
    Réponses: 10
    Dernier message: 08/08/2011, 12h21
  3. [Struts][Hibernate][EJB3]Problème d'intégration EJB 3.0
    Par midoENSI dans le forum Struts 1
    Réponses: 2
    Dernier message: 31/05/2007, 11h17
  4. Tests Unitaires pour EJB
    Par PhunkyBob dans le forum Tests et Performance
    Réponses: 2
    Dernier message: 20/11/2006, 00h01
  5. Tests de intégration
    Par spekal dans le forum Maven
    Réponses: 3
    Dernier message: 26/07/2006, 10h55

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