Ifnu bima wrote: > Hi All, > > Gw ada masalah nih di kode. > > 1. Session Bean > @Stateless > public class XmlEntityBean implements XmlEntityLocal, XmlEntityRemote { > public void saveLocal(XmlEntity entity) { > System.out.println("local"); > } > public void saveRemote(XmlEntity entity) { > System.out.println("remote"); > } > } > > Trus gw ada servlet yang dijalankan di salan container yang sama, mau > mengakses local interface : > > public class XmlToDataServlet extends HttpServlet { > private static final long serialVersionUID = 1L; > @EJB XmlEntityLocal xmlEntityLocal; > public XmlToDataServlet() { > super(); > } > protected void doPost(HttpServletRequest request, HttpServletResponse > response) throws ServletException, IOException { > XmlEntity entity = new XmlEntity(); > entity.setType("simplexml"); > entity.setXml("xml"); > if(xmlEntityLocal!=null){ > xmlEntityLocal.saveLocal(entity); > } else { > System.out.println("tidak ada session yang bisa diinject!"); > String ejbContext = "XmlEntityBean"; > try{ > Context c = new InitialContext(); > xmlEntityLocal=(XmlEntityLocal) c.lookup(ejbContext); > if(xmlEntityLocal!=null){ > xmlEntityLocal.saveLocal(entity); > System.out.println("Initial context berhasil > lookup ke : " > + ejbContext); > return; > } > } catch(Exception ex){ > System.out.println("Initial context gagal lookup ke : " > + ejbContext); > ex.printStackTrace(); > } > ejbContext = "java:comp/env/ejb/XmlEntityBean"; > try{ > Context c = new InitialContext(); > xmlEntityLocal=(XmlEntityBean) c.lookup(ejbContext); > if(xmlEntityLocal!=null){ > xmlEntityLocal.saveLocal(entity); > } > } catch(Exception ex){ > System.out.println("Initial context gagal lookup ke : " > + ejbContext); > ex.printStackTrace(); > } > } > } > } > > Nggak berhasil nih untuk lookup Local interface, ada yang salah ga yah? > > 1. Mencoba lookup dengan @EJB (pake netbeans 6.7 dan glassfish 2.1 lancar nih) > 2. Menggunakan JNDI Lookup "XmlEntityBean" > 3. menggunaka JNDI Lookup "java:comp/env/ejb/XmlEntityBean" > > Nggak berhasil lookup Session Bean nya :(, ada saran dimana salahnya? >
Local interface tidak didaftarkan di JNDI karena itu memang tidak bisa dilookup lewat JNDI. Salahnya disitu. He he he. Local interface cuma bisa diinject lewat annotation.