/***************************************************************************/ /* */ /* (c) Copyright IBM Corp. 2003 All rights reserved. */ /* */ /* This sample program is owned by International Business Machines */ /* Corporation or one of its subsidiaries ("IBM") and is copyrighted */ /* and licensed, not sold. */ /* */ /* You may copy, modify, and distribute this sample program in any */ /* form without payment to IBM, for any purpose including developing, */ /* using, marketing or distributing programs that include or are */ /* derivative works of the sample program. */ /* */ /* The sample program is provided to you on an "AS IS" basis, without */ /* warranty of any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, */ /* EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ /* Some jurisdictions do not allow for the exclusion or limitation of */ /* implied warranties, so the above limitations or exclusions may not */ /* apply to you. IBM shall not be liable for any damages you suffer as */ /* a result of using, modifying or distributing the sample program or */ /* its derivatives. */ /* */ /***************************************************************************/ /* */ /* Program name: mqjmsusr */ /* */ /* Description: Sample java program that shows putting user properties */ /* into a jms message. */ /* */ /***************************************************************************/ /* */ /* Function: */ /* */ /* This program writes some properties into the usr folder of a jms */ /* message. These properties are stored in the RFH2 of the message. */ /* */ /* This program is run as follows: */ /* */ /* java mqjmsusr -icf ..... -url ... -qcf .... -q .... */ /* */ /* where */ /* -icf is the classname of the initial context factory. */ /* -url is the JNDI location of the administered objects. */ /* -qcf is the queue connection factory. */ /* -q is the queue. */ /* */ /* The output of this program can be verified by running: */ /* */ /* amqsbcg */ /* */ /* and looking at the message to see that it contains an RFH header that */ /* contains a usr properties folder with StringTag1 and IntTag2. */ /* */ /* This program has been tested with both WebSphere MQ 5.3 and */ /* MQSeries V5.2 CSD 6 against JDK 1.3.0. */ /* */ /***************************************************************************/ /* */ /* The queue connection factory and queue parameters to this program need */ /* to be setup so that they can be found. This is done via the JMS Admin- */ /* istration tool that is described in the Using Java manual. This */ /* program was tested using a file system context set up in a */ /* jmsadmin.config as folllows: */ /* */ /* INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory */ /* PROVIDER_URL=file:c://support//jms//sample */ /* SECURITY_AUTHENTICATION=none */ /* */ /* The actual JMSAdmin utility was run with the following definitions: */ /* */ /* def qcf(sampleQCF) qmanager(bower1.qmgr) */ /* def q(sampleQ) qu(SYSTEM.DEFAULT.LOCAL.QUEUE) */ /* */ /* The actual program execution would then be: */ /* */ /* java mqjmsusr -icf com.sun.jndi.fscontext.RefFSContextFactory */ /* -url file:c://support//jms//sample */ /* -qcf sampleQCF */ /* -q sampleQ */ /* */ /* An alternate method of running this program is to create a file named */ /* mqjmsusr.properties that contains the following: */ /* */ /* icf=com.sun.jndi.fscontext.RefFSContextFactory */ /* url=file:c://support//jms//sample */ /* qcf=sampleQCF */ /* q=sampleQ */ /* */ /***************************************************************************/ import java.io.*; import javax.jms.*; import javax.naming.*; import javax.naming.directory.*; import java.util.Hashtable; import java.util.Properties; public class mqjmsusr { private static String icf = null; private static String url = null; private static String qcfLookup = null; private static String qLookup = null; public mqjmsusr() { /***********************************************/ /* We'll get anything with the -D syntax first */ /***********************************************/ url = System.getProperty("url"); icf = System.getProperty("icf"); qcfLookup = System.getProperty("qcf"); qLookup = System.getProperty("q"); /**************************************************/ /* Check to see if there is a mqjmsusr.properties */ /**************************************************/ try { Properties props = new Properties(System.getProperties()); props.load(new BufferedInputStream(new FileInputStream("mqjmsusr.properties"))); System.setProperties(props); } catch (Exception e) { System.out.println("Unable to read mqjmsusr.properties:"); System.err.println(" " + e); } /******************************************************/ /* If any of the necessary properties are null, we'll */ /* take the value from the file since they weren't */ /* specified with -D. */ /******************************************************/ if (url == null) {url = System.getProperty("url");} if (icf == null) {icf = System.getProperty("icf");} if (qLookup == null) {qLookup = System.getProperty("q");} if (qcfLookup == null) {qcfLookup = System.getProperty("qcf");} } public mqjmsusr(String[] args) { this(); /**********************************/ /* Get the command-line arguments */ /**********************************/ for( int i=0; i