package wbitest; /* * Licensed Materials - Property of IBM Corp. * 5648-C60 (c) Copyright IBM Corp. 1999 * * Point to Point Sample01 * * Demonstrates: * how to retrieve administered objects from JNDI namespace * how to create administered objects at runtime if no JNDI is availabe * how to create connections, sessions, senders and receivers * how to send and receive a message * * This program connects to the default queue manager on the local machine * using the MQ Classes for Java bindings. It then sends a message to the * queue SYSTEM.DEFAULT.LOCAL.QUEUE and reads it back again. * * This sample uses the same administered objects as the installation * verification test program. These are: * * (i) an MQQueueConnectionFactory bound under the name "ivtQCF", created * using no explicit properties, thus making use of all available * defaults * * e.g. DEFINE QCF(ivtQCF) * * (ii) an MQQueue bound under the name "ivtQ", created using the property * QUEUE(SYSTEM.DEFAULT.LOCAL.QUEUE) plus other available defaults * * e.g. DEFINE Q(ivtQ) QUEUE(SYSTEM.DEFAULT.LOCAL.QUEUE) * * This sample will fail if these objects cannot be retrieved from a JNDI * service provider, unless -nojndi is specified (see below). They can be * created automatically by running the IVTSETUP script, and can be auto- * matically removed by running the IVTTIDY script. * * Usage: * * java PTPSample01 -nojndi [ -m qmgr ] [ -t ] * or java PTPSample01 -url providerURL [ -icf initialContextFactory ] [ -t ] * * where: * * -nojndi - specify this to disable JNDI lookup of * the two required administered objects * -m qmgr - specify the name of the queue manager to * connect to, if not the default one * -t - enabled tracing * -url providerURL - specify the URL of the JNDI initial * context (this parameter is obligatory * unless the -nojndi switch is supplied, * in which case it is ignored * -icf initialContextFactory - specify the initialContextFactory for * JNDI [com.sun.jndi.ldap.LdapCtxFactory] * */ // Import of Sun's JMS interface import javax.jms.*; // Imports for JNDI import javax.naming.*; import javax.naming.directory.*; // Used for JNDI initialisation import java.util.Hashtable; // The following import would not normally be required in a JMS application, // but is included here to allow us to bypass the JNDI lookup stage import com.ibm.mq.jms.MQQueueConnectionFactory; // Import required for program tracing import com.ibm.mq.jms.services.ConfigEnvironment; public class QueueTest { // These are used when the -nojndi flag is given. public static String QMGR = ""; public static final String QUEUE = "SYSTEM.DEFAULT.LOCAL.QUEUE" ; // The following can be modified if you want to experiment with // using other administered objects with different content. public static final String qcfLookup = "headleyCF"; public static final String qLookup = "headleyq"; //public static final String qcfLookup = "headleyCF"; // public static final String qLookup = "jms/WBICF"; public static void main( String[] args ) { String outString = "A simple text message from PTPSample01"; Queue ioQueue = null; QueueSession session = null; QueueConnection connection = null; QueueConnectionFactory factory = null; Context ctx = null; boolean useJNDI = true; boolean enableTrace = false; //String icf = "com.sun.jndi.fscontext.RefFSContextFactory"; String icf = "com.ibm.websphere.naming.WsnInitialContextFactory"; String url = null; System.out.println( "\n5648-C60, 5724-B41, 5655-F10 (c) Copyright IBM Corp. 1999. " + "All Rights Reserved."); System.out.println( "Websphere MQ classes for Java(tm) Message Service - "+ "Point to Point Sample 1"+ "\n" ); // Process each of the command-line arguments in turn for( int i=0; i