<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: lookup a session bean inside a servlet
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/bertoz84">stefano bertozzi</a> in <i>JNDI and Naming</i> - <a href="http://community.jboss.org/message/603644#603644">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>one step ahead!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>I created the .ear ( EARShop ) that "uses" both the .jar ( BookShop ) and the .war ( WebShop ).</p><p>I removed the .jar from the WEB-INF/lib inside the .war ( because during .ear deploy there was a duplicate name error ); to include my beans in my web project i simply added under its properties, to the JavaBuildPath/Projects, my BookShop project.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>now while deploying the .ear i can read this:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:25,110 INFO&#160; [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> <em> </em>&#160;</p><p><em>&#160; EARShop/AccessoUtente/local - EJB3.x Default Local Business Interface</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/AccessoUtente/local-bookshop.library.sessionbean.AccessoUtenteLocal - EJB3.x Local Business Interface</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:25,113 INFO&#160; [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=EARShop.ear,jar=BookShop.jar,name=Carrello,service=EJB3</em></p><p><em>12:37:25,114 INFO&#160; [org.jboss.ejb3.EJBContainer] STARTED EJB: bookshop.library.sessionbean.Carrello ejbName: Carrello</em></p><p><em>12:37:25,118 INFO&#160; [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:</em></p><p><em>&#160; </em></p><p><em>&#160; EARShop/Carrello/local - EJB3.x Default Local Business Interface</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/Carrello/local-bookshop.library.sessionbean.CarrelloLocal - EJB3.x Local Business Interface</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:25,120 INFO&#160; [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=EARShop.ear,jar=BookShop.jar,name=OperazioniLibri,service=EJB3</em></p><p><em>12:37:25,121 INFO&#160; [org.jboss.ejb3.EJBContainer] STARTED EJB: bookshop.library.sessionbean.OperazioniLibri ejbName: OperazioniLibri</em></p><p><em>12:37:25,125 INFO&#160; [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/OperazioniLibri/local - EJB3.x Default Local Business Interface</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/OperazioniLibri/local-bookshop.library.sessionbean.OperazioniLibriLocal - EJB3.x Local Business Interface</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:25,125 WARN&#160; [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers</em></p><p><em>12:37:25,127 INFO&#160; [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=EARShop.ear,jar=BookShop.jar,name=BookTestBean,service=EJB3</em></p><p><em>12:37:25,128 INFO&#160; [org.jboss.ejb3.EJBContainer] STARTED EJB: bookshop.test.BookTestBean ejbName: BookTestBean</em></p><p><em>12:37:25,133 INFO&#160; [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/BookTestBean/remote - EJB3.x Default Remote Business Interface</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/BookTestBean/remote-bookshop.test.BookTestBeanRemote - EJB3.x Remote Business Interface</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/BookTestBean/local - EJB3.x Default Local Business Interface</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/BookTestBean/local-bookshop.test.BookTestBeanLocal - EJB3.x Local Business Interface</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:25,134 WARN&#160; [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers</em></p><p><em>12:37:25,135 INFO&#160; [org.jboss.ejb3.session.SessionSpecContainer] Starting jboss.j2ee:ear=EARShop.ear,jar=BookShop.jar,name=OperazioniUtenti,service=EJB3</em></p><p><em>12:37:25,136 INFO&#160; [org.jboss.ejb3.EJBContainer] STARTED EJB: bookshop.library.sessionbean.OperazioniUtenti ejbName: OperazioniUtenti</em></p><p><em>12:37:25,138 INFO&#160; [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><strong><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/OperazioniUtenti/local - EJB3.x Default Local Business Interface</em></strong></p><p><strong><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;EARShop/OperazioniUtenti/local-bookshop.library.sessionbean.OperazioniUtentiLocal - EJB3.x Local Business Interface</em></strong></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:25,139 WARN&#160; [org.jboss.ejb3.TimerServiceContainer] EJBTHREE-2193: using deprecated TimerServiceFactory for restoring timers</em></p><p><em>12:37:25,147 INFO&#160; [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/WebShop</em></p><p><em>12:37:47,745 INFO&#160; [STDOUT] interface bookshop.library.sessionbean.OperazioniUtentiLocal</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>that means i should lookup my ejbs with this name:</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <em>EARShop/OperazioniUtenti/local</em></p><p>( EAR_NAME/bean/local, not JAR_NAME/bean/local );</p><p>i tried it and i found out that it doesn't work; instead it works if i use: </p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EARShop/OperazioniUtenti/local-bookshop.library.sessionbean.OperazioniUtentiLocal</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Why are there 2 jndi binding, non-default and default, and here i need to use the default while testing my .jar i use the non-default?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>A problem however still persist in the lookup procedure:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>opUser = (OperazioniUtenti) context.lookup("EARShop/OperazioniUtenti/local-bookshop.library.sessionbean.OperazioniUtentiLocal");</em></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><em>12:37:47,753 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/WebShop].[somethingServlet]] Servlet.service() for servlet somethingServlet threw exception: java.lang.ClassCastException: $Proxy330 cannot be cast to bookshop.library.sessionbean.OperazioniUtenti</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at webinterface.servlet.somethingServlet.doPost(somethingServlet.java:50) [:]</em></p><p><em>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [:1.0.0.Final]</em></p><p>bla bla bla</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Do you know how to solve it?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Thank you a lot and sorry for bothering you so much!!!</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/603644#603644">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JNDI and Naming at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>