[jboss-user] [EJB 3.0] - Call Back Listeners not working - Please help
gurubbc
do-not-reply at jboss.com
Mon Jul 23 00:27:58 EDT 2007
EJB 3.0 Call Back methods are working, but the listeners are not working.
ListenerHelloCallBack.java (Interface)
/**
* This is the ListenerHelloCallBack business interface.
*/
public interface ListenerHelloCallBack {
/**
* @return a greeting to the client.
*/
public String listenerHelloCallBack();
}
Bean class:
import javax.ejb.*;
import javax.ejb.*;
/**
* Demonstration stateless session bean.
*/
@Stateful
@Remote(ListenerHelloCallBack.class)
@CallbackListener(CallBackListener.class)
public class ListenerHelloCallBackBean implements ListenerHelloCallBack {
public String listenerHelloCallBack() {
System.out.println("listenerHelloCallBack()");
return "Hello, Call Back Listener World!";
}
}
Call Back Listener class:
import javax.ejb.*;
import javax.ejb.*;
public class CallBackListener {
@Init
public void sayInit(Object obj)
{
System.out.println("This would be called upon Init from listener class");
}
@PostConstruct
public void sayPostConstruct(Object obj)
{
System.out.println("This would be called upon post construct from listener class");
}
@PreDestroy
public void sayPreDestroy(Object obj)
{
System.out.println("This would be called upon pre destroy from listener class");
}
@PrePassivate
public void sayPrePassivate(Object obj)
{
System.out.println("This would be called upon pre passivate from listener class");
}
@PostActivate
public void sayPostActivate(Object obj)
{
System.out.println("This would be called upon post activate from listener class");
}
public void finalize()
{
System.out.println("Finalize method is getting called...");
}
}
Client:
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;
import javax.naming.*;
/**
* This class is an example of client code which invokes
* methods on a simple, remote stateless session bean.
*/
public class ListenerHelloCallBackClient {
public static void main(String[] args) throws Exception {
/*
* Obtain the JNDI initial context.
*
* The initial context is a starting point for
* connecting to a JNDI tree. We choose our JNDI
* driver, the network location of the server, etc
* by passing in the environment properties.
*/
Properties p = new Properties();
//The JNDI properties you set depend
//on which server you are using.
//These properties are for the Remote Server.
p.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
p.put("java.naming.provider.url", "jnp://localhost:1099");
p.put("java.naming.factory.url.pkgs", "org.jboss.naming rg.jnp.interfaces");
Context ctx = new InitialContext(p);
/*
* Get a reference to a bean instance, looked up by class name
*/
ListenerHelloCallBack listenerHelloCallBack = (ListenerHelloCallBack) ctx.lookup("ListenerHelloCallBack");
/*
* Call the helloCallBack() method on the bean.
* We then print the result to the screen.
*/
System.out.println(listenerHelloCallBack.listenerHelloCallBack());
listenerHelloCallBack=null;
}
}
But, none of the call back methods like @init, @postconstruct are working.
Please help.
Thanks,
Guru
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4066531#4066531
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4066531
More information about the jboss-user
mailing list