Friday, July 29, 2011

HIBERNATE Examples - Step 4. Criteria based queries Examples

The following examples takes you through a series of aggregate functions, where clauses, group by and order by criteria using hibernate.

MAX()

public int getMaxDeptId() {

    int maxId = 0;

    HibernateTemplate ht = new HibernateTemplate(sessionFactory);
    DetachedCriteria criteria = DetachedCriteria
            .forClass(Departments.class);
    criteria.setProjection(Projections.max("deptId"));

    List result = ht.findByCriteria(criteria);
    maxId = (Integer) result.get(0);

    return maxId;
}

MIN()

public int getMinDeptId() {

    int minId = 0;

    HibernateTemplate ht = new HibernateTemplate(sessionFactory);
    DetachedCriteria criteria = DetachedCriteria
            .forClass(Departments.class);
    criteria.setProjection(Projections.min("deptId"));

    List result = ht.findByCriteria(criteria);

    minId = (Integer) result.get(0);
    return minId;
}

COUNT()

public int getDepartmentsCountStartedInYear(String year) {

    int value = 0;

    try {
        HibernateTemplate ht = new HibernateTemplate(sessionFactory);
        DetachedCriteria criteria = DetachedCriteria
                .forClass(Departments.class);
        criteria.setProjection(Projections.rowCount()).add(
                Restrictions.eq("yearStarted", year));

        List results = ht.findByCriteria(criteria);
        value = (Integer) results.get(0);

    } catch (Throwable e) {
        e.printStackTrace();
    }

    return value;
}

Restrictions based Query (AND, OR, comparators)

public List getCustomDepartments() {

 ArrayList values = new ArrayList();
 values.add("ECE");
 values.add("EEE");
 values.add("Info Tech");
 values.add("Mechanical");

 HibernateTemplate ht = new HibernateTemplate(sessionFactory);
 DetachedCriteria criteria = DetachedCriteria
   .forClass(Departments.class);

 criteria.add(Restrictions.in("deptName", values));
 criteria.add(Restrictions.and(Restrictions.in("deptName", values),
   Restrictions.le("deptId", 3)));

 criteria.addOrder(Order.desc("deptName"));

 return ht.findByCriteria(criteria);
}

GROUP BY

public void getDepartmentsInEachYear() {

    HibernateTemplate ht = new HibernateTemplate(sessionFactory);
    DetachedCriteria criteria = DetachedCriteria
            .forClass(Departments.class);

    criteria.setProjection(Projections.groupProperty("yearStarted"));

    System.out.println(">>>>" + ht.findByCriteria(criteria).size());
}

Order By

public List<Departments> getDepartments(boolean ascending) {

    HibernateTemplate ht = new HibernateTemplate(sessionFactory);
    DetachedCriteria criteria = DetachedCriteria
            .forClass(Departments.class);

    if (!ascending) {
        criteria.addOrder(Order.desc("deptName"));
    } else {
        criteria.addOrder(Order.asc("deptName"));
    }

    return ht.findByCriteria(criteria);
}


HIBERNATE Examples - Step 3. Simple CUD operations

The following example takes you through the Create Update Delete operations on a simple persistent object.

Departments.java

package org.mybusiness.pojos;

import java.io.Serializable;

public class Departments implements Serializable {

    private int deptId;

    private String deptName;

    private String yearStarted;

    public int getDeptId() {
        return deptId;
    }

    public void setDeptId(int deptId) {
        this.deptId = deptId;
    }

    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    public String getYearStarted() {
        return yearStarted;
    }

    public void setYearStarted(String yearStarted) {
        this.yearStarted = yearStarted;
    }
}

DepartmentsDao.java

package org.mybusiness.daos;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.mybusiness.pojos.Departments;
import org.springframework.orm.hibernate3.HibernateTemplate;

public class DepartmentDao {

    private SessionFactory sessionFactory;

    public DepartmentDao(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public boolean addDepartment(Departments department) {

        HibernateTemplate ht = new HibernateTemplate(sessionFactory);
        Serializable s = ht.save(department);
        System.out.println("Primary Key: " + s);
        return true;
    }

    public boolean deleteDepartment(Departments department) {

        HibernateTemplate ht = new HibernateTemplate(sessionFactory);
        ht.delete(department);
        return true;
    }
}

HIBERNATE Examples - Step 2. Creating HBM

The following are the HBMs defined for the examples used.

Departments.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.mybusiness.pojos">
    <class name="org.mybusiness.pojos.Departments" table="departments">
        <id column="DEPT_ID" name="deptId">
            <generator class="increment" />
        </id>

        <property name="deptName" column="NAME" update="false" />

        <property name="yearStarted" column="YEAR_STARTED" update="false" />        
    </class>
</hibernate-mapping>

HIBERNATE Examples - Step 1. Database Creation

The examples are all done using MYSQL database.

The following is the schema that is used for developing the examples.

CREATE TABLE DEPARTMENTS (
 DEPT_ID INTEGER(2) PRIMARY KEY, 
 NAME VARCHAR(20),
 YEAR_STARTED VARCHAR(4));

CREATE TABLE STUDENTS (
 STUDENT_ID INTEGER(5) PRIMARY KEY,
 NAME VARCHAR(30),
 AGE INTEGER(2),
 ADDRESS VARCHAR(50),
 DEPT_ID INTEGER(2),
 FOREIGN KEY (DEPT_ID) REFERENCES DEPARTMENTS(DEPT_ID)); 
 
COMMIT;

Thursday, July 28, 2011

MULE & HIBERNATE - Integrating Spring HibernateTemplate with Mule

How do I configure Hibernate in Mule?

The Mule config is basically built over the Spring Framework and it supports all the features in Spring Framework. It is quite simple to use the Spring's HibernateTemplate for making database calls inside your Mule Application.

The following steps takes through the configurations involved in using HibernateTemplate inside Mule.

1. Configuring the dependencies in your pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.mybusiness</groupId>
    <artifactId>HibernateTutorial</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>HibernateTutorial</name>
    <url>http://maven.apache.org</url>

    <repositories>
        <repository>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <id>MuleRepo</id>
            <name>Mule Repository</name>
            <url>http://repository.muleforge.org/
            </url>
        </repository>
        <repository>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <id>JBossRepo</id>
            <name>JBoss Repository</name>
            <url>
                https://repository.jboss.org/nexus/content/groups/public/
            </url>
        </repository>
        <repository>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <id>MuleDependencies</id>
            <name>Mule Dependencies</name>
            <url>http://dist.codehaus.org/mule/dependencies/maven2/</url>
        </repository>
    </repositories>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <!-- Hibernate Jars - START -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.2.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.3.2.GA</version>
            <type>pom</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.1.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <!-- Hibernate Jars - END -->

        <!-- Mysql Jars - START -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.14</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <!-- Mysql Jars - END -->

        <!-- Mule Jars - START -->
        <dependency>
            <groupId>org.mule</groupId>
            <artifactId>mule-core</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-vm</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-stdio</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <!-- Mule Jars - END -->

        <!-- Spring Framework Jars - START -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>2.5.6</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>2.5.6</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <!-- Spring Framework Jars - END -->

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project>

2. Configuring the DB Configurations in Spring Framework Style (DBConfigurations.xml).

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/mycollege" />
        <property name="username" value="root" />
        <property name="password" value="admin" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect
                </prop>
                <prop key="hibernate.connection.pool_size">20</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>Departments.hbm.xml</value>
            </list>
        </property>
    </bean>
</beans>

3. Importing the Database Configurations in your mule-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
    xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
    xmlns:spring="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="
          http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
          http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
          http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

    <spring:beans>
        <spring:import resource="DBConfigurations.xml" />
    </spring:beans>
</mule>

HIBERNATE - Hibernate Artifacts from Maven

How can I use Maven to get the latest Hibernate release?

The Maven Repository contains the hibernate jars as separate artifacts. The following dependencies in your pom.xml should be enough to get the hibernate jars in your maven project.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.mybusiness</groupId>
    <artifactId>HibernateTutorial</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>HibernateTutorial</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.3.2.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.3.2.GA</version>
            <type>pom</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.1.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</project> 

HIBERNATE - Creating configurations using Eclipse Hibernate Tool

Hibernate Configuration

The following steps takes you through the steps on creating an hibernate configuration easily using the Eclipse Plug-in.

1. Switch to Hibernate Perspective. Window->Open Perspective->Other->Hibernate

2. Right click on Hibernate Configurations tab and click on Add Configurations.

Add Configuration
3. In the new wizard, click on the Setup button on the Configuration file panel. This would ask for creating a new configuration or use an existing configuration.

Click on Setup to create configuration file
4. Proceed by click on Create new.

Create New Configurations
5. Select the location where the hibernate.cfg.xml file has to be created.

Location for storing hibernate.cfg.xml
6. Create the configuration based on your database. Here I am using MYSQL as my Database.

Configure the hibernate.cfg.xml based on database needs
7. Once the configuration file is created, go to the classpath tab and select the project that has to be used to refer the class files for this configuration. This classpath would be useful in using Hibernate Editors.

Classpath configurations

8. Click on Finish. Now you should be able to see the tables under the database that you have connected.

Databases and tables under Hibernate Configurations
NOTE: To use the HQL Editor and write queries, you need to create the HBM files and the corresponding POJO classes.

HIBERNATE - Hibernate Plugin for Ganymede Eclipse 3.4.2

We can find good hibernate plug-ins available under the JBoss plug-ins for eclipse. The following steps takes you through the installation of the Hibernate Tools alone from the JBoss Website for Ganymede Eclipse 3.4.2.

1. Open your Eclipse Platform.

2. Go to Help->Software Updates->Available Software->Add Site

3. Add the Site http://download.jboss.org/jbosstools/updates/JBossTools-3.0.3.GA

Add the Site
4. Select the Hibernate Tools from the list of available tools under JBoss and click on Install.

Select Hibernate Tools and Install
5. Review and continue with the installation.

Review and Finish the Installation
6. Allow the certificates to install the plugin.

Accept Certificates to install the plug-in
7. Restart Eclipse.

For installing other versions of the JBOSS Plug-in, refer to the following link that contains the update sites for different versions of Eclipse.

http://www.jboss.org/tools/download

Wednesday, July 27, 2011

Java - Purpose of SerialVersionUID

What is the purpose of defining a serialVersionUID in the classes that implements the serializable interface.


The idea is that if you change the class you change the serialVersionUID (for classes that implement Serializable).

This is helpful when you have serialized an object of one version at some point (like persisting an object to disk), and then deserialize it and attempt to cast it into the new version of the object. The id's will mismatch and you get an exception. This is a crude version safety mechanism.

MULE JMS - JMS Connector Acknowledgement Mode

The JMS Connector is used to configure a generic connector to send and receive messages over JMS Queues.

Attributes:

name: This is a mandatory attribute that provides a unique name to this connector.

acknowledgementMode: When a JMS Session is not having any transactions, one can use three kinds of acknowledgement mode.

DUPS_OK_ACKNOWLEDGE: This option instructs the session to lazily acknowledge the 
delivery of messages. This is likely to result in the delivery of some duplicate 
messages if JMS fails, so it should be used only by consumers that are tolerant of duplicate messages.
AUTO_ACKNOWLEDGE: The session automatically acknowledges a client’s receipt of a 
message when it has either successfully returned from a call to receive or the 
MessageListener it has called to process the message successfully returns.
CLIENT_ACKNOWLEDGE: A client acknowledges a message by calling the message’s 
acknowledge method. Acknowledging a consumed message automatically acknowledges 
the receipt of all messages that have been delivered by its session.

Tuesday, July 26, 2011

MULE - JBOSS JMS Integration

Mule JBoss JMS Integration

Mule is not a JMS provider. Mule can use the queues and topics from a JMS provider like JBOSS easily. The following example provides a simple configuration to use the JBoss JMS Queue in Mule.

1. Configuring your pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.mybusiness</groupId>
    <artifactId>MuleTutorial</artifactId>
    <version>1.0</version>

    <repositories>
        <repository>
            <id>MuleRepo</id>
            <name>Mule Repository</name>
            <url>http://repository.muleforge.org/</url>
            <layout>default</layout>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>

        <repository>
            <id>codehaus-repo</id>
            <name>Codehaus Repository</name>
            <url>http://dist.codehaus.org/mule/dependencies/maven2</url>
            <layout>default</layout>
            <releases>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>

        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group </name>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.mule</groupId>
            <artifactId>mule-core</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-vm</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-stdio</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-jms</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-file</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-jbossts</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.modules</groupId>
            <artifactId>mule-module-management</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.mule.transports</groupId>
            <artifactId>mule-transport-http</artifactId>
            <version>2.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jbossall-client</artifactId>
            <version>3.2.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jboss-client</artifactId>
            <version>4.0.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <properties>
        <mule.version>2.2.1</mule.version>
    </properties>
</project>

2. Configuring the mule-config.xml. In this example we are using the default queue testQueue provided by JBoss to test the JMS Functionality.

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
    xmlns:retry="http://www.mulesource.com/schema/mule/retry/2.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jbossts="http://www.mulesource.org/schema/mule/jbossts/2.2"
    xmlns:jms="http://www.mulesource.org/schema/mule/jms/2.2"
    xmlns:http="http://www.mulesource.org/schema/mule/http/2.2"
    xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
    xmlns:vm="http://www.mulesource.org/schema/mule/vm/2.2"
    xsi:schemaLocation="
          http://www.mulesource.org/schema/mule/file/2.2 http://www.mulesource.org/schema/mule/file/2.2/mule-file.xsd
          http://www.mulesource.org/schema/mule/jbossts/2.2 http://www.mulesource.org/schema/mule/jbossts/2.2/mule-jbossts.xsd
          http://www.mulesource.org/schema/mule/jms/2.2 http://www.mulesource.org/schema/mule/jms/2.2/mule-jms.xsd
          http://www.mulesource.org/schema/mule/management/2.2 http://www.mulesource.org/schema/mule/management/2.2/mule-management.xsd
          http://www.mulesource.org/schema/mule/cxf/2.2 http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd
          http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
          http://www.mulesource.com/schema/mule/retry/2.2 http://www.mulesource.com/schema/mule/retry/2.2/mule-retry-ee.xsd
          http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd
          http://www.mulesource.org/schema/mule/vm/2.2 http://www.mulesource.org/schema/mule/vm/2.2/mule-vm.xsd
          http://www.mulesource.org/schema/mule/jetty/2.2 http://www.mulesource.org/schema/mule/jetty/2.2/mule-jetty.xsd          
          http://www.mulesource.org/schema/mule/http/2.2 http://www.mulesource.org/schema/mule/http/2.2/mule-http.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd          
          http://www.mulesource.org/schema/mule/xml/2.2 http://www.mulesource.org/schema/mule/xml/2.2/mule-xml.xsd">

    <jbossts:transaction-manager/>

    <configuration>
        <default-dispatcher-threading-profile maxThreadsActive="50" maxThreadsIdle="25"
            threadTTL="60000"/>
        <default-receiver-threading-profile maxThreadsActive="50" maxThreadsIdle="25"
            threadTTL="60000"/>
        <default-service-threading-profile maxThreadsActive="50" maxThreadsIdle="25"
            threadTTL="60000"/>
    </configuration>

    <jms:connector name="jms-connector" jndiInitialFactory="org.jnp.interfaces.NamingContextFactory"
        jndiProviderUrl="jnp://127.0.0.1:1099"
        connectionFactoryJndiName="java:/QueueConnectionFactory" jndiDestinations="true"
        forceJndiDestinations="true" createMultipleTransactedReceivers="true"
        numberOfConcurrentTransactedReceivers="10" disableTemporaryReplyToDestinations="true">
        <!--retry:forever-policy frequency="2000"/-->
    </jms:connector>

    <stdio:connector name="stdioConnector" promptMessage="Please enter message: "  outputMessage="Received message: " messageDelayTime="3000"/>

    <jms:object-to-jmsmessage-transformer name="ObjectToJMSMessageTransformer"/>

    <jms:jmsmessage-to-object-transformer name="JMSMessageToObjectTransformer"/>

    <model>

        <service name="stdioToQueue">
            <inbound>
                <stdio:inbound-endpoint system="IN" synchronous="true"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <jms:outbound-endpoint queue="queue/testQueue" synchronous="true"/>
                </pass-through-router>
            </outbound>
        </service>

        <service name="queueToStdio">
            <inbound>
                <jms:inbound-endpoint queue="queue/testQueue" synchronous="true"/>
            </inbound>
            <outbound>
                <pass-through-router>
                    <stdio:outbound-endpoint system="OUT" synchronous="true"/>
                </pass-through-router>
            </outbound>
        </service>

    </model>
</mule>

3. Start the JBoss Server. This would bind the testQueue to JNDI.

4. Starting Mule Server. The Mule Server should get started successfully without any errors.

INFO  2011-07-26 23:49:32,035 [main] org.mule.MuleServer: Mule Server initializing...
INFO  2011-07-26 23:49:32,387 [main] org.mule.config.spring.MuleApplicationContext: Refreshing org.mule.config.spring.MuleApplicationContext@b753f8: display name [org.mule.config.spring.MuleApplicationContext@b753f8]; startup date [Tue Jul 26 23:49:32 CDT 2011]; root of context hierarchy
INFO  2011-07-26 23:49:33,285 [main] org.mule.config.spring.MuleApplicationContext: Bean factory for application context [org.mule.config.spring.MuleApplicationContext@b753f8]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1b6101e
WARN  2011-07-26 23:49:33,704 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_ObjectToString'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,708 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_ObjectToByteArray'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,708 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_ObjectToOutputHandler'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,708 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_ObjectToInputStream'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,713 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_XmlToOutputHandler'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,715 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_DomDocumentToString'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,718 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_XmlToDocumentResult'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,720 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named 'XmlToDom4jDocument'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,723 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named 'XmlToW3CDocument'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,731 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named 'transformer.7'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,732 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_JMSMessageToByteArray'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,732 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_JMSMessageToString'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,732 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_JMSMessageToHashtable'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,733 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_JMSMessageToVector'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,733 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_JMSMessageToObject'.  The previous object will be overwritten.
WARN  2011-07-26 23:49:33,734 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named '_ObjectToMessage'.  The previous object will be overwritten.
INFO  2011-07-26 23:49:33,892 [main] org.mule.transport.jms.JmsConnector: Initialising: JmsConnector{this=1552b76, started=false, initialised=false, name='jms-connector', disposed=false, numberOfConcurrentTransactedReceivers=10, createMultipleTransactedReceivers=true, connected=false, supportedProtocols=[jms], serviceOverrides=null}
INFO  2011-07-26 23:49:34,129 [main] org.mule.DefaultExceptionStrategy: Initialising exception listener: org.mule.DefaultExceptionStrategy@8f9a32
INFO  2011-07-26 23:49:34,140 [main] org.mule.transport.stdio.PromptStdioConnector: Initialising: PromptStdioConnector{this=e99ce5, started=false, initialised=false, name='stdioConnector', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=false, supportedProtocols=[stdio], serviceOverrides=null}
INFO  2011-07-26 23:49:34,150 [main] org.mule.DefaultExceptionStrategy: Initialising exception listener: org.mule.DefaultExceptionStrategy@15d252d
INFO  2011-07-26 23:49:34,237 [main] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.jms.transformers.ObjectToJMSMessage
INFO  2011-07-26 23:49:34,241 [main] org.mule.component.simple.PassThroughComponent: Initialising: org.mule.component.simple.PassThroughComponent component for: SedaService{stdioToQueue}
INFO  2011-07-26 23:49:34,249 [main] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default inbound transformer: org.mule.transport.jms.transformers.JMSMessageToObject
INFO  2011-07-26 23:49:34,250 [main] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default response transformer: org.mule.transport.jms.transformers.ObjectToJMSMessage
WARN  2011-07-26 23:49:34,250 [main] org.mule.registry.TransientRegistry: TransientRegistry already contains an object named 'ObjectToMessage'.  The previous object will be overwritten.
INFO  2011-07-26 23:49:34,253 [main] org.mule.component.simple.PassThroughComponent: Initialising: org.mule.component.simple.PassThroughComponent component for: SedaService{queueToStdio}
INFO  2011-07-26 23:49:34,254 [main] org.mule.config.builders.AutoConfigurationBuilder: Configured Mule using "org.mule.config.spring.SpringXmlConfigurationBuilder" with configuration resource(s): "[ConfigResource{resourceName='/C:/Vijay/Office/ganymedeWorkspace/MuleWork/MuleTutorial/src/main/resources/mule-config.xml'}]"
INFO  2011-07-26 23:49:34,254 [main] org.mule.config.builders.AutoConfigurationBuilder: Configured Mule using "org.mule.config.builders.AutoConfigurationBuilder" with configuration resource(s): "[ConfigResource{resourceName='/C:/Vijay/Office/ganymedeWorkspace/MuleWork/MuleTutorial/src/main/resources/mule-config.xml'}]"
INFO  2011-07-26 23:49:34,254 [main] org.mule.MuleServer: Mule Server starting...
INFO  2011-07-26 23:49:34,367 [main] org.mule.transport.jms.JmsConnector: Connected: JmsConnector{this=1552b76, started=false, initialised=true, name='jms-connector', disposed=false, numberOfConcurrentTransactedReceivers=10, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[jms], serviceOverrides=null}
INFO  2011-07-26 23:49:34,367 [main] org.mule.transport.jms.JmsConnector: Starting: JmsConnector{this=1552b76, started=false, initialised=true, name='jms-connector', disposed=false, numberOfConcurrentTransactedReceivers=10, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[jms], serviceOverrides=null}
INFO  2011-07-26 23:49:34,372 [main] org.mule.transport.jms.JmsConnector: Started: JmsConnector{this=1552b76, started=true, initialised=true, name='jms-connector', disposed=false, numberOfConcurrentTransactedReceivers=10, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[jms], serviceOverrides=null}
INFO  2011-07-26 23:49:34,373 [main] org.mule.transport.stdio.PromptStdioConnector: Connected: PromptStdioConnector{this=e99ce5, started=false, initialised=true, name='stdioConnector', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[stdio], serviceOverrides=null}
INFO  2011-07-26 23:49:34,373 [main] org.mule.transport.stdio.PromptStdioConnector: Starting: PromptStdioConnector{this=e99ce5, started=false, initialised=true, name='stdioConnector', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[stdio], serviceOverrides=null}
INFO  2011-07-26 23:49:34,373 [main] org.mule.transport.stdio.PromptStdioConnector: Started: PromptStdioConnector{this=e99ce5, started=true, initialised=true, name='stdioConnector', disposed=false, numberOfConcurrentTransactedReceivers=4, createMultipleTransactedReceivers=true, connected=true, supportedProtocols=[stdio], serviceOverrides=null}
INFO  2011-07-26 23:49:34,374 [main] org.mule.component.simple.PassThroughComponent: Starting: org.mule.component.simple.PassThroughComponent component for: SedaService{stdioToQueue}
INFO  2011-07-26 23:49:34,374 [main] org.mule.transport.stdio.PromptStdioConnector: Registering listener: stdioToQueue on endpointUri: stdio://system.in
INFO  2011-07-26 23:49:34,392 [main] org.mule.transport.stdio.StdioMessageReceiver: Connected: stdio://system.in
INFO  2011-07-26 23:49:34,397 [main] org.mule.model.seda.SedaService: Service stdioToQueue has been started successfully
INFO  2011-07-26 23:49:34,398 [main] org.mule.component.simple.PassThroughComponent: Starting: org.mule.component.simple.PassThroughComponent component for: SedaService{queueToStdio}
INFO  2011-07-26 23:49:34,398 [main] org.mule.transport.jms.JmsConnector: Registering listener: queueToStdio on endpointUri: jms://queue/testQueue
INFO  2011-07-26 23:49:34,448 [main] org.mule.transport.jms.MultiConsumerJmsMessageReceiver: Connected: jms://queue/testQueue
INFO  2011-07-26 23:49:34,451 [main] org.mule.model.seda.SedaService: Service queueToStdio has been started successfully
INFO  2011-07-26 23:49:34,451 [main] org.mule.util.queue.TransactionalQueueManager: Starting ResourceManager
INFO  2011-07-26 23:49:34,453 [main] org.mule.util.queue.TransactionalQueueManager: Started ResourceManager
INFO  2011-07-26 23:49:34,492 [main] org.mule.DefaultMuleContext: 
**********************************************************************
* Mule ESB and Integration Platform                                  *
* Version: 2.2.1 Build: 14422                                        *
* MuleSource, Inc.                                                   *
* For more information go to http://mule.mulesource.org              *
*                                                                    *
* Server started: 26/7/11 11:49 PM                                   *
* Server ID: d196b253-b80b-11e0-a167-db747a402dbb                    *
* JDK: 1.6.0_21 (mixed mode, sharing)                                *
* OS encoding: UTF-8, Mule encoding: UTF-8                           *
* OS: Windows Vista - Service Pack 2 (6.0, x86)                      *
* Host: vijay-Laptop (192.168.1.65)                                  *
*                                                                    *
* Agents Running: None                                               *
**********************************************************************

5. Testing the application

Please enter message: this is a test message
INFO  2011-07-26 23:50:12,104 [stdioConnector.receiver.1] org.mule.transport.jms.JmsMessageDispatcher: Connected: endpoint.outbound.jms://queue/testQueue
INFO  2011-07-26 23:50:12,147 [MessageListenerThread - testQueue] org.mule.transport.stdio.StdioMessageDispatcher: Connected: endpoint.outbound.stdio://system.out
Received message: this is a test message