/***************************************************************************/ /* */ /* (c) Copyright IBM Corp. 2006 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: mqhash */ /* */ /* Description: Sample java program that uses java hash table for the */ /* setting of the WebSphere MQ client environment variables */ /* */ /***************************************************************************/ /* */ /* Function: This program shows the use of a java hash table to set the */ /* WebSphere MQ environment. It requires a queue name parameter and */ /* takes an optional queue manager name parameter. The message that is */ /* put on the queue is hard-coded. This program has been tested with */ /* WebSphere MQ v6.0.10 and Java 1.5.0. */ /* */ /***************************************************************************/ /* */ /* Note: In order for this program to work, you'll need to change the */ /* MQC.CHANNEL_PROPERTY and MQC.HOST_NAME_PROPERTY to be the values that */ /* are valid for your system. The MQC.PORT_PROPERTY value can remain at */ /* 1414 if you are using the default port. */ /* */ /***************************************************************************/ /* */ /* mqhash has 2 parameters: */ /* queue name (required) */ /* queue manager name (optional) */ /* */ /***************************************************************************/ import com.ibm.mq.*; // Include the MQ package import java.io.*; import java.lang.*; public class mqhash { private MQQueueManager qMgr; /**********************************************************/ /* This program doesn't have any specific initialization. */ /* If it did, it could go here. */ /**********************************************************/ public void init() { /* put specific initialization here.... */ } public static void main (String args[]) throws IOException { /****************************************************************/ /* Check to make sure that at least the queue name was entered. */ /****************************************************************/ if (args.length < 1) { System.out.println("Required parameter missing - queue name"); } else { mqhash mySample = new mqhash(); mySample.init(); mySample.start(args); } } public void start(String args[]) { try { /*************************************************************/ /* Create a hash table to hold the WebSphere MQ environment. */ /* Note: Change values to be appropriate. */ /*************************************************************/ java.util.Hashtable env = new java.util.Hashtable(); env.put(MQC.CHANNEL_PROPERTY, "your channel name here"); env.put(MQC.HOST_NAME_PROPERTY, "your hostname here"); env.put(MQC.PORT_PROPERTY, new Integer(1414)); /********************************************************/ /* If a queue manager name was entered, then connect to */ /* it. Otherwise, use the default queue manager. */ /********************************************************/ if (args.length > 1) { qMgr = new MQQueueManager(args[1], env); } else { qMgr = new MQQueueManager("", env); } /***********************************************************/ /* Open the queue, build the message, and put the message. */ /***********************************************************/ int openOptions = MQC.MQOO_OUTPUT; MQQueue myQueue = qMgr.accessQueue(args[0], openOptions, null, null, null); MQMessage myMessage = new MQMessage(); myMessage.writeString("Environment set in hash table"); myMessage.format = MQC.MQFMT_STRING; MQPutMessageOptions pmo = new MQPutMessageOptions(); myQueue.put(myMessage, pmo); /**********************************************************/ /* Close the queue and disconnect from the queue manager. */ /**********************************************************/ myQueue.close(); qMgr.disconnect(); } catch (MQException ex) { System.out.println("An MQ error occurred: " + ex.completionCode + " " + ex.reasonCode); } catch (java.io.IOException ex) { System.out.println("Java exception: " + ex); } } }