But you don't necessarily need them in the application server classpath - and that's what we'll be avoiding here.
MQ v5.2.1 MA88
25-07-2002 09:39 249.780 com.ibm.mq.jar
25-07-2002 09:39 39.267 com.ibm.mqbind.jar
25-07-2002 09:39 1.339.712 com.ibm.mqjms.jar
28-01-2002 09:29 17.978 connector.jar
28-01-2002 09:30 22.769 fscontext.jar
28-01-2002 09:30 77.116 providerutil.jar
MQ v5.3 CSD 11 (you need a login to access files)
01-03-2003 00:00 3.000 com.ibm.mqetclient.jar (required only if you want to interact transactionally)
02-08-2005 01:00 344.964 com.ibm.mq.jar
02-08-2005 01:00 41.816 com.ibm.mqbind.jar
02-08-2005 01:00 1.785.421 com.ibm.mqjms.jar
02-08-2005 01:00 17.978 connector.jar
02-08-2005 01:00 22.769 fscontext.jar
02-08-2005 01:00 77.116 providerutil.jar
MQ v6.0 (out-of-the box)
24-05-2005 01:00 3.363 com.ibm.mqetclient.jar (required only if you want to interact transactionally)
24-05-2005 02:00 421.771 com.ibm.mq.jar
24-05-2005 02:00 1.230.751 com.ibm.mqjms.jar
24-05-2005 02:00 2.099.749 dhbcore.jar
24-05-2005 02:00 22.769 fscontext.jar
24-05-2005 02:00 77.116 providerutil.jar
JMSAdmin.config
... INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory #INITIAL_CONTEXT_FACTORY=com.sun.jndi.ldap.LdapCtxFactory #INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory #INITIAL_CONTEXT_FACTORY=com.ibm.ejs.ns.jndi.CNInitialContextFactory #INITIAL_CONTEXT_FACTORY=com.ibm.websphere.naming.WsnInitialContextFactory # # The following line specifies the URL of the service provider's initial # context. It currently refers to an LDAP root context. Examples of a # file system URL and WebSphere's JNDI namespace are also shown, commented # out. # PROVIDER_URL=file:/C:/jms-jndi-directory #PROVIDER_URL=ldap://localhost:389/ou=Groups,o=Airius.com #PROVIDER_URL=ldap://polaris/o=ibm,c=us #PROVIDER_URL=file:/C:/JNDI-Directory #PROVIDER_URL=iiop://localhost/ ... # # The following line specifies the security authentication model in use, # and may be 'none' (for anonymous authentication), 'simple', or 'CRAM_MD5'. # SECURITY_AUTHENTICATION=none ... #Leave out the following entries as they probably already are #PROVIDER_USERDN #PROVIDER_PASSWORD ... |
MQSC commands
def qcf(TOPSECURITY_QCF) qmgr(BEAQM) channel(SYSTEM.DEF.SVRCONN) hostname(semp20) port(1421) transport(CLIENT) def q(TOPSECURITY_QUEUE) queue(TOPSECURITY.QUEUE) qmgr(BEAQM) |
TOPSECURITY_QCF/ClassName=com.ibm.mq.jms.MQQueueConnectionFactory TOPSECURITY_QCF/FactoryName=com.ibm.mq.jms.MQQueueConnectionFactoryFactoryWe're using the same queue manager for both non-transactional and transactional interaction. "hostname" is defined as "semp20" (2GHz sempron) and the queue manager operates from port 1421.
c:\jms-jndi-directory\.bindings
#This file is used by the JNDI FSContext. #Sun Aug 14 16:56:00 CEST 2005 TOPSECURITY_QUEUE/ClassName=com.ibm.mq.jms.MQQueue TOPSECURITY_QUEUE/FactoryName=com.ibm.mq.jms.MQQueueFactory TOPSECURITY_QUEUE/RefAddr/0/Content=6 TOPSECURITY_QUEUE/RefAddr/0/Encoding=String TOPSECURITY_QUEUE/RefAddr/0/Type=VER TOPSECURITY_QUEUE/RefAddr/1/Content=-2 TOPSECURITY_QUEUE/RefAddr/1/Encoding=String TOPSECURITY_QUEUE/RefAddr/1/Type=EXP TOPSECURITY_QUEUE/RefAddr/2/Content=-2 TOPSECURITY_QUEUE/RefAddr/2/Encoding=String TOPSECURITY_QUEUE/RefAddr/2/Type=PRI TOPSECURITY_QUEUE/RefAddr/3/Content=-2 TOPSECURITY_QUEUE/RefAddr/3/Encoding=String TOPSECURITY_QUEUE/RefAddr/3/Type=PER TOPSECURITY_QUEUE/RefAddr/4/Content=1208 TOPSECURITY_QUEUE/RefAddr/4/Encoding=String TOPSECURITY_QUEUE/RefAddr/4/Type=CCS TOPSECURITY_QUEUE/RefAddr/5/Content=0 TOPSECURITY_QUEUE/RefAddr/5/Encoding=String TOPSECURITY_QUEUE/RefAddr/5/Type=TC TOPSECURITY_QUEUE/RefAddr/6/Content=273 TOPSECURITY_QUEUE/RefAddr/6/Encoding=String TOPSECURITY_QUEUE/RefAddr/6/Type=ENC TOPSECURITY_QUEUE/RefAddr/7/Content=1 TOPSECURITY_QUEUE/RefAddr/7/Encoding=String TOPSECURITY_QUEUE/RefAddr/7/Type=FIQ TOPSECURITY_QUEUE/RefAddr/8/Content=TOPSECURITY.QUEUE TOPSECURITY_QUEUE/RefAddr/8/Encoding=String TOPSECURITY_QUEUE/RefAddr/8/Type=QU TOPSECURITY_QUEUE/RefAddr/9/Content=BEAQM TOPSECURITY_QUEUE/RefAddr/9/Encoding=String TOPSECURITY_QUEUE/RefAddr/9/Type=QMGR TOPSECURITY_QCF/ClassName=com.ibm.mq.jms.MQQueueConnectionFactory TOPSECURITY_QCF/FactoryName=com.ibm.mq.jms.MQQueueConnectionFactoryFactory TOPSECURITY_QCF/RefAddr/0/Content=6 TOPSECURITY_QCF/RefAddr/0/Encoding=String TOPSECURITY_QCF/RefAddr/0/Type=VER TOPSECURITY_QCF/RefAddr/1/Content=1 TOPSECURITY_QCF/RefAddr/1/Encoding=String TOPSECURITY_QCF/RefAddr/1/Type=TRAN TOPSECURITY_QCF/RefAddr/10/Content=false TOPSECURITY_QCF/RefAddr/10/Encoding=String TOPSECURITY_QCF/RefAddr/10/Type=SFIPS TOPSECURITY_QCF/RefAddr/11/Content=false TOPSECURITY_QCF/RefAddr/11/Encoding=String TOPSECURITY_QCF/RefAddr/11/Type=SPAG TOPSECURITY_QCF/RefAddr/12/Content=true TOPSECURITY_QCF/RefAddr/12/Encoding=String TOPSECURITY_QCF/RefAddr/12/Type=UCP TOPSECURITY_QCF/RefAddr/13/Content=5000 TOPSECURITY_QCF/RefAddr/13/Encoding=String TOPSECURITY_QCF/RefAddr/13/Type=PINT TOPSECURITY_QCF/RefAddr/14/Content=10 TOPSECURITY_QCF/RefAddr/14/Encoding=String TOPSECURITY_QCF/RefAddr/14/Type=MBS TOPSECURITY_QCF/RefAddr/15/Content=1 TOPSECURITY_QCF/RefAddr/15/Encoding=String TOPSECURITY_QCF/RefAddr/15/Type=FIQ TOPSECURITY_QCF/RefAddr/16/Content= TOPSECURITY_QCF/RefAddr/16/Encoding=String TOPSECURITY_QCF/RefAddr/16/Type=LA TOPSECURITY_QCF/RefAddr/17/Content=5000 TOPSECURITY_QCF/RefAddr/17/Encoding=String TOPSECURITY_QCF/RefAddr/17/Type=RINT TOPSECURITY_QCF/RefAddr/18/Content=true TOPSECURITY_QCF/RefAddr/18/Encoding=String TOPSECURITY_QCF/RefAddr/18/Type=TCM TOPSECURITY_QCF/RefAddr/19/Content=SYSTEM.DEFAULT.MODEL.QUEUE TOPSECURITY_QCF/RefAddr/19/Encoding=String TOPSECURITY_QCF/RefAddr/19/Type=TM TOPSECURITY_QCF/RefAddr/2/Content=BEAQM TOPSECURITY_QCF/RefAddr/2/Encoding=String TOPSECURITY_QCF/RefAddr/2/Type=QMGR TOPSECURITY_QCF/RefAddr/20/Content= TOPSECURITY_QCF/RefAddr/20/Encoding=String TOPSECURITY_QCF/RefAddr/20/Type=TQPFX TOPSECURITY_QCF/RefAddr/21/Content=1 TOPSECURITY_QCF/RefAddr/21/Encoding=String TOPSECURITY_QCF/RefAddr/21/Type=MRET TOPSECURITY_QCF/RefAddr/3/Content=semp20 TOPSECURITY_QCF/RefAddr/3/Encoding=String TOPSECURITY_QCF/RefAddr/3/Type=HOST TOPSECURITY_QCF/RefAddr/4/Content=1421 TOPSECURITY_QCF/RefAddr/4/Encoding=String TOPSECURITY_QCF/RefAddr/4/Type=PORT TOPSECURITY_QCF/RefAddr/5/Content=SYSTEM.DEF.SVRCONN TOPSECURITY_QCF/RefAddr/5/Encoding=String TOPSECURITY_QCF/RefAddr/5/Type=CHAN TOPSECURITY_QCF/RefAddr/6/Content=819 TOPSECURITY_QCF/RefAddr/6/Encoding=String TOPSECURITY_QCF/RefAddr/6/Type=CCS TOPSECURITY_QCF/RefAddr/7/Content=\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000 TOPSECURITY_QCF/RefAddr/7/Encoding=String TOPSECURITY_QCF/RefAddr/7/Type=CT TOPSECURITY_QCF/RefAddr/8/Content=0 TOPSECURITY_QCF/RefAddr/8/Encoding=String TOPSECURITY_QCF/RefAddr/8/Type=CTO TOPSECURITY_QCF/RefAddr/9/Content=0 TOPSECURITY_QCF/RefAddr/9/Encoding=String TOPSECURITY_QCF/RefAddr/9/Type=SRC |
TopsecurityMDB.java
package dk.topsecurity; import weblogic.rmi.RemoteException; import javax.ejb.*; import javax.jms.*; import javax.naming.*; /** * The message bean, which - through external JNDI provider - is using a * context factory, that uses IBM mq classes - and treats the MQ as an * external JMS provider. * */ public class TopsecurityMDB implements MessageDrivenBean, MessageListener { public void ejbActivate() { System.out.println("ejbActivate called"); } public void ejbRemove() { System.out.println("ejbRemove called"); } public void ejbPassivate() { System.out.println("ejbPassivate called"); } public void ejbCreate () throws CreateException { System.out.println("ejbCreate called"); } public void setMessageDrivenContext(MessageDrivenContext ctx) { System.out.println("setMessageDrivenContext called"); m_context = ctx; } /** * onMessage required by the MessageListener interface - receives messages * from the external JMS provider */ public void onMessage(Message msg) { TextMessage tm = (TextMessage) msg; try { String text = tm.getText(); System.out.println("Received message from JMS provider : " + text); } catch(JMSException ex) { ex.printStackTrace(); } } private MessageDrivenContext m_context; } |
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd"> <ejb-jar> <enterprise-beans> <message-driven> <ejb-name>TopsecurityMDB example1</ejb-name> <ejb-class>dk.topsecurity.TopsecurityMDB</ejb-class> <transaction-type>Container</transaction-type> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> </message-driven-destination> </message-driven> <message-driven> <ejb-name>TopsecurityMDB example2</ejb-name> <ejb-class>dk.topsecurity.TopsecurityMDB</ejb-class> <transaction-type>Container</transaction-type> <message-driven-destination> <destination-type>javax.jms.Queue</destination-type> </message-driven-destination> </message-driven> </enterprise-beans> <assembly-descriptor> <container-transaction> <method> <ejb-name>TopsecurityMDB example1</ejb-name> <method-name>*</method-name> </method> <trans-attribute>NotSupported</trans-attribute> </container-transaction> <container-transaction> <method> <ejb-name>TopsecurityMDB example2</ejb-name> <method-name>*</method-name> </method> <trans-attribute>NotSupported</trans-attribute> </container-transaction> </assembly-descriptor> </ejb-jar> |
weblogic-ejb-jar.xml
<?xml version="1.0"?> <!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd"> <!-- Sample MessageDriven bean Weblogic deployment descriptor --> <weblogic-ejb-jar> <weblogic-enterprise-bean> <ejb-name>TopsecurityMDB example1</ejb-name> <message-driven-descriptor> <pool> <max-beans-in-free-pool>5</max-beans-in-free-pool> <initial-beans-in-free-pool>2</initial-beans-in-free-pool> </pool> <destination-jndi-name>TOPSECURITY_QUEUE</destination-jndi-name> <initial-context-factory>com.sun.jndi.fscontext.RefFSContextFactory</initial-context-factory> <provider-url>file:/C:/jms-jndi-directory</provider-url> <connection-factory-jndi-name>TOPSECURITY_QCF</connection-factory-jndi-name> </message-driven-descriptor> <jndi-name>TopsecurityMDB1</jndi-name> </weblogic-enterprise-bean> <weblogic-enterprise-bean> <ejb-name>TopsecurityMDB example2</ejb-name> <message-driven-descriptor> <destination-jndi-name>TOPSECURITY_QUEUE</destination-jndi-name> <initial-context-factory>com.sun.jndi.fscontext.RefFSContextFactory</initial-context-factory> <provider-url>file:/C:/jms-jndi-directory</provider-url> <connection-factory-jndi-name>TOPSECURITY_QCF</connection-factory-jndi-name> </message-driven-descriptor> <jndi-name>TopsecurityMDB2</jndi-name> </weblogic-enterprise-bean> </weblogic-ejb-jar> |
config.xml
... <Application Name="_appsdir_TopsecurityMQ_jar" Path="C:\bea\user_projects\domains\mqtest\applications" StagedTargets="myserver" StagingMode="stage" TwoPhase="true"> <EJBComponent Name="TopsecurityMQ" Targets="myserver" URI="TopsecurityMQ.jar"/> </Application> ... |
TopsecurityMQClient.java
package dk.topsecurity; import javax.jms.*; import javax.naming.*; import javax.naming.directory.*; import java.util.*; public class TopsecurityMQClient implements ExceptionListener { /** * Setting up authorisation username. Used by classes in com.ibm.mqjms.jar * Setting up queue connection factory (QCF) * Setting up name of queue, as defined in the MQ setup * Setting up url for file-based, external JNDI provider * Setting up context factory to use with external JNDI */ public String mq_username = "Administrator"; public String mq_qcf = "TOPSECURITY_QCF"; public String mq_qname = "TOPSECURITY_QUEUE"; public String mq_url = "file:/C:/jms-jndi-directory"; public String mq_jndi = "com.sun.jndi.fscontext.RefFSContextFactory"; /** * main method - binding to the Websphere MQ installation - and delivering a * number of messages. * * Make sure you've run the MQSC commands on MQ before deploying examples * * define qcf(TOPSECURITY_QCF) qmgr(BEAQM) channel(SYSTEM.DEF.SVRCONN) hostname(semp20) port(1421) transport(CLIENT) * define q(TOPSECURITY_QUEUE) queue(TOPSECURITY.QUEUE) qmgr(BEAQM) */ public static void main(String[] args) { TopsecurityMQClient sender = null; try { sender = new TopsecurityMQClient(); sender.setupQueueConnection(); for(int i=0;;i++) { sender.send(sender.setMessage("Hello no "+i+" from client at "+new Date())); } } catch(JMSException je) { System.out.println("Caught JMSException: "+je); Exception le = je.getLinkedException(); if (le != null) System.out.println("Linked exception: "+le); je.printStackTrace(); } catch(Exception e) { e.printStackTrace(); } finally { try { if (sender != null) sender.cleanup(); } catch (Exception e) { } } } private void setupQueueConnection() throws Exception { |
/* authentication related part - completely remove when running MQ and * J2EE client on same machine under same user - or different machines * and identical user names. Otherwise enter the username used for the * MQ installation. Failure to do so, will cause the program to exit with * authentication exception. */ System.out.println("Initial user.name="+System.getProperty("user.name")); System.setProperty("user.name",mq_username); System.out.println("Authrorisation required user.name="+System.getProperty("user.name")); /*end of authentication related part*/ |
Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, mq_jndi); env.put(Context.PROVIDER_URL, mq_url); InitialDirContext ctx = new InitialDirContext(env); com.ibm.mq.jms.MQQueueConnectionFactory factory = (com.ibm.mq.jms.MQQueueConnectionFactory)ctx.lookup(mq_qcf); System.out.println("Factory = " +factory); /* Create a QueueConnection, QueueSession * When a connection is made, use the createQueueSession method on the * QueueConnection to obtain a session. Parameters: * boolean= determines whether the session is transacted or non-transacted. * int = that determines the acknowledge mode. * Simplest case is that of the non-transacted session with AUTO_ACKNOWLEDGE * - p319 in the IBM redbook. */ connection = factory.createQueueConnection(); session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); ioQueue = (Queue)ctx.lookup(mq_qname); connection.start(); connection.setExceptionListener(this); queueSender = session.createSender(ioQueue); } /** * For test purpose, create one of many possible types of messages: * BytesMessage, MapMessage, ObjectMessage, StreamMessage */ TextMessage setMessage(String text) throws Exception { TextMessage msg = session.createTextMessage(); msg.setText(text); return(msg); } /** * Send message off to MQ */ void send(TextMessage msg) throws Exception { System.out.println("Sending the message on queue " + ioQueue.getQueueName()); queueSender.send(msg); } /** * required in the ExceptionListener interface */ public void onException(JMSException jms) { System.out.println("onException: jms" + jms); jms.printStackTrace(); } /** * do away with connections to MQ */ void cleanup() throws Exception { if (session != null) { session.close(); session = null; } if (connection != null) connection.close(); connection = null; } private Queue ioQueue; private QueueSession session; private QueueConnection connection; private QueueConnectionFactory factory; private QueueSender queueSender; private InitialContext ctx; private TextMessage msg; } |
build.xml
<project name="TopsecurityMQ" default="all" basedir="."> <target name="init"> <property name="wl_home" value="C:/bea/weblogic81"/> <property environment="env"/> <property name="JAVAC" value="modern"/> <property name="build.compiler" value="${JAVAC}"/> <property name="source" value="./src"/> <property name="compiledir" value="./build"/> <property name="mqlibdir" value="./mqlib"/> <property name="earstage" value="./earstage"/> <property name="project_name" value="TopsecurityMQ"/> <property name="mqjava" value="${mqlibdir}/com.ibm.mq.jar"/> <property name="mqjms" value="${mqlibdir}/com.ibm.mqjms.jar"/> </target> <target name="all" depends="init, clean, compile, buildjar, ejbc"/> <target name="clean" depends="init"> <!-- Create the time stamp --> <tstamp/> <delete dir="${compiledir}" /> <mkdir dir="${compiledir}"/> <mkdir dir="${compiledir}/META-INF"/> <delete dir="${earstage}" /> <mkdir dir="${earstage}" /> <mkdir dir="${earstage}/META-INF" /> </target> <target name="compile" depends="clean"> <javac srcdir="${source}" destdir="${compiledir}" classpath="${wl_home}\server\lib\weblogic.jar;${mqjava};${mqjms}" includes="**/*.java"/> </target> <target name="buildjar" depends="compile"> <copy file="${source}/ejb-jar.xml" todir="${compiledir}/META-INF" overwrite="yes"/> <copy file="${source}/weblogic-ejb-jar.xml" todir="${compiledir}/META-INF" overwrite="yes"/> <unzip dest="${compiledir}"> <fileset dir="${mqlibdir}"> <include name="**/*.jar"/> <exclude name="**/weblogic*.jar"/> </fileset> </unzip> <jar jarfile="${compiledir}/${project_name}.jar" basedir="${compiledir}" includes="**/TopsecurityMDB*.class,**/*.xml,com/**/*.class,*.properties" update="yes"> <manifest> <attribute name="Built-By" value="${user.name}"/> </manifest> </jar> <jar jarfile="${earstage}/${project_name}_client.jar" basedir="${compiledir}" includes="**/TopsecurityMQ*Client*.class" update="yes"> </jar> </target> <target name="ejbc" depends="buildjar"> <java classname="weblogic.ejbc" fork="yes" failonerror="yes" classpath="${wl_home}\server\lib\weblogic.jar"> <sysproperty key="weblogic.home" value="${compiledir}"/> <arg line="-compiler javac ${compiledir}/${project_name}.jar ${earstage}/${project_name}.jar"/> </java> </target> </project> |
send-NOTX.cmd
set BEA_HOME=C:\bea set WL_HOME=C:\bea\weblogic81 java -classpath .;.\earstage\TopsecurityMQ_client.jar;%WL_HOME%\weblogic.jar;.\mqlib\com.ibm.mq.jar;.\mqlib\com.ibm.mqjms.jar;.\mqlib\fscontext.jar;.\mqlib\providerutil.jar;.\mqlib\dbhcore.jar dk/topsecurity/TopsecurityMQClient |