[jboss-user] [JNDI and Naming] - EJB 3.0 and JNDI problems

gk-bgh do-not-reply at jboss.com
Sat Sep 5 11:42:23 EDT 2009


Hello all!

I need some help with the following:

Web Server - Jboss 5.1.0 GA
IDE - eclipse

I created a EJB project using eclipse and the following files:

ejb.server.HelloWorld.HelloWorldBeanRemote 
   
  | package ejb.server.HelloWorld;
  | import javax.ejb.Remote;
  | 
  | @Remote
  | public interface HelloWorldBeanRemote {
  | 	public void sayHelloRemoto();
  | }
  | 
  | 
  | 

ejb.server.HelloWorld.HelloWorldBeanLocal 
    
  | package ejb.server.HelloWorld;
  | import javax.ejb.Local;
  | 
  | @Local
  | public interface HelloWorldBeanLocal {
  | 	public void sayHelloLocal();
  | }
  | 
  | 


ejb.server.HelloWorld.HelloWorldBean 
   
  | package ejb.server.HelloWorld;
  | 
  | import javax.ejb.Stateless;
  | 
  | /**
  |  * Session Bean implementation class HelloWorldBean
  |  */
  | @Stateless
  | public class HelloWorldBean implements HelloWorldBeanRemote, HelloWorldBeanLocal {
  | 
  |     /**
  |      * Default constructor. 
  |      */
  |     public HelloWorldBean() {
  |         // TODO Auto-generated constructor stub
  |     }
  | 
  | 	@Override
  | 	public void sayHelloRemoto() {
  | 		// TODO Auto-generated method stub
  | 		System.out.println("Remoto");
  | 	}
  | 
  | 	@Override
  | 	public void sayHelloLocal() {
  | 		// TODO Auto-generated method stub
  | 		System.out.println("Local");
  | 	}
  | 
  | }
  | 
  | 


and the client

    
  | package ejb.client;
  | 
  | import java.util.Properties;
  | 
  | import javax.naming.InitialContext;
  | import javax.naming.NamingException;
  | import javax.rmi.PortableRemoteObject;
  | 
  | import ejb.server.HelloWorld.HelloWorldBean;
  | import ejb.server.HelloWorld.HelloWorldBeanRemote;
  | 
  | public class EJBClient {
  | 
  | 	/**
  | 	 * @param args
  | 	 */
  | 	public static void main(String[] args) {
  | 		// TODO Auto-generated method stub	
  | 		try {
  | 			Properties properties = new Properties();
  | 			properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
  | 			properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
  | 			properties.put("java.naming.provider.url","jnp://localhost:1099");
  | 			InitialContext context = new InitialContext(properties);
  | 
  | 
  | 			Object bean = context.lookup("HelloWorldBean/remote");
  | 			Object bean2 = context.lookup(HelloWorldBean.class.getSimpleName()+"/remote");
  | 			
  | 			HelloWorldBeanRemote beanH = (HelloWorldBeanRemote)PortableRemoteObject.narrow(bean, HelloWorldBeanRemote.class);
  | 			//Object bean3 = context.lookup("HelloWorldBean/local");
  | 			//bean.sayHelloRemoto();
  | 			System.out.println(bean);
  | 			System.out.println(bean2);
  | 			System.out.println(beanH);
  | 			
  | 		} catch (NamingException e) {
  | 			// TODO Auto-generated catch block
  | 			e.printStackTrace();
  | 		}
  | 	}
  | 
  | }
  | 
  | 
  | 

I execute the project from Eclipse and my ejb is deployed as I get the message:
11:27:41,999 INFO  [EJBContainer] STARTED EJB: ejb.server.HelloWorld.HelloWorldBean ejbName: HelloWorldBean
11:27:42,018 INFO  [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

	HelloWorldBean/remote - EJB3.x Default Remote Business Interface
	HelloWorldBean/remote-ejb.server.HelloWorld.HelloWorldBeanRemote - EJB3.x Remote Business Interface
	HelloWorldBean/local - EJB3.x Default Local Business Interface
	HelloWorldBean/local-ejb.server.HelloWorld.HelloWorldBeanLocal - EJB3.x Local Business Interface




When I run the client as a JAVA APPLICATION I get the output:
Proxy to jboss.j2ee:jar=EJB.jar,name=HelloWorldBean,service=EJB3 implementing [interface ejb.server.HelloWorld.HelloWorldBeanRemote]
Proxy to jboss.j2ee:jar=EJB.jar,name=HelloWorldBean,service=EJB3 implementing [interface ejb.server.HelloWorld.HelloWorldBeanRemote]
Proxy to jboss.j2ee:jar=EJB.jar,name=HelloWorldBean,service=EJB3 implementing [interface ejb.server.HelloWorld.HelloWorldBeanRemote]

What I am doing wrong that I dont get the object I want from the Container?



View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4253730#4253730

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4253730



More information about the jboss-user mailing list