aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes MDB Beans using JBOSS and Eclipse IDE... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "MDB Beans using JBOSS and Eclipse IDE..." Watch "MDB Beans using JBOSS and Eclipse IDE..." New topic
Author

MDB Beans using JBOSS and Eclipse IDE...

Abhishek Asthana
Ranch Hand

Joined: Sep 08, 2004
Posts: 146
we are implemeting an MDB EJB Bean( testEJBBean.java).But we are not able to generate any EJB files.We also made an test client for it(testMDBClient.java) and another Stateless bean (SupplierEJBBean).

Wat we are actually trying to do is that ..our test client (testMDBClient.java) will send data and MDB EJB Bean(testEJBBean.java) will recieve it and pass it to Stateless bean(SupplierEJBBean).

We already made statefull and stateless bean and they were successfuly generating EJB files and also deployed it but MDB we were unable to do it.
We have tried very hard to find it but we were unable to find it..plz help us as we are at the end of completing our project

here are our files... very simple test program.
MDB EJB Bean( testEJBBean.java)
/*
* Created on Mar 30, 2005
*/
package temp.mdb.bean;

import javax.ejb.MessageDrivenBean;
import javax.jms.MessageListener;

import temp.supplier.bean.*;
import javax.jms.*;
import javax.jms.JMSException;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import javax.naming.InitialContext;
import java.util.Hashtable;
/**
* @ejb.bean name="testingEJB"
* acknowledge-mode="Auto-acknowledge"
* destination-type="javax.jms.Queue"
* subscription-durability="NonDurable"
* transaction-type="Bean"
*
* @ejb.ejb-ref
* ejb-name="SupplierEJB"
* view-type="remote"
* ref-name="SupplierEJB"
*
* @jboss.ejb-ref-jndi ref-name="SupplierEJB"
* jndi-name="SupplierEJBBean"
*
* @jboss.destination-jndi-name
* name="queue/MdbQueue"
*
**/


public class testingEJBBean implements MessageDrivenBean, MessageListener {

//private SupplierEJBHome suppHome = null;

//supp

private SupplierEJBHome getHome() throws NamingException {
Object result = getContext().lookup(SupplierEJBHome.JNDI_NAME);
return (
(SupplierEJBHome) PortableRemoteObject.narrow(
result,
SupplierEJBHome.class));
}

private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(
InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
/** Required method for container to set context. */
public void setMessageDrivenContext(
javax.ejb.MessageDrivenContext messageContext)
throws javax.ejb.EJBException {
this.messageContext = messageContext;
}
/**
* Required creation method for message-driven beans.
*
* @ejb.create-method
*/
public void ejbCreate() {
// no specific action required for message-driven beans
}

/** Required removal method for message-driven beans. */
public void ejbRemove() {
messageContext = null;
}

/**
* This method implements the business logic for the EJB.
*
*

Make sure that the business logic accounts for asynchronous message processing.
* For example, it cannot be assumed that the EJB receives messages in the order they were
* sent by the client. Instance pooling within the container means that messages are not
* received or processed in a sequential order, although individual onMessage() calls to
* a given message-driven bean instance are serialized.
*
*

The onMessage() method is required, and must take a single parameter
* of type javax.jms.Message. The throws clause (if used) must not include an application
* exception. Must not be declared as final or static.
*/
public void onMessage(javax.jms.Message message) {
System.out.println("Message Driven Bean got message " + message);


try {
RequestItem ri = (RequestItem) ((ObjectMessage) message).getObject();
if (message instanceof ObjectMessage) {

System.out.println("Showing Replenished item and qauntity");
System.out.println("Item ID :" + ri.getItemID());
System.out.println("Quantity :" + ri.getQuantity());

/// sending this info to another bean/////

SupplierEJB mybean = SupplierEJBUtil.getHome().create();
mybean.test(ri.getItemID(), ri.getQuantity());
//supplier.requestitem(ri.getItemID(),ri.getQuantity());
}

} catch (JMSException e) {
System.out.println("Inside JMS Exception");
} catch (Exception e) {
System.out.println("in onMessage()" + e.getMessage());
}

System.out.println("Leaving onMessage()");

}

/** The context for the message-driven bean, set by the EJB container. */
private javax.ejb.MessageDrivenContext messageContext = null;

}

Stateless bean(SupplierEJBBean)
/*
* Created on Mar 30, 2005
*/
package temp.supplier.bean;

import javax.ejb.SessionBean;


/**
* @ejb.bean name="SupplierEJB"
* jndi-name="SupplierEJBBean"
* type="Stateless"
*@ejb.dao class="temp.supplier.bean.SupplierEJBDAO"
* impl-class="temp.supplier.bean.dao.SupplierEJBDAOImpl"
* @ejb.resource-ref res-ref-name="jdbc/OracleDS"
* res-type="javax.sql.Datasource"
* res-auth="Container"
* @jboss.resource-ref res-ref-name="jdbc/OracleDS" jndi-name="java:/OracleDS"

**/


public abstract class SupplierEJBBean implements SessionBean {


/**
* @ejb.interface-method
* view-type="remote"
* @dao.call name="test"
**/
public void test(String itemID,int Qty)
{
System.out.println("Entering SupplierEJBBean.test()");
System.out.println("Leaving SupplierEJBBean.test()");


}
}


client (testMDBClient.java)

/*
* Created on Mar 30, 2005
*/

import javax.naming.InitialContext;
import java.util.Hashtable;
import javax.naming.NamingException;

import temp.mdb.bean.*;
import javax.jms.*;
/**
* @author ram
**/
public class testMDBClient {
public static void main(String args[])
{
testMDBBEAN();
}
private static InitialContext getContext() throws NamingException
{

Hashtable props = new Hashtable();

props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL,
"jnp://127.0.0.1:1099");

InitialContext initialContext = new InitialContext(props);
return initialContext;
}

public static void testMDBBEAN()
{
RequestItem ri = new RequestItem("abc",12);
try
{
System.out.println("Looking up the factory");
InitialContext ctx = getContext();
QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup

("ConnectionFactory");

System.out.println("Looking up the Queue");
Queue queue = (Queue) ctx.lookup("queue/MdbQueue");

System.out.println("Creating the Connection now");
QueueConnection connection = factory.createQueueConnection

();

System.out.println("Creating the Session now");
QueueSession session = connection.createQueueSession(true,1);

System.out.println("Creating the sender now");

QueueSender sender = session.createSender(queue);

ObjectMessage message = session.createObjectMessage();
System.out.println("setting the object in message now ..");
message.setObject(ri);

System.out.println("sending the message now");

sender.send(message);
System.out.println("shutting down");
session.commit();
session.close();
connection.close();
System.out.println("finished");

}catch(Exception e)
{
e.printStackTrace();
}
}
}
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Abhishek,

Not sure if I understand you right, but from what I�ve been reading looks like your problem is that you cannot generate the deployment descriptors for your MDB. We�re using WebLogic and we specify the bean-type as well within the ejb.bean tag (although this is not documented):

See if this helps.
By the way, you might like considering CMT with your MDB. One disadvantage of using BMT is that if your transaction rolls back, you application cannot cause the message to remain to the original destination.
Regards.


I think, therefore I exist -- Rene Descartes
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MDB Beans using JBOSS and Eclipse IDE...
 
Similar Threads
Need Help With JBoss/JMS/JNDI/MQSeries
WL guru's - message bean not receiving messages from JMS
Message apparantly not getting to Queue or MDB from Java Client
java.rmi.RemoteExcepion. Working with StatefulSessionBean
Jboss Remote Connection JMS