Connecting to JBoss ESB from Tomcat

User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive

Important note: JBoss ESB is an archived project and its latest release dates back to Mar 2013. The replacement technology for it is JBoss Fuse which is an open source enterprise integration platform and service bus. You can find here a quickstart tutorial about JBoss Fuse.

Tomcat by default doesn't ship with a JMS provider implementation: however connecting to jBoss JMS provider is not at all complicated. To make things more interesting we'll use JBoss ESB messaging provider, so we'll see how a Servlet deployed on Tomcat container can land on JBoss Service Bus.

In this tutorial we assume you have already a minimal knowledge of JBoss Service Bus. If you are new to this topic I suggest you reading this start-up tutorial:

1) Deploy the HelloWorld Service on your JBoss ESB

Ok the first thing to do is deploying the Helloworld service on your JBoss ESB. Move to the samples directory and compile first and deploy your service on the Service Bus. 

C:\jbossesb-server-4.4.GA\samples\quickstarts\helloworld>ant compile

C:\jbossesb-server-4.4.GA\samples\quickstarts\helloworld>ant deploy

Now start JBoss ESB.


2) Write your JMS Client

Your JMS Client will be a standard Servlet which init the JMS connection in its init() method and closes the connection in the destroy() callback method.

package test;

import java.util.Properties;

import javax.jms.JMSException;
import javax.jms.ObjectMessage;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

    QueueConnection conn;
    QueueSession session;
    Queue que;

    public TestServlet() {
    public void setupConnection() throws JMSException, NamingException
        Properties properties1 = new Properties();
        properties1.put(Context.PROVIDER_URL, "jnp://");
        InitialContext iniCtx = new InitialContext(properties1);

        Object tmp = iniCtx.lookup("ConnectionFactory");
        QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
        conn = qcf.createQueueConnection();
        que = (Queue) iniCtx.lookup("queue/quickstart_helloworld_Request_gw");
        session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        System.out.println("Connection Started");
    public void init(ServletConfig config) throws ServletException {
        try {
        } catch (JMSException e) {
            // TODO Auto-generated catch block
        } catch (NamingException e) {
            // TODO Auto-generated catch block

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

        try {
            sendAMessage("Hello World");
        } catch (JMSException e) {
            // TODO Auto-generated catch block


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    public void destroy()
        try {
        } catch (JMSException e) {
            // TODO Auto-generated catch block


    public void sendAMessage(String msg) throws JMSException {

        QueueSender send = session.createSender(que);
        ObjectMessage tm = session.createObjectMessage(msg);


Now create a mapping for this Servlet in your web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">


Add libraries to your Web application :

Last piece of the puzzle is adding the JBoss Messaging libraries (and its dependancies) in your WEB-INF/LIB. This is the list of needed jar files and its locations.

concurrent.jar JBOSS/CLIENT
javassist.jar  JBOSS/CLIENT
jbossall-client.jar JBOSS/CLIENT
jboss-aop-jdk50.jar        JBOSS/deploy/JBoss-aop-jdk50.deployer
jboss-common-client.jar  JBOSS/CLIENT
jboss-j2ee.jar JBOSS/server/default/lib
jboss-messaging.jar        JBOSSESB/server/default/lib
jbossmq-client.jar           JBOSS/CLIENT
jboss-system-client.jar     JBOSS/CLIENT
jnp-client.jar                  JBOSS/CLIENT
log4j.jar                        JBOSS/CLIENT
trove.jar                        JBOSS/CLIENT

Ok Now deploy your Web application and try sending messages....

JBoss & Tomcat versions used in this sample:

In order to run this sample, the following configurations were used:

Tomcat 6.0

The JDK used was the latest stable release of 1.5