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

Java EE Discussion :

Connexions client Java et EJB


Sujet :

Java EE

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Avril 2012
    Messages : 10
    Par défaut Connexions client Java et EJB
    je suis entrain de faire un projet jEE,donc j'ai commencé par créer la partie persistance ensuite je suis passé a la partie Dao
    j'ai crée une classe siteDao et une interface Remote
    ensuite j'ai créer un projet client java,j'ai configure le fichier JNDi.propreties avec les paramétrés de connexion avec mon serveur
    ensuite j’exécute le main mais je reçois un message d'erreur
    voici le contenu des fichiers siteDaoremote:
    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
    package cartographie_reseaux.dao;
     
    import javax.ejb.Remote;
    import cartographie_reseaux.persistence.Site;
    import java.util.List;
    import cartographie_reseaux.persistence.maps;
    le main client java:
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
     
    import cartographie_reseaux.dao.siteDaoremote;
    import cartographie_reseaux.persistence.Site;
    public class Main {
    	public static void main(String[] args) {
    		Site s1=new Site();
    	     s1.setNomsiteg2r("cobra");
    	     s1.setLatitude("12025");
    	     s1.setLongitude("15023");
    	     s1.setNositeg2r(15028);
    	     s1.setRegion("lyon");
    	     s1.setType("XATM");
     
     
    	     siteDaoremote siteDao=null;
    	     try {
     
    	    	 Context ctx=new InitialContext();
    				siteDao=(siteDaoremote) ctx.lookup("siteDao/remote");
    				siteDao.ajouter(s1);
     
     
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
    		// TODO Auto-generated method stub
    	}
     
    	/* (non-Java-doc)
    	 * @see java.lang.Object#Object()
    	 */
    	public Main() {
    		super();
    	}
     
    }
    et le fichier jndi.propreties:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
    java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
    java.naming.provider.url=localhost:1099
    et le message d'erreur qui s'affiche:

    javax.naming.NameNotFoundException: siteDao not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
    at sun.rmi.transport.Transport$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
    at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)
    at javax.naming.InitialContext.lookup(Unknown Source)
    at Main.main(Main.java:22)
    Merci d'avance

  2. #2
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2004
    Messages
    1 184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 184
    Par défaut
    Bonjour,

    As-tu essayé de préfixer ton nom JNDI avec le nom de l'EAR (Sans le .ear) ?

    http://docs.jboss.org/ejb3/app-serve...ding/jndi.html


    When the EJBs are deployed in an .ear file, the default jndi binding will be prepended by the name of the .ear file. So if the ear file name is foo.ear the default jndi names would be foo/EJB-NAME/remote and foo/EJB-NAME/local. You can override this behavior by defining your own @org.jboss.ejb3.LocalBinding or @org.jboss.ejb3.remoting.RemoteBinding.

  3. #3
    Membre Expert
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Par défaut
    salut Nader.

    Tu déploies sur quel serveur d'app ?

    de mémoire sous glassfish, le lookup est de ce genre :

    "java:global/MonEAR/ModuleEJB/MonInterfaceRemote"

    je ne sais pas si pour les autres serveurs la racine "java:global" est la même.

    edit : tiens, un petit lien :
    http://stackoverflow.com/questions/4...94057#10194057

  4. #4
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2004
    Messages
    1 184
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Avril 2004
    Messages : 1 184
    Par défaut
    D'après le fichier jndi.properties il s'agit de plutôt de JBoss.

  5. #5
    Membre Expert
    Avatar de fxrobin
    Homme Profil pro
    Architecte SI, Java Fan, API Manager
    Inscrit en
    Novembre 2007
    Messages
    875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Architecte SI, Java Fan, API Manager
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Novembre 2007
    Messages : 875
    Par défaut
    Citation Envoyé par Mathieu.J Voir le message
    D'après le fichier jndi.properties il s'agit de plutôt de JBoss.
    bien vu j'vais pas regardé avec attention.

    Dans la doc de JBOSS, ils construisent la chaine JNDI de cette façon :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    return (RemoteCalculator) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
    le lien :
    https://docs.jboss.org/author/displa...ent+using+JNDI

  6. #6
    Membre actif
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2012
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Avril 2012
    Messages : 10
    Par défaut
    Merci pour vos réponses j'ai essayé de préfixer mon EAr avec le nom JNDI mais ca marche pas,il y a le meme type d'erreur
    Voici les fichiers utulisé
    client java :
    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
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
     
    import cartographiemaps.Dao.siteDaoremote;
    import cartographiemaps.persistence.Site;
     
     
    public class Main {
    	public static void main(String[] args) {
     
    		Site s1=new Site();
    		s1.setLatitude("102020");
    		s1.setLongitude("20587");
    		s1.setNomsiteg2r("10000");
    		s1.setNomsiteg2r("corba");
    		s1.setRegion("lyon");
    		s1.setType("XATM");
    		siteDaoremote siteDao=null;
    		try {
    			Context ctx=new InitialContext();
    			siteDao=(siteDaoremote) ctx.lookup("siteDao/remote");
    			siteDao.ajouter(s1);
     
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
     
     
     
    		// TODO Auto-generated method stub
    	}
     
    	/* (non-Java-doc)
    	 * @see java.lang.Object#Object()
    	 */
    	public Main() {
    		super();
    	}
     
    }
    fichier siteDao
    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
    package cartographiemaps.Dao;
     
    import java.util.List;
     
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
     
    import org.jboss.annotation.ejb.RemoteBinding;
     
     
    import cartographiemaps.persistence.Site;
    import cartographiemaps.persistence.maps;
     
     
    @Stateless
    @RemoteBinding(jndiBinding="siteDao/remote")
     
    public class siteDao implements siteDaoremote {
     
     
    	@PersistenceContext
    	EntityManager entityManager;
     
     
    	public void ajouter(Site site) {
    		entityManager.persist(site);
     
    	}
     
     
    	public void modifier(Site site) {
     
    		entityManager.merge(site);
    	}
     
     
    	public void supprimer(Site site) {
     
    		entityManager.remove(site);
    	}
     
    	public java.util.List<maps> getmap() {
     
    		return entityManager.createQuery("SELECT Site.latitude,Site.longitude FROM Site site").getResultList();
    	}
     
     
    	public List<Site> getsit() {
    		return entityManager.createQuery("FROM Site").getResultList();
    	}
     
    }
    et mon interface remote
    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
    package cartographiemaps.Dao;
     
    import javax.ejb.Remote;
     
    import org.jboss.annotation.ejb.RemoteBinding;
     
    import cartographiemaps.persistence.Site;
    import java.util.List;
    import cartographiemaps.persistence.maps;
     
    @Remote
     
     
    public interface siteDaoremote {
    		public void ajouter(Site site);
    		public void modifier(Site site);
    		public void supprimer(Site site);
    		public List<maps> getmap();
    		public List<Site> getsit();
     
    }

Discussions similaires

  1. Client Java et connexion SSL
    Par Nico02 dans le forum Développement Web en Java
    Réponses: 1
    Dernier message: 14/06/2014, 19h33
  2. Connexion à IOM server depuis client java en sso
    Par cscerim3 dans le forum Administration et Installation
    Réponses: 0
    Dernier message: 10/07/2013, 10h01
  3. Réponses: 0
    Dernier message: 19/10/2012, 01h18
  4. comment gerer plusieurs connexions client/serveur
    Par naili dans le forum C++Builder
    Réponses: 3
    Dernier message: 14/08/2002, 16h58
  5. Je ne peux établir une connexion cliente sous Linux.
    Par Anonymous dans le forum CORBA
    Réponses: 5
    Dernier message: 16/04/2002, 15h57

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