18 package com.ca.on.burlington.base.forms;
20 import java.awt.Color;
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;
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;
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;
99 private Font
errorFont =
new Font(
"Verdana", Font.ITALIC, 12);
106 private List<PropertiesClass>
arList =
new ArrayList<PropertiesClass>();
160 jLabel1112.setBounds(
new Rectangle(13, 154, 172, 17));
161 jLabel1112.setText(
"Enter Reply QManager Name:");
163 .setToolTipText(
"Enter the name of the QManage to connect to");
166 jLabel1111.setBounds(
new Rectangle(10, 117, 159, 21));
169 jLabel1.setBounds(
new Rectangle(12, 63, 151, 17));
170 jLabel1.setText(
"Enter Channel Name:");
173 jLabel.setToolTipText(
"Enter the name of the Host");
174 jLabel.setBounds(
new Rectangle(12, 9, 101, 16));
175 jLabel.setText(
"Enter Host Name:");
177 panel.setLayout(null);
178 panel.setBounds(
new Rectangle(12, 11, 557, 208));
227 jLabel113.setBounds(
new Rectangle(10, 60, 223, 23));
228 jLabel113.setText(
"Enter the Queue Name to Listen to ");
232 panel1.setBounds(
new Rectangle(588, 15, 557, 200));
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);
251 ImageIcon image =
new ImageIcon(
FRMMain.class.getResource(
"/com/ca/on/burlington/base/images/gplv3-127x51.png"));
280 scrollbar.setOrientation(Scrollbar.HORIZONTAL);
282 scrollbar.setBounds(
new Rectangle(19, 143, 165, 39));
285 .addAdjustmentListener(
new java.awt.event.AdjustmentListener() {
286 public void adjustmentValueChanged(
287 java.awt.event.AdjustmentEvent e) {
333 jButtonSend.setBounds(
new Rectangle(18, 770, 123, 32));
336 .setToolTipText(
"Click to send a message to Websphere MQ");
339 jButtonSend.addActionListener(
new java.awt.event.ActionListener() {
340 public void actionPerformed(java.awt.event.ActionEvent e) {
341 StringBuffer sb =
new StringBuffer();
343 System.out.println(
"arLidt : " +
arList.toString());
347 sb.append(
"Host: [" + oList.getHostName() +
"]\n");
349 .append(
"Port Number: [" + oList.getPortNum()
352 .append(
"Channel: [" + oList.getChannelName()
354 sb.append(
"Queue Manager ["
355 + oList.getRequestQManager() +
"]\n");
356 sb.append(
"Queue Name: [" + oList.getRequestQueueName()
379 jBtnExit.setBounds(
new Rectangle(1022, 773, 120, 26));
381 jBtnExit.setToolTipText(
"Click to Exit Application");
382 jBtnExit.setMnemonic(KeyEvent.VK_X);
383 jBtnExit.addActionListener(
new java.awt.event.ActionListener() {
384 public void actionPerformed(java.awt.event.ActionEvent e) {
406 .addActionListener(
new java.awt.event.ActionListener() {
407 public void actionPerformed(java.awt.event.ActionEvent e) {
408 String sHold =
"Socket connection attempt refused";
416 }
catch (MQException e1) {
419 sMsg =
"MQException with Queue: Unable to connect to WMQ. Check your configuration and try again "
422 + oList.getHostName()
424 + oList.getPortNum() +
"]";
426 if (e1.getMessage().contains(sHold)) {
430 String strMsg =
"MQException with Queue "
456 .setToolTipText(
"Check to duplicate Send Queue to Listen Queue");
459 .addActionListener(
new java.awt.event.ActionListener() {
460 public void actionPerformed(java.awt.event.ActionEvent e) {
487 .setToolTipText(
"Check if you want to use the same Queue name as Request Queue");
490 .addActionListener(
new java.awt.event.ActionListener() {
491 public void actionPerformed(java.awt.event.ActionEvent e) {
521 .addActionListener(
new java.awt.event.ActionListener() {
522 public void actionPerformed(java.awt.event.ActionEvent e) {
538 jScrollPane.setBounds(
new Rectangle(16, 228, 1125, 284));
554 public void keyTyped(java.awt.event.KeyEvent e) {
566 public static void main(String[] args) {
568 SwingUtilities.invokeLater(
new Runnable() {
571 thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
572 thisClass.setVisible(
true);
596 this.setSize(1182, 866);
597 this.setIconImage(Toolkit.getDefaultToolkit().getImage(
598 getClass().getResource(
599 "/com/ca/on/burlington/base/images/office5_32.png")));
600 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
602 this.setTitle(
"WebSphere MQ Messenger");
603 this.setLocationRelativeTo(null);
615 jLabel112.setBounds(
new Rectangle(12, 530, 1127, 19));
616 jLabel112.setText(
"Results back from Websphere MQ");
619 jLabel111.setText(
"Enter Request QManager Name:");
620 jLabel111.setBounds(
new Rectangle(12, 106, 222, 16));
622 .setToolTipText(
"Enter the name of the QManage to connect to");
624 jLabel11.setText(
"Enter the Queue Name to send the message");
625 jLabel11.setBounds(
new Rectangle(5, 5, 506, 16));
645 @SuppressWarnings(
"unchecked")
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);
673 String sRequestManager = null;
674 String sRequestQueue = null;
677 sRequestManager = oList.getRequestQManager();
678 sRequestQueue = oList.getRequestQueueName();
685 int iOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
691 MQMessage send_msg =
new MQMessage();
695 MQPutMessageOptions pmo =
new MQPutMessageOptions();
702 setFonts(
false,
"Message has been placed on the Queue "
703 + sRequestQueue +
" With Message of: "
706 }
catch (MQException ex) {
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);
715 catch (java.io.IOException ex) {
717 .println(
"An error occurred while writing to the message buffer: "
720 "An error occurred while writing to the message buffer: "
732 boolean blnCheck =
true;
737 "Enter a Host Name");
745 "Enter a Channel Name");
750 if (blnSendMessage) {
754 "Please enter a Request Queue Name to send to?",
755 "Enter Post to Queue Name");
762 if (blnSendMessage ==
false) {
766 "Please enter a Reply Queue Name to listen to?",
767 "Enter a listen queue Name");
773 if (blnSendMessage ==
false) {
778 "Reply Queue Manager");
783 if (blnSendMessage) {
787 "Enter a Message to send");
801 if (JOptionPane.showConfirmDialog(null,
802 "Are you sure you want to Exit?",
"Verify Exit Request",
803 JOptionPane.OK_CANCEL_OPTION) == 0) {
815 JOptionPane.showMessageDialog(null, sText, sTitle,
816 JOptionPane.OK_OPTION);
824 public void readMQ() throws MQException {
825 String sReplyManager = null;
826 String sReplyQueueName = null;
829 sReplyManager = oList.getReplyQManager();
830 sReplyQueueName = oList.getReplyQueueName();
831 iPort = oList.getPortNum();
835 int iOptions = MQC.MQOO_INQUIRE + MQC.MQOO_FAIL_IF_QUIESCING
836 + MQC.MQOO_INPUT_SHARED;
838 replyQMgr =
new MQQueueManager(sReplyManager);
845 System.out.println(
"Current depth: [" + iDepth +
"]");
849 setFonts(
false,
"No messages located in Queue - Current depth: ["
850 + iDepth +
"] On port: [" + iPort +
"]");
854 MQGetMessageOptions getOptions =
new MQGetMessageOptions();
856 getOptions.options = MQC.MQGMO_NO_WAIT + MQC.MQGMO_FAIL_IF_QUIESCING
861 MQMessage replyMsg =
new MQMessage();
869 byte[] bByte =
new byte[replyMsg.getMessageLength()];
870 replyMsg.readFully(bByte);
871 msgText = (
new String(bByte)).trim();
874 setFonts(
false,
"Message Returned from Queue: [" + msgText
876 System.out.println(
"The message is: " + msgText);
878 replyMsg.clearMessage();
879 }
catch (IOException e) {
880 System.out.println(
"IOException: during Read: " + e.toString());
882 setFonts(
true,
"An IOException error while reading Queue: "
886 }
catch (MQException e) {
890 if (e.completionCode == 2
891 && e.reasonCode == MQException.MQRC_NO_MSG_AVAILABLE) {
893 System.out.println(
"All messages read.");
894 setFonts(
false,
"All messages in Queue ["
895 + sReplyQueueName +
"] have been read");
898 System.out.println(
"MQException: " + e);
900 setFonts(
true,
"MQException with Queue [" + sReplyQueueName
918 private void setFonts(
boolean errFont, String strMsg) {
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) {
944 }
else if (response == JOptionPane.YES_OPTION) {
946 }
else if (response == JOptionPane.CLOSED_OPTION) {
947 System.out.println(
"JOptionPane closed");
968 return wIcon.isVisible();
971 wIcon.setVisible(visible);