WebSphere MQ Messenger Java GUI  1.0
GNU Free Software License
 All Classes Namespaces Files Functions Variables
FRMMain.java
Go to the documentation of this file.
1  /* Websphere MQ Client - Connects and sends or receives messages from WebSphere (IBM) Application Server
2  * WebSphere is Copyright IBM
3  Copyright (C) 2012 David Welford-Costelloe (http://www.welford-costelloe.org)
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 package com.ca.on.burlington.base.forms;
19 
20 import java.awt.Color;
21 import java.awt.Font;
22 import java.awt.Panel;
23 import java.awt.Rectangle;
24 import java.awt.Scrollbar;
25 import java.awt.TextArea;
26 import java.awt.TextField;
27 import java.awt.Toolkit;
28 import java.awt.event.KeyEvent;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 import javax.swing.JButton;
34 import javax.swing.JCheckBox;
35 import javax.swing.JFrame;
36 import javax.swing.JLabel;
37 import javax.swing.JOptionPane;
38 import javax.swing.JPanel;
39 import javax.swing.JScrollPane;
40 import javax.swing.JTextArea;
41 import javax.swing.SwingUtilities;
42 
43 import com.ca.on.burlington.base.classes.PropertiesClass;
44 import com.ca.on.burlington.base.classes.UtilsClass;
45 import com.ibm.mq.MQC;
46 import com.ibm.mq.MQEnvironment;
47 import com.ibm.mq.MQException;
48 import com.ibm.mq.MQGetMessageOptions;
49 import com.ibm.mq.MQMessage;
50 import com.ibm.mq.MQPutMessageOptions;
51 import com.ibm.mq.MQQueue;
52 import com.ibm.mq.MQQueueManager;
53 import javax.swing.ImageIcon;
54 import javax.swing.SwingConstants;
55 import javax.swing.JTextPane;
56 import javax.swing.JTable;
57 import javax.swing.JScrollBar;
58 import javax.swing.border.EtchedBorder;
59 import javax.swing.UIManager;
60 import org.openswing.swing.client.ImagePanel;
61 import java.awt.BorderLayout;
62 
67 public class FRMMain extends JFrame {
68 
69  private static final long serialVersionUID = 1L;
70  private JPanel jContentPane = null;
75  private JLabel jLabel11 = null;
76  private TextArea textAreaResults = null;
77  private JLabel jLabel111 = null;
78  private TextField textRequestQManagerName = null;
79  private TextField textRequestQueueName = null;
80  private JLabel jLabel112 = null;
81  private Panel panel = null;
82  private JLabel jLabel = null;
83  private TextField textFieldHostName = null;
84  private JLabel jLabel1 = null;
85  private TextField textFieldChannleName = null;
86  private Panel panel1 = null;
87  private JLabel jLabel113 = null;
88  private TextField textReplyQueueName = null;
89  private JLabel jLabel1111 = null;
90  private Scrollbar scrollbar = null;
91  private TextField textFieldPort = null;
92  private JLabel jLabel1112 = null;
93  private TextField textReplyQManager = null;
94  private JButton jButtonSend = null;
95  private JButton jBtnExit = null;
96  private JButton jBtnCheckMessages = null;
97  private JCheckBox jChkDuelQueues = null;
98  private JCheckBox jChkQueueManager = null;
99  private Font errorFont = new Font("Verdana", Font.ITALIC, 12);
100  private Font regularFont = new Font("Verdana", Font.PLAIN, 12); // @jve:decl-index=0:
101  private MQQueueManager requestQMgr;
102  private MQQueueManager replyQMgr;
103  private UtilsClass utils = new UtilsClass();
104  private MQQueue requestQueue = null;
105  private MQQueue replyQueue = null;
106  private List<PropertiesClass> arList = new ArrayList<PropertiesClass>(); // @jve:decl-index=0:
107  private JButton jBtnClearResults = null;
108  private JScrollPane jScrollPane = null;
109  private JTextArea textAreaMessage = null;
110  private JLabel wIcon;
111 
117  private TextArea getTextAreaResults() {
118  if (textAreaResults == null) {
119  textAreaResults = new TextArea();
120  textAreaResults.setBounds(new Rectangle(17, 554, 1135, 170)); // Generated
121  textAreaResults.setEditable(false); // Generated
122  }
123  return textAreaResults;
124  }
125 
131  private TextField getTextRequestQManagerName() {
132  if (textRequestQManagerName == null) {
133  textRequestQManagerName = new TextField();
134  textRequestQManagerName.setBounds(new Rectangle(12, 125, 527, 25)); // Generated
135  }
137  }
138 
144  private TextField getTextRequestQueueName() {
145  if (textRequestQueueName == null) {
146  textRequestQueueName = new TextField();
147  textRequestQueueName.setBounds(new Rectangle(6, 28, 527, 25)); // Generated
148  }
149  return textRequestQueueName;
150  }
151 
157  private Panel getPanel() {
158  if (panel == null) {
159  jLabel1112 = new JLabel();
160  jLabel1112.setBounds(new Rectangle(13, 154, 172, 17)); // Generated
161  jLabel1112.setText("Enter Reply QManager Name:"); // Generated
162  jLabel1112
163  .setToolTipText("Enter the name of the QManage to connect to"); // Generated
164  jLabel1111 = new JLabel();
165  jLabel1111.setText("Select the port number"); // Generated
166  jLabel1111.setBounds(new Rectangle(10, 117, 159, 21)); // Generated
167  jLabel1111.setToolTipText(""); // Generated
168  jLabel1 = new JLabel();
169  jLabel1.setBounds(new Rectangle(12, 63, 151, 17)); // Generated
170  jLabel1.setText("Enter Channel Name:"); // Generated
171 
172  jLabel = new JLabel();
173  jLabel.setToolTipText("Enter the name of the Host"); // Generated
174  jLabel.setBounds(new Rectangle(12, 9, 101, 16)); // Generated
175  jLabel.setText("Enter Host Name:"); // Generated
176  panel = new Panel();
177  panel.setLayout(null); // Generated
178  panel.setBounds(new Rectangle(12, 11, 557, 208)); // Generated
179  panel.add(getTextFieldHostName(), null); // Generated
180  panel.add(jLabel, null); // Generated
181  panel.add(jLabel1, null); // Generated
182  panel.add(getTextFieldChannleName(), null); // Generated
183  panel.add(getTextRequestQManagerName(), null); // Generated
184  panel.add(jLabel111, null); // Generated
185  panel.add(jLabel1112, null); // Generated
186  panel.add(getTextReplyQManager(), null); // Generated
187  panel.add(getJChkQueueManager(), null); // Generated
188  }
189  return panel;
190  }
191 
197  private TextField getTextFieldHostName() {
198  if (textFieldHostName == null) {
199  textFieldHostName = new TextField();
200  textFieldHostName.setBounds(new Rectangle(12, 28, 527, 25)); // Generated
201  }
202  return textFieldHostName;
203  }
204 
210  private TextField getTextFieldChannleName() {
211  if (textFieldChannleName == null) {
212  textFieldChannleName = new TextField();
213  textFieldChannleName.setBounds(new Rectangle(12, 80, 527, 25)); // Generated
214  }
215  return textFieldChannleName;
216  }
217 
224  private Panel getPanel1() throws IOException {
225  if (panel1 == null) {
226  jLabel113 = new JLabel();
227  jLabel113.setBounds(new Rectangle(10, 60, 223, 23)); // Generated
228  jLabel113.setText("Enter the Queue Name to Listen to "); // Generated
229  jLabel113.setToolTipText(""); // Generated
230  panel1 = new Panel();
231  panel1.setLayout(null); // Generated
232  panel1.setBounds(new Rectangle(588, 15, 557, 200)); // Generated
233  panel1.add(jLabel11, null); // Generated
234  panel1.add(getTextRequestQueueName(), null); // Generated
235  panel1.add(jLabel113, null); // Generated
236  panel1.add(getTextReplyQueueName(), null); // Generated
237  panel1.add(jLabel1111, null); // Generated
238  panel1.add(getScrollbar(), null); // Generated
239  panel1.add(getTextFieldPort(), null); // Generated
240  panel1.add(getJChkDuelQueues(), null);
241 
242  ImagePanel imagePanel = new ImagePanel();
243  BorderLayout borderLayout = (BorderLayout) imagePanel.getLayout();
244  borderLayout.setVgap(1);
245  borderLayout.setHgap(1);
246  imagePanel.setToolTipText("GNU Free Software");
247  imagePanel.setImageName("");
248  imagePanel.setImage(Toolkit.getDefaultToolkit().getImage(FRMMain.class.getResource("/com/ca/on/burlington/base/images/gplv3-127x51.png")));
249  imagePanel.setBounds(361, 120, 172, 62);
250  panel1.add(imagePanel);
251  ImageIcon image = new ImageIcon(FRMMain.class.getResource("/com/ca/on/burlington/base/images/gplv3-127x51.png"));
252 
253  //ImageIcon image = new ImageIcon(FRMMain.class.getResource("/com/ca/on/burlington/base/images/gplv3-127x51.png"));
254  }
255  return panel1;
256  }
257 
263  private TextField getTextReplyQueueName() {
264  if (textReplyQueueName == null) {
265  textReplyQueueName = new TextField();
266  textReplyQueueName.setBounds(new Rectangle(10, 85, 528, 23)); // Generated
267  }
268  return textReplyQueueName;
269  }
270 
276  private Scrollbar getScrollbar() {
277  if (scrollbar == null) {
278  scrollbar = new Scrollbar();
279  scrollbar.setValue(1420); // Generated
280  scrollbar.setOrientation(Scrollbar.HORIZONTAL); // Generated
281  scrollbar.setVisibleAmount(10); // Generated
282  scrollbar.setBounds(new Rectangle(19, 143, 165, 39)); // Generated
283  scrollbar.setMaximum(9999); // Generated
284  scrollbar
285  .addAdjustmentListener(new java.awt.event.AdjustmentListener() {
286  public void adjustmentValueChanged(
287  java.awt.event.AdjustmentEvent e) {
288  int val = scrollbar.getValue();
289  textFieldPort.setText(String.valueOf(val));
290 
291  }
292 
293  });
294  }
295  return scrollbar;
296  }
297 
303  private TextField getTextFieldPort() {
304  if (textFieldPort == null) {
305  textFieldPort = new TextField();
306  textFieldPort.setEditable(false); // Generated
307  textFieldPort.setBounds(new Rectangle(204, 149, 139, 24)); // Generated
308  }
309  return textFieldPort;
310  }
311 
317  private TextField getTextReplyQManager() {
318  if (textReplyQManager == null) {
319  textReplyQManager = new TextField();
320  textReplyQManager.setBounds(new Rectangle(12, 173, 532, 24)); // Generated
321  }
322  return textReplyQManager;
323  }
324 
330  private JButton getJButtonSend() {
331  if (jButtonSend == null) {
332  jButtonSend = new JButton();
333  jButtonSend.setBounds(new Rectangle(18, 770, 123, 32)); // Generated
334  jButtonSend.setText("Send Message"); // Generated
336  .setToolTipText("Click to send a message to Websphere MQ"); // Generated
337  jButtonSend.setEnabled(false); // Generated
338  jButtonSend.setMnemonic(KeyEvent.VK_S); // Generated
339  jButtonSend.addActionListener(new java.awt.event.ActionListener() {
340  public void actionPerformed(java.awt.event.ActionEvent e) {
341  StringBuffer sb = new StringBuffer();
342  init();
343  System.out.println("arLidt : " + arList.toString());
344  for (PropertiesClass oList : arList) {
345  oList.setPortNum(Integer.parseInt(textFieldPort
346  .getText()));
347  sb.append("Host: [" + oList.getHostName() + "]\n");
348  sb
349  .append("Port Number: [" + oList.getPortNum()
350  + "]\n");
351  sb
352  .append("Channel: [" + oList.getChannelName()
353  + "]\n");
354  sb.append("Queue Manager ["
355  + oList.getRequestQManager() + "]\n");
356  sb.append("Queue Name: [" + oList.getRequestQueueName()
357  + "]");
358  }
359  // Make sure required fields are checked
360  if (checkInputs(true)) {
361 
362  sendYesNoDialog(sb, "Confirm Parameters");
363 
364  }
365  }
366  });
367  }
368  return jButtonSend;
369  }
370 
376  private JButton getJBtnExit() {
377  if (jBtnExit == null) {
378  jBtnExit = new JButton();
379  jBtnExit.setBounds(new Rectangle(1022, 773, 120, 26)); // Generated
380  jBtnExit.setText("Exit"); // Generated
381  jBtnExit.setToolTipText("Click to Exit Application"); // Generated
382  jBtnExit.setMnemonic(KeyEvent.VK_X); // Generated
383  jBtnExit.addActionListener(new java.awt.event.ActionListener() {
384  public void actionPerformed(java.awt.event.ActionEvent e) {
385  exitApplication();
386  }
387  });
388  }
389  return jBtnExit;
390  }
391 
397  private JButton getJBtnCheckMessages() {
398  if (jBtnCheckMessages == null) {
399  jBtnCheckMessages = new JButton();
400  jBtnCheckMessages.setBounds(new Rectangle(271, 775, 156, 25)); // Generated
401  jBtnCheckMessages.setText("Check for Messages"); // Generated
402  jBtnCheckMessages.setToolTipText("Click to check for messages"); // Generated
403  jBtnCheckMessages.setEnabled(true); // Generated
404  jBtnCheckMessages.setMnemonic(KeyEvent.VK_E); // Generated
406  .addActionListener(new java.awt.event.ActionListener() {
407  public void actionPerformed(java.awt.event.ActionEvent e) {
408  String sHold = "Socket connection attempt refused";
409  String sMsg = null;
410  // Only need to check reading
411  if (checkInputs(false)) {
412 
413  init();
414  try {
415  readMQ();
416  } catch (MQException e1) {
417  for (PropertiesClass oList : arList) {
418 
419  sMsg = "MQException with Queue: Unable to connect to WMQ. Check your configuration and try again "
420  + e1.toString()
421  + " Host: ["
422  + oList.getHostName()
423  + "] Port: ["
424  + oList.getPortNum() + "]";
425  }
426  if (e1.getMessage().contains(sHold)) {
427  setFonts(true, sMsg);
428 
429  } else {
430  String strMsg = "MQException with Queue "
431  + e1.getMessage();
432  setFonts(true, strMsg);
433 
434  }
435 
436  }
437  }
438  }
439 
440  });
441  }
442  return jBtnCheckMessages;
443  }
444 
450  private JCheckBox getJChkDuelQueues() {
451  if (jChkDuelQueues == null) {
452  jChkDuelQueues = new JCheckBox();
453  jChkDuelQueues.setBounds(new Rectangle(295, 57, 241, 21)); // Generated
454  jChkDuelQueues.setText("Listen Queue same as Send Queue"); // Generated
456  .setToolTipText("Check to duplicate Send Queue to Listen Queue"); // Generated
457  jChkDuelQueues.setMnemonic(KeyEvent.VK_Q); // Generated
459  .addActionListener(new java.awt.event.ActionListener() {
460  public void actionPerformed(java.awt.event.ActionEvent e) {
461  if (jChkDuelQueues.isSelected()) {
463  .getText());
464  textReplyQueueName.setEnabled(false);
465 
466  } else {
467  textReplyQueueName.setEnabled(true);
468  textReplyQueueName.setText(null);
469  textReplyQueueName.requestFocus();
470  }
471  }
472  });
473  }
474  return jChkDuelQueues;
475  }
476 
482  private JCheckBox getJChkQueueManager() {
483  if (jChkQueueManager == null) {
484  jChkQueueManager = new JCheckBox();
485  jChkQueueManager.setBounds(new Rectangle(299, 148, 237, 27)); // Generated
487  .setToolTipText("Check if you want to use the same Queue name as Request Queue"); // Generated
488  jChkQueueManager.setText("Use Request Queue Name"); // Generated
490  .addActionListener(new java.awt.event.ActionListener() {
491  public void actionPerformed(java.awt.event.ActionEvent e) {
492  if (jChkQueueManager.isSelected()) {
494  .setText(textRequestQManagerName
495  .getText());
496  textReplyQManager.setEnabled(false);
497  } else {
498  textReplyQManager.setText(null);
499  textReplyQManager.setEnabled(true);
500  textReplyQManager.requestFocus();
501  }
502  }
503  });
504  }
505  return jChkQueueManager;
506  }
507 
513  private JButton getJBtnClearResults() {
514  if (jBtnClearResults == null) {
515  jBtnClearResults = new JButton();
516  jBtnClearResults.setBounds(new Rectangle(662, 777, 163, 24)); // Generated
517  jBtnClearResults.setText("Clear Results"); // Generated
518  jBtnClearResults.setToolTipText("Click to clear the results pane"); // Generated
519  jBtnClearResults.setMnemonic(KeyEvent.VK_L); // Generated
521  .addActionListener(new java.awt.event.ActionListener() {
522  public void actionPerformed(java.awt.event.ActionEvent e) {
523  textAreaResults.setText("");
524  }
525  });
526  }
527  return jBtnClearResults;
528  }
529 
535  private JScrollPane getJScrollPane() {
536  if (jScrollPane == null) {
537  jScrollPane = new JScrollPane();
538  jScrollPane.setBounds(new Rectangle(16, 228, 1125, 284)); // Generated
539  jScrollPane.setViewportView(getTextAreaMessage()); // Generated
540 
541  }
542  return jScrollPane;
543  }
544 
550  private JTextArea getTextAreaMessage() {
551  if (textAreaMessage == null) {
552  textAreaMessage = new JTextArea();
553  textAreaMessage.addKeyListener(new java.awt.event.KeyAdapter() {
554  public void keyTyped(java.awt.event.KeyEvent e) {
556  .setEnabled(textAreaMessage.getText().length() > 0);
557  }
558  });
559  }
560  return textAreaMessage;
561  }
562 
566  public static void main(String[] args) {
567  // TODO Auto-generated method stub
568  SwingUtilities.invokeLater(new Runnable() {
569  public void run() {
570  FRMMain thisClass = new FRMMain();
571  thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
572  thisClass.setVisible(true);
573  }
574  });
575 
576  }
577 
581  public FRMMain() {
582  super();
583  initialize();
585  // My Test Case
586  testDavid();
587 
588  }
589 
595  private void initialize() {
596  this.setSize(1182, 866);
597  this.setIconImage(Toolkit.getDefaultToolkit().getImage(
598  getClass().getResource(
599  "/com/ca/on/burlington/base/images/office5_32.png"))); // Generated
600  this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Generated
601  this.setContentPane(getJContentPane());
602  this.setTitle("WebSphere MQ Messenger");
603  this.setLocationRelativeTo(null);
604 
605  }
606 
612  private JPanel getJContentPane() {
613  if (jContentPane == null) {
614  jLabel112 = new JLabel();
615  jLabel112.setBounds(new Rectangle(12, 530, 1127, 19)); // Generated
616  jLabel112.setText("Results back from Websphere MQ"); // Generated
617  jLabel112.setToolTipText(""); // Generated
618  jLabel111 = new JLabel();
619  jLabel111.setText("Enter Request QManager Name:"); // Generated
620  jLabel111.setBounds(new Rectangle(12, 106, 222, 16)); // Generated
621  jLabel111
622  .setToolTipText("Enter the name of the QManage to connect to"); // Generated
623  jLabel11 = new JLabel();
624  jLabel11.setText("Enter the Queue Name to send the message"); // Generated
625  jLabel11.setBounds(new Rectangle(5, 5, 506, 16)); // Generated
626  jLabel11.setToolTipText(""); // Generated
627  jContentPane = new JPanel();
628  jContentPane.setLayout(null);
629  jContentPane.add(getTextAreaResults(), null); // Generated
630  jContentPane.add(jLabel112, null); // Generated
631  jContentPane.add(getPanel(), null); // Generated
632  jContentPane.add(getPanel1(), null); // Generated
633  jContentPane.add(getJButtonSend(), null); // Generated
634  jContentPane.add(getJBtnExit(), null); // Generated
635  jContentPane.add(getJBtnCheckMessages(), null); // Generated
636  jContentPane.add(getJBtnClearResults(), null); // Generated
637  jContentPane.add(getJScrollPane(), null);
638  }
639  return jContentPane;
640  }
641 
642  /***
643  * Initialize Variables and set arrayList of PropertiesClass
644  */
645  @SuppressWarnings("unchecked")
646  public void init() {
647  PropertiesClass list = new PropertiesClass();
648  arList.clear();
649  // Set up MQSeries environment
650  list.setHostName(this.textFieldHostName.getText());
651  list.setChannelName(this.textFieldChannleName.getText());
653  list.setReplyQueueName(textReplyQueueName.getText());
654  list.setReplyQManager(textReplyQManager.getText());
656  list.setPortNum(Integer.parseInt(textFieldPort.getText()));
657  arList.add(list);
658  for (PropertiesClass oList : arList) {
659  MQEnvironment.hostname = oList.getHostName();
660  MQEnvironment.channel = oList.getChannelName();
661  MQEnvironment.port = oList.getPortNum();
662  MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,
663  MQC.TRANSPORT_MQSERIES);
664 
665  }
666 
667  } // end of init
668 
672  public void processRequest() {
673  String sRequestManager = null;
674  String sRequestQueue = null;
675 
676  for (PropertiesClass oList : arList) {
677  sRequestManager = oList.getRequestQManager();
678  sRequestQueue = oList.getRequestQueueName();
679  }
680  try {
681  // Create a connection to the queue manager
682  requestQMgr = new MQQueueManager(sRequestManager);
683 
684  // Set options
685  int iOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
686 
687  // Open queue and set options
688  requestQueue = requestQMgr.accessQueue(sRequestQueue, iOptions,
689  null, null, null);
690  // Build Message
691  MQMessage send_msg = new MQMessage();
692  // Get the message from the jTextArea
693  send_msg.writeUTF(textAreaMessage.getText().trim());
694  // Set the options
695  MQPutMessageOptions pmo = new MQPutMessageOptions();
696  // put the message on the queue
697  requestQueue.put(send_msg, pmo);
698  // Close the Queue
699  requestQueue.close();
700  // Disconnect from the queue manager
701  requestQMgr.disconnect();
702  setFonts(false, "Message has been placed on the Queue "
703  + sRequestQueue + " With Message of: "
704  + textAreaMessage.getText());
705 
706  } catch (MQException ex) {
707  // MQ Error
708  System.out.println("An MQSeries error occurred : Completion code "
709  + ex.completionCode + " Reason code " + ex.reasonCode);
710  setFonts(true, "An MQException error: Completion code "
711  + ex.completionCode + " Reason code " + ex.reasonCode);
712 
713  }
714  // Buffer Error?
715  catch (java.io.IOException ex) {
716  System.out
717  .println("An error occurred while writing to the message buffer: "
718  + ex);
719  setFonts(true,
720  "An error occurred while writing to the message buffer: "
721  + ex);
722  }
723 
724  } // end of start
725 
726  /***
727  * Check to ensure all required Textboxes values are set
728  *
729  * @return Return true or false
730  */
731  private boolean checkInputs(boolean blnSendMessage) {
732  boolean blnCheck = true;
733  // Required for Send and receive
734  if (this.textFieldHostName.getText().length() == 0) {
735  blnCheck = false;
736  sendUserMessage("Please enter a Host Name to send to?",
737  "Enter a Host Name");
738  this.textFieldHostName.requestFocus();
739  return blnCheck;
740  }
741  // Required for Send and Receive
742  if (this.textFieldChannleName.getText().length() == 0) {
743  blnCheck = false;
744  sendUserMessage("Please enter a Channel Name to send to?",
745  "Enter a Channel Name");
746  this.textFieldChannleName.requestFocus();
747  return blnCheck;
748  }
749  // Only required for Sending
750  if (blnSendMessage) {
751  if (this.textRequestQueueName.getText().length() == 0) {
752  blnCheck = false;
754  "Please enter a Request Queue Name to send to?",
755  "Enter Post to Queue Name");
756  this.textRequestQueueName.requestFocus();
757  return blnCheck;
758  }
759  }
760 
761  // Required for Checking only
762  if (blnSendMessage == false) {
763  if (this.textReplyQueueName.getText().length() == 0) {
764  blnCheck = false;
766  "Please enter a Reply Queue Name to listen to?",
767  "Enter a listen queue Name");
768  this.textReplyQueueName.requestFocus();
769  return blnCheck;
770  }
771  }
772  // Only required for Checking messages
773  if (blnSendMessage == false) {
774  if (this.textReplyQManager.getText().length() == 0) {
775  blnCheck = false;
776  this.textReplyQManager.requestFocus();
777  sendUserMessage("Please enter Reply Queue Manager?",
778  "Reply Queue Manager");
779  return blnCheck;
780  }
781  }
782  // Only required for Sending messages
783  if (blnSendMessage) {
784  if (this.textAreaMessage.getText().length() == 0) {
785  blnCheck = false;
786  sendUserMessage("Please enter a message to send?",
787  "Enter a Message to send");
788  this.textAreaMessage.requestFocus();
789  return blnCheck;
790  }
791  }
792 
793  return blnCheck;
794  }
795 
796  /***
797  * Exit Application and confirm
798  */
799  private void exitApplication() {
800 
801  if (JOptionPane.showConfirmDialog(null,
802  "Are you sure you want to Exit?", "Verify Exit Request",
803  JOptionPane.OK_CANCEL_OPTION) == 0) {
804  System.exit(0);
805  }
806  }
807 
808  /***
809  * Send single JOptionPane with OK button only
810  *
811  * @param sText
812  * @param sTitle
813  */
814  private void sendUserMessage(String sText, String sTitle) {
815  JOptionPane.showMessageDialog(null, sText, sTitle,
816  JOptionPane.OK_OPTION);
817  }
818 
819  /***
820  * Read WebSphere MQueue
821  *
822  * @throws MQException
823  */
824  public void readMQ() throws MQException {
825  String sReplyManager = null;
826  String sReplyQueueName = null;
827  int iPort = 0;
828  for (PropertiesClass oList : arList) {
829  sReplyManager = oList.getReplyQManager();
830  sReplyQueueName = oList.getReplyQueueName();
831  iPort = oList.getPortNum();
832  }
833  // See this link for more information:
834  // http://middleware.its.state.nc.us/middleware/Documentation/en_US/htm/csqzaw09/csqzaw092c.htm
835  int iOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING
836  + MQC.MQOO_INPUT_SHARED;
837  // Create MQ Queue Manager
838  replyQMgr = new MQQueueManager(sReplyManager);
839  // Setup Queue to look in and pass options
840  replyQueue = replyQMgr.accessQueue(sReplyQueueName, iOptions, null,
841  null, null);
842 
843  // Get the depth of the queue
844  int iDepth = replyQueue.getCurrentDepth();
845  System.out.println("Current depth: [" + iDepth + "]");
846  // Here we check to see if there are any messages in the Queue
847  if (iDepth == 0) {
848  // Not a big deal no messages to look at
849  setFonts(false, "No messages located in Queue - Current depth: ["
850  + iDepth + "] On port: [" + iPort + "]");
851  return;
852  }
853  // Only get here if we have messages in Queue
854  MQGetMessageOptions getOptions = new MQGetMessageOptions();
855  // Set the Get message options
856  getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING
857  + MQC.MQGMO_CONVERT;
858  // Loop thru if there are multiple messages
859  while (true) {
860  // Create new MQMessage
861  MQMessage replyMsg = new MQMessage();
862  try {
863  // Get the message from Queue
864  replyQueue.get(replyMsg, getOptions);
865  String msgText = "";
866  // Read message and format for UTF8
867  // readUTF() will sometimes return an error when using WebSphere
868  // Explorer to publish a test message
869  byte[] bByte = new byte[replyMsg.getMessageLength()];
870  replyMsg.readFully(bByte);
871  msgText = (new String(bByte)).trim();
872 
873  // Populate Results to TextArea
874  setFonts(false, "Message Returned from Queue: [" + msgText
875  + "]");
876  System.out.println("The message is: " + msgText);
877  // Clear the messages
878  replyMsg.clearMessage();
879  } catch (IOException e) {
880  System.out.println("IOException: during Read: " + e.toString());
881 
882  setFonts(true, "An IOException error while reading Queue: "
883  + e.toString());
884 
885  break;
886  } catch (MQException e) {
887  // Check if this is just telling us there are no messages left
888  // in the Queue
889  // Thanks to Google Search for this fix
890  if (e.completionCode == 2
891  && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
892  if (iDepth > 0) {
893  System.out.println("All messages read.");
894  setFonts(false, "All messages in Queue ["
895  + sReplyQueueName + "] have been read");
896  }
897  } else {
898  System.out.println("MQException: " + e);
899 
900  setFonts(true, "MQException with Queue [" + sReplyQueueName
901  + "]");
902 
903  }
904  break;
905  }
906  }
907  // Clean up Queue
908  replyQueue.close();
909  replyQMgr.disconnect();
910  }
911 
912  /***
913  * Set Font for TextArea to Red for Erros or Black for regular
914  *
915  * @param errFont
916  * @param strMsg
917  */
918  private void setFonts(boolean errFont, String strMsg) {
919 
920  if (errFont) {
921  textAreaResults.setFont(errorFont);
922  textAreaResults.setForeground(Color.RED);
923  textAreaResults.append(strMsg + "\n");
924  } else {
925 
926  textAreaResults.setFont(regularFont);
927  textAreaResults.setForeground(Color.BLACK);
928  textAreaResults.append(strMsg + "\n");
929  }
930  }
931 
932  /***
933  * Send JoptionPane for Yes or No responses
934  *
935  * @param sMsg
936  * @param sTitle
937  */
938  private void sendYesNoDialog(StringBuffer sMsg, String sTitle) {
939  int response = JOptionPane.showConfirmDialog(null, sMsg.toString()
940  + "\nDo you want to continue?", sTitle,
941  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
942  if (response == JOptionPane.NO_OPTION) {
943  return;
944  } else if (response == JOptionPane.YES_OPTION) {
945  processRequest();
946  } else if (response == JOptionPane.CLOSED_OPTION) {
947  System.out.println("JOptionPane closed");
948  return;
949  }
950  }
951 
952  /***
953  * Test setup for me
954  * */
955  private void testDavid() {
956  textFieldChannleName.setText("SERVERCHANNEL");
957  textRequestQManagerName.setText("REQUESTQUEUEMAN");
958  textReplyQManager.setText("REQUESTQUEUEMAN");
959  textRequestQueueName.setText(textRequestQueueName.getText());
960  textRequestQueueName.setText("ESB_DWC_REQ.IN");
961  textReplyQueueName.setText("ESB_DWC_REQ.OUT");
962  scrollbar.setValue(1420);
963  textFieldPort.setText("1420");
964 
965 
966  }
967  public boolean getWIconVisible() {
968  return wIcon.isVisible();
969  }
970  public void setWIconVisible(boolean visible) {
971  wIcon.setVisible(visible);
972  }
973 } // @jve:decl-index=0:visual-constraint="10,10"

Check Out David's Web Site http://www.welford-costelloe.org

GNU Free Software: http://www.gnu.org/philosophy/free-sw.html