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 :

Problème d'utilisation dans un projet Web


Sujet :

Java EE

  1. #1
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 36
    Points : 17
    Points
    17
    Par défaut Problème d'utilisation dans un projet Web
    Bonjour,

    J'ai un problème avec mes EJB,lorsque je les deploient sous un EJBproject sa marche nikcel alors que si je les deploient sous un projet WEB j'ail'erreur suivante:

    EJB not bound,a parement il ne trouve pas l'ejb alors que j'ai bien ajouter une interface remote et j'ai bien ajouter mon fichier jndi.properties.

    est ce qu'il y a un paramétrage spécifique à faire ? je sais pas

    si quelqu'un peut m'aider il est vraiment le bien venu

    sa m'angoisse vraiment ce truc

  2. #2
    Invité(e)
    Invité(e)
    Par défaut
    bonjour,

    si tu pouvais mettre le code
    de ton client
    de l'ejb
    de l'interface

    ça permettra d'avoir un aperçu pour t'aider

  3. #3
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    ben voila
    j'utilise struts comme client donc j'apel les ejb dans mes action et voila mon code:

    a savoire que j'ai mes ejb et mes classe action dans le meme projet web:

    voici l'interface:
    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
     
     
     
    import java.util.Collection;
     
     
    import javax.ejb.Remote;
     
     
     
     
    @Remote
    public interface BookManager_Interface {
    public void init ();
    public void loadData();
    public long saveToDB(Book2 book);
    public Book2 loadBookById(long id);
    public void deleteBookById(long id);
    public Collection getAllBooks();
    }
    mon bean:
    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
    91
    92
    93
    94
    95
    96
     
     
     
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.Random;
     
    import javax.ejb.Stateless;
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
     
     
     
    @Stateless
    public class BookManager implements BookManager_Interface {
    	private Collection books;
    	@PersistenceContext
    	EntityManager em;
    	public void deleteBookById(long id) {
    		em.remove(em.find(Book2.class, id));
    	}
     
    	public Collection getAllBooks() {
    		// TODO Auto-generated method stub
    		loadData();
    		return books;
    	}
     
    	public void init() {
    		// TODO Auto-generated method stub
    		// TODO Auto-generated method stub
    		Random random = new Random();
    		em.persist(new Book2(random.nextLong(), "David Roos", "Struts book", true));
    	    em.persist(new Book2(random.nextLong(), "Micheal Jackson", "Java book", true));
    	    em.persist(new Book2(random.nextLong(), "Bruce Lee", "Java2 book", false));
    	    em.persist(new Book2(random.nextLong(), "Tom Jones" ,"EJB book", true));
    	    em.persist(new Book2(random.nextLong(), "Mc Donald", "Jboss for beginners", false));
            em.persist(new Book2(random.nextLong(), "Lars Mars", "Using Myeclipse for cooking", true));
            em.persist(new Book2(random.nextLong(), "Mary Jane", "EJB or spending your weekends", true));
     
    	}
     
    	public Book2 loadBookById(long id) {
    		// TODO Auto-generated method stub
     
    		return (Book2)em.find(Book2.class, id);
    	}
     
    	public void loadData() {
    		// TODO Auto-generated method stub
            books = (Collection)em.createQuery("from Book2");
            if (books == null)
                init();
    	}
     
     
     
     
    	public long saveToDB(Book2 book) {
    		 loadData();
     
    	        // laliluna 04.10.2004 loop over collection and trying to find the book
    	        boolean bookExist = false;
    	        ArrayList booksNew = (ArrayList) books;
    	        int index = 0;
    	        for (Iterator iter = books.iterator(); iter.hasNext();) {
    	            Book2 element = (Book2) iter.next();
    	            // laliluna 04.10.2004 if book is found do an update
    	            if (element.getId() == book.getId()) {
    	            	booksNew.set(index, book);
    	                bookExist = true;
    	                break;
    	            }
    	            index++;
    	        }
     
    	        books = booksNew;
     
    	        // laliluna 04.10.2004 if book is not found, create a new book
    	        if (bookExist == false) {
    	            Random random = new Random();
    	            book.setId(random.nextLong());
    em.persist(book);	       
    }
     
    	        // laliluna 04.10.2004 save to DB ;-)
     
    	        return book.getId();
    	}
     
     
     
     
     
    }

    et voila l'action qui apelle l'ejb:

    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
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    //Created by MyEclipse Struts
    // XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_3.8.0/xslt/JavaClass.xsl
     
     
    package test;
     
     
     
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
     
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.actions.DispatchAction;
     
     
     
    /** 
     * MyEclipse Struts
     * Creation date: 11-04-2004
     * 
     * XDoclet definition:
     * @struts:action path="/bookEdit" name="bookEditForm" parameter="do" scope="request" validate="true"
     * @struts:action-forward name="/jsp/bookEdit.jsp" path="/jsp/bookEdit.jsp"
     */
    public class BookEditAction extends DispatchAction {
     
    	/** 
             * Method editBook
             * @param mapping
             * @param form
             * @param request
             * @param response
             * @return ActionForward
             */
    	public ActionForward editBook(
    		ActionMapping mapping,
    		ActionForm form,
    		HttpServletRequest request,
    		HttpServletResponse response) {
    		BookEditForm bookEditForm = (BookEditForm) form;
     
    		/* lalinuna.de 04.11.2004
    		 * get id of the book from request
    		 */
    		long id = Long.parseLong(request.getParameter("id"));
     
    		/* lalinuna.de 04.11.2004
    		 * init SimulateDB class and get book id
    		 */
     
    		try {
    			 Context context = new InitialContext();
    			BookManager_Interface BM=(BookManager_Interface)context.lookup("BookManager/remote") ;
    		bookEditForm.setBook(BM.loadBookById(id));
    		} catch (NamingException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
     
     
    		return mapping.findForward("showEdit");
     
    	}
     
    	/** 
             * Method deleteBook
             * @param mapping
             * @param form
             * @param request
             * @param response
             * @return ActionForward
             */
    	public ActionForward deleteBook(
    		ActionMapping mapping,
    		ActionForm form,
    		HttpServletRequest request,
    		HttpServletResponse response) {
    		BookEditForm bookEditForm = (BookEditForm) form;
     
    		/* lalinuna.de 04.11.2004
    		 * get id of the book from request
    		 */
    		long id = Long.parseLong(request.getParameter("id"));
     
    		/* lalinuna.de 04.11.2004
    		 * init SimulateDB class and delete book by id
    		 */
     
    			try {
    				 Context context = new InitialContext();
    				BookManager_Interface BM=(BookManager_Interface)context.lookup("BookManager/remote") ;
    			BM.deleteBookById(id);
    			} catch (NamingException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
     
     
    		return mapping.findForward("showList");
     
    	}
     
    	/** 
             * Method addBook
             * @param mapping
             * @param form
             * @param request
             * @param response
             * @return ActionForward
             */
    	public ActionForward addBook(
    		ActionMapping mapping,
    		ActionForm form,
    		HttpServletRequest request,
    		HttpServletResponse response) {
    		BookEditForm bookEditForm = (BookEditForm) form;
     
    		return mapping.findForward("showAdd");
     
    	}
     
    	/** 
             * Method saveBook
             * @param mapping
             * @param form
             * @param request
             * @param response
             * @return ActionForward
             */
    	public ActionForward saveBook(
    		ActionMapping mapping,
    		ActionForm form,
    		HttpServletRequest request,
    		HttpServletResponse response) {
    		BookEditForm bookEditForm = (BookEditForm) form;
     
    		/* lalinuna.de 04.11.2004
    		 * init SimulateDB class and get data by id
    		 */
     
    			try {
    				 Context	context = new InitialContext();
    				BookManager_Interface BM=(BookManager_Interface)context.lookup("BookManager/remote") ;
    			BM.saveToDB(bookEditForm.getBook());
    			} catch (NamingException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
     
     
     
    		return mapping.findForward("showList");
     
    	}
     
    }

    et j' ai bien sur ajouté mon jndi.properties

    et j'utilise jboss 4.2

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2006
    Messages
    156
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 156
    Points : 191
    Points
    191
    Par défaut
    Tu utilises quoi comme serveur?
    Peux tu vérifier en utilisant sa console si l'EJB est bien déployé ?

  5. #5
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    j'utilise jboss-4.0.5.GA


    j'ai regarder dans la console mais l'ejb n'apparait pas.

    alors que si j'ecri les meme ejb sous un ejb project sa marche nickel

    vraiment je comprend pas

  6. #6
    Invité(e)
    Invité(e)
    Par défaut
    hum bizarre

    moi j'aurai plutôt fait comme ça:

    pour le stateless

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    @Stateless(mappedName="BookManager")
    @Remote(BookManager_Interface.class)
     
    public class BookManager implements BookManager_Interface {
     
    ...
    }
    pour l'interface, tu n'as pas besoin du @remote pour l'interface

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    public interface BookManager_Interface {
    ensuite le jndi.properties doit se trouver dans le src (moi j'utilise jboss et je procède ainsi sans soucis)

    quelle est l'erreur affichée dans la console ?
    généralement quand tu as EJB not bound c'est:
    soit ton ejb n'est pas déployé pour une erreur x (compilation ect..)
    ou un mauvais nom donné dans ton lookup

    peux tu donner la trace de ton log au moment ou tu démarre ton serveur ?
    et celle au moment ou l'erreur not bound est générée ?


    EDIT:

    tu exportes ton projet dans un JAR ? ou un WAR ? ou autre ?

  7. #7
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    voila l'erreur que sa me génére:
    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
    17:23:59,464 ERROR [STDERR] javax.naming.NameNotFoundException: BookManager not bound
    17:23:59,464 ERROR [STDERR] 	at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
    17:23:59,464 ERROR [STDERR] 	at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
    17:23:59,464 ERROR [STDERR] 	at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
    17:23:59,464 ERROR [STDERR] 	at org.jnp.server.NamingServer.lookup(NamingServer.java:267)
    17:23:59,464 ERROR [STDERR] 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
    17:23:59,464 ERROR [STDERR] 	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
    17:23:59,474 ERROR [STDERR] 	at javax.naming.InitialContext.lookup(InitialContext.java:351)
    17:23:59,474 ERROR [STDERR] 	at test.BookListAction.execute(BookListAction.java:59)
    17:23:59,474 ERROR [STDERR] 	at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
    17:23:59,474 ERROR [STDERR] 	at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
    17:23:59,474 ERROR [STDERR] 	at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    17:23:59,474 ERROR [STDERR] 	at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
    17:23:59,474 ERROR [STDERR] 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
    17:23:59,474 ERROR [STDERR] 	at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
    17:23:59,474 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    17:23:59,474 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    17:23:59,474 ERROR [STDERR] 	at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    17:23:59,474 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    17:23:59,484 ERROR [STDERR] 	at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
    17:23:59,484 ERROR [STDERR] 	at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    17:23:59,484 ERROR [STDERR] 	at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    17:23:59,484 ERROR [STDERR] 	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    17:23:59,484 ERROR [STDERR] 	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
    17:23:59,484 ERROR [STDERR] 	at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
    17:23:59,484 ERROR [STDERR] 	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    17:23:59,484 ERROR [STDERR] 	at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
    17:23:59,484 ERROR [STDERR] 	at java.lang.Thread.run(Thread.java:595)

  8. #8
    Invité(e)
    Invité(e)
    Par défaut
    pour reprendre phantomass as tu bien remarqué si ton ejb se déployais au démarrage de ton serveur ?

    normalement dans la console tu devrais voir un truc du genre:

    Mon JAr se nomme EJB3.jar
    et mon EJB se nomme BeanProxy

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    17:22:24,295 INFO  [JmxKernelAbstraction] installing MBean: jboss.j2ee:ear=EJB3.ear,jar=EJB3.jar,name=BeanProxy,service=EJB3 with dependencies:
    17:22:24,312 INFO  [EJBContainer] STARTED EJB: bean.BeanProxy ejbName: BeanProxy
    17:22:24,344 INFO  [EJB3Deployer] Deployed: file:/C:/EJB3.jar
    bon moi c'est sous Jboss, mais ça reste le même principe je suppose, normalement tu devrais avoir une trace t'indiquant si ton ejb a bien été ou non déployé

  9. #9
    Membre à l'essai
    Inscrit en
    Avril 2008
    Messages
    36
    Détails du profil
    Informations forums :
    Inscription : Avril 2008
    Messages : 36
    Points : 17
    Points
    17
    Par défaut
    en plus voici ce quin s'affiche dans la console jboss dans le jndiview plus precisement:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    java:comp namespace of the Tuto_Struts_Jboss.war application:
     
      +- UserTransaction[link -> UserTransaction] (class: javax.naming.LinkRef)
      +- ORB (class: org.jacorb.orb.ORB)
      +- env (class: org.jnp.interfaces.NamingContext)
      |   +- security (class: org.jnp.interfaces.NamingContext)
      |   |   +- realmMapping[link -> java:/jaas/other] (class: javax.naming.LinkRef)
      |   |   +- subject[link -> java:/jaas/other/subject] (class: javax.naming.LinkRef)
      |   |   +- securityMgr[link -> java:/jaas/other] (class: javax.naming.LinkRef)
      |   |   +- security-domain[link -> java:/jaas/other] (class: javax.naming.LinkRef)

  10. #10
    Invité(e)
    Invité(e)
    Par défaut
    qu'entends tu par webproject ?

    tu veux dire que tu mes ton jar dans un war ?

Discussions similaires

  1. Quelle méthode utilise dans mon projet Web
    Par sepltura dans le forum Méthodes Agiles
    Réponses: 2
    Dernier message: 08/04/2012, 12h25
  2. Problème de quote dans un projet web suite aux migrations de poste
    Par tamildark dans le forum Développement Web en Java
    Réponses: 2
    Dernier message: 03/01/2011, 15h16
  3. Utilisation de conversion PDF dans un projet web
    Par amnass dans le forum Documents
    Réponses: 3
    Dernier message: 26/05/2009, 15h08
  4. Réponses: 1
    Dernier message: 20/01/2009, 14h31
  5. Utiliser plusieurs fichiers .config dans un projet web
    Par Zakapatul dans le forum ASP.NET
    Réponses: 8
    Dernier message: 06/10/2008, 12h34

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