users@glassfish.java.net

Call remote EJB3 module from web application.

From: <glassfish_at_javadesktop.org>
Date: Sun, 09 Dec 2007 12:44:18 PST

Hello all,
I have following problem, I have remote ejb3 module deployed on glassfish 58g and web application with servlet deployed on the same server. I want to call remote ejb from web application but I get NameNotFoundException. This is my code:

[b]EJB3 module[/b]
package org.petka.remote.ejb;
import javax.ejb.Remote;

@Remote
public interface HelloRemote {

        public void sayHello();
}


package org.petka.remote.ejb;

import javax.ejb.Remote;
import javax.ejb.Stateless;

import org.petka.remote.ejb.HelloRemote;

@Stateless(mappedName="hello")
@Remote({HelloRemote.class})

public class Hello implements HelloRemote{

        public void sayHello() {
                System.out.println("Petka say hello EJB3 remote interface.");
        }

}

[b]web application[/b]
package org.petka.web;

import java.io.IOException;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.petka.remote.ejb.HelloRemote;


 public class Hello extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   


        public Hello() {
                super();
        }
         

        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                System.out.println("doGet()");

                try {
                        InitialContext ctx = new InitialContext();
                        HelloRemote hello = (HelloRemote) ctx.lookup("java:comp/env/hello");
                        hello.sayHello();
                } catch (NamingException e) {
                        e.printStackTrace();
                }
        }
        

        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        }
}

[b]web.xml[/b]
  <ejb-ref>
          <ejb-ref-name>hello</ejb-ref-name>
          <ejb-ref-type>Session</ejb-ref-type>
          <remote>org.petka.remote.ejb.HelloRemote</remote>
  </ejb-ref>

[b]sun-web.xml[/b]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.
//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN"
"http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_3-1.dtd">
<sun-web-app>
        <ejb-ref>
                <ejb-ref-name>hello</ejb-ref-name>
                <jndi-name>java:comp/env/hello</jndi-name>
        </ejb-ref>
</sun-web-app>



Where I wrong ???? Please any advice.
If someone post some example will be great.
Thanks in advance.
[Message sent by forum member 'petka' (petka)]

http://forums.java.net/jive/thread.jspa?messageID=249237