EJB Naming problem (NameNotFoundException)
dabubble Dec 11, 2005 9:20 PMHi i've circled the web but I just cant get this going.
I have a MDB listening from a queue, receives the message and the call the respective process model on a Stateless Session Bean. I'm using XDoclet and can't seam to get this to work.
The MDB Bean looks like this:
ackage is.scholar.orchestrator.ejb;
import is.scholar.orchestrator.interfaces.MainOrchestratorLocal;
import is.scholar.orchestrator.interfaces.MainOrchestratorUtil;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.MessageDrivenBean;
import javax.ejb.MessageDrivenContext;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* XDoclet-based Message Driven entity bean.
*
* To generate EJB related classes using XDoclet:
*
* - Add Standard EJB module to XDoclet project properties
* - Customize XDoclet configuration
* - Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name="UIOutboxProcessorMDB"
* display-name="UIOutboxProcessorMDB"
* description="MDB that retreives transactionaly a message from its outbox queue and sends it to the corresponding method en the orchestrator"
* destination-type="javax.jms.Queue"
* acknowledge-mode="Auto-acknowledge"
* transaction-type = "Container"
* subscription-durability = "Durable"
*
* @jboss.destination-jndi-name name="queue/UIOutboxQueue"
*
* @ejb.ejb-ref ejb-name="MainOrchestrator"
* type="Session"
* view-type="local"
* ref-name="MainOrchestrator"
*
* @jboss.ejb-local-ref ref-name="MainOrchestrator"
* jndi-name="ejb/MainOrchestrator"
*/
public class UIOutboxProcessorMDB implements MessageDrivenBean, MessageListener {
private static final long serialVersionUID = 4883475689156890475L;
/** The MessageDrivenContext */
private MessageDrivenContext context;
private InitialContext initialContext;
MainOrchestratorLocal orchestrator;
public UIOutboxProcessorMDB() {
super();
}
/**
* Set the associated context. The container calls this method
* after the instance creation. <br>
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable. <br>
*
* This method is called with no transaction context.
*
* @param newContext A MessageDrivenContext interface for the instance.
*
* @throws EJBException Thrown by the method to indicate a failure caused by a system-level error.
*
*
*
*/
public void setMessageDrivenContext(MessageDrivenContext newContext) throws EJBException {
context = newContext;
}
public void ejbRemove() throws EJBException {
// TODO Auto-generated method stub
}
/**
* Method that retreives a message from the message queue specified
* Since container managed transaction in enabled if there is an exception
* between the retreiving of the message and the end of the process specified
* in the orchestrator SessionBean the transaction will be rolled back with
* no need for user specified commit() or rollback methods()
* @param msg the message from the user interface outbox
*/
public void onMessage(Message msg) {
try {
System.out.println("UIOMDB: Received Message from queue");
TextMessage tm = (TextMessage) msg;
String theMessage = tm.getText();
orchestrator = MainOrchestratorUtil.getLocalHome().create();
System.out.println("UIOMDB: Createnew StatelessSB Orchestrator");
orchestrator.processMessageFromUIOutbox(theMessage);
System.out.println("UIOMDB: Orchestrator returned from process message");
} catch (CreateException e) {
e.printStackTrace();
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
} catch (EJBException e) {
e.printStackTrace();
}
}
/**
* An ejbCreate method as required by the EJB specification.
*
* The container calls the instance?s <code>ejbCreate</code> method
* immediately after instantiation.
*
* @ejb.create-method
*/
public void ejbCreate() {
}
}
The Session Bean looks like this:
package is.scholar.orchestrator.ejb;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.jms.JMSException;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/**
* XDoclet-based session bean. The class must be declared
* public according to the EJB specification.
*
* To generate the EJB related files to this EJB:
* - Add Standard EJB module to XDoclet project properties
* - Customize XDoclet configuration for your appserver
* - Run XDoclet
*
* Below are the xdoclet-related tags needed for this EJB.
*
* @ejb.bean name="MainOrchestrator"
* jndi-name="ejb/MainOrchestrator"
* type="Stateless"
* view-type="local"
*
*/
public class MainOrchestratorBean implements SessionBean {
private static final long serialVersionUID = -5234607840877395891L;
/** The session context */
private SessionContext context;
private QueueConnectionFactory connectionFactory;
public MainOrchestratorBean() {
super();
// TODO Auto-generated constructor stub
}
/**
* Set the associated session context. The container calls this method
* after the instance creation.
*
* The enterprise bean instance should store the reference to the context
* object in an instance variable.
*
* This method is called with no transaction context.
*
* @throws EJBException Thrown if method fails due to system-level error.
*/
public void setSessionContext(SessionContext newContext) throws EJBException {
context = newContext;
}
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
/**
* An ejbCreate method as required by the EJB specification.
*
* The container calls the instance?s <code>ejbCreate</code> method whose
* signature matches the signature of the <code>create</code> method invoked
* by the client. The input parameters sent from the client are passed to
* the <code>ejbCreate</code> method. Each session bean class must have at
* least one <code>ejbCreate</code> method. The number and signatures
* of a session bean?s <code>create</code> methods are specific to each
* session bean class.
*
* @throws CreateException Thrown if method fails due to system-level error.
*
* @ejb.create-method
*
*/
public void ejbCreate() throws CreateException {
//Set up all the queues
try {
connectionFactory = (QueueConnectionFactory) new InitialContext().lookup("JQCF");
} catch (NamingException ex) {
ex.printStackTrace();
}
}
/**
*
* @ejb.interface-method view-type = "local"
*
* @throws EJBException
* Thrown if method fails due to system-level error.
* @throws NamingException
* @throws JMSException
*/
public void processMessageFromUIOutbox(String aMessage) throws EJBException, NamingException, JMSException {
System.out.println("ORCH: received call to processMessageUIO");
Queue queue = (Queue)new InitialContext().lookup("queue/ScholarXMLInboxQueue");
QueueConnection connection = connectionFactory.createQueueConnection();
QueueSession session = (QueueSession)connection.createQueueSession(true,Session.AUTO_ACKNOWLEDGE);
QueueSender sender = (QueueSender)session.createSender(queue);
TextMessage tm = session.createTextMessage();
tm.setText(aMessage);
System.out.println("ORCH: About to put the message in ScholarXMLInboxQueue");
sender.send(tm);
System.out.println("ORCH: Message sent returning...");
return;
}
}
the ejb-jar.xml looks like this:
... <!-- Session Beans --> <session > <description><![CDATA[XDoclet-based session bean.]]></description> <ejb-name>MainOrchestrator</ejb-name> <local-home>is.scholar.orchestrator.interfaces.MainOrchestratorLocalHome</local-home> <local>is.scholar.orchestrator.interfaces.MainOrchestratorLocal</local> <ejb-class>is.scholar.orchestrator.ejb.MainOrchestratorSession</ejb-class> <session-type>Stateless</session-type> <transaction-type>Container</transaction-type> </session> ..... <message-driven > <description><![CDATA[MDB that retreives transactionaly a message from its outbox queue and sends it to the corresponding method en the orchestrator]]></description> <display-name>UIOutboxProcessorMDB</display-name> <ejb-name>UIOutboxProcessorMDB</ejb-name> <ejb-class>is.scholar.orchestrator.ejb.UIOutboxProcessorMDB</ejb-class> <transaction-type>Container</transaction-type> <acknowledge-mode>Auto-acknowledge</acknowledge-mode> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> <subscription-durability>Durable</subscription-durability> </message-driven-destination> <ejb-local-ref > <ejb-ref-name>MainOrchestrator</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local-home>is.scholar.orchestrator.interfaces.MainOrchestratorLocalHome</local-home> <local>is.scholar.orchestrator.interfaces.MainOrchestratorLocal</local> <ejb-link>MainOrchestrator</ejb-link> </ejb-local-ref>
and finally the jboss.xml looks like this:
... <session> <ejb-name>MainOrchestrator</ejb-name> <local-jndi-name>MainOrchestratorLocal</local-jndi-name> <method-attributes> </method-attributes> </session> ... </message-driven> <message-driven> <ejb-name>UIOutboxProcessorMDB</ejb-name> <destination-jndi-name>queue/UIOutboxQueue</destination-jndi-name> </message-driven>
I can't seem to get this right. Any help would be very much appreciated.