/*Created by Sunil K Abraham ()
This program accepts the queue details and takes the data from the specified location and puts the message into the queue*/
import javax.swing.*;
import java.awt.GridLayout;
import com.ibm.mq.*;
import java.io.*;
public class postMQmsg {
public static void main(String[] args) {
int countOfLines = 0;
JPanel panel = new JPanel(new GridLayout(6, 0, 0, 0));
JTextField field1 = new JTextField("WS95DEUE.OPR.TEST.cc");
JTextField field2 = new JTextField("cc.SVRC");
JTextField field3 = new JTextField("1414");
JTextField field4 = new JTextField("WS95dewxDEUE");
JTextField field5 = new JTextField("A1070.00.asdad");
JTextField field6 = new JTextField(
"C:\\AllShare\\DSS_Data_Generator\\Workings\\CA_Oct3\\GeneratedData1.txt");
panel.add(new JLabel("Host Name:"));
panel.add(field1);
panel.add(new JLabel("Channel Name:"));
panel.add(field2);
panel.add(new JLabel("Port:"));
panel.add(field3);
panel.add(new JLabel("Queue Manager:"));
panel.add(field4);
panel.add(new JLabel("Queue:"));
panel.add(field5);
panel.add(new JLabel("Data File:"));
panel.add(field6);
String hostName, ChanelName, Port, queueMgr, queue, dataFile;
hostName = field1.getText();
ChanelName = field2.getText();
Port = field3.getText();
queueMgr = field4.getText();
queue = field5.getText();
dataFile = field6.getText();
int option = JOptionPane.showConfirmDialog(null, panel,
"MQ message posting - by TLQE", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE);
if (option == JOptionPane.OK_OPTION) {
hostName = field1.getText();
ChanelName = field2.getText();
Port = field3.getText();
queueMgr = field4.getText();
queue = field5.getText();
dataFile = field6.getText();
/* System.out.println("hostName: " + hostName + "\n ChanelName: "
+ ChanelName + "\n Port: " + Port + "\n queueMgr: "
+ queueMgr + "\n queue: " + queue + "\n dataFile: "
+ dataFile);*/
MQQueueManager QueueManager = null;
MQPutMessageOptions PutMsgOptions;
MQQueue QueueName = null;
String sFilename = dataFile;
int PortInt;
PortInt = Integer.parseInt(Port);
MQEnvironment.hostname = hostName;
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
MQEnvironment.channel = ChanelName;
MQEnvironment.port = PortInt;
int openOptions = MQC.MQOO_OUTPUT;
try {
QueueManager = new MQQueueManager(queueMgr);
} catch (MQException e) {
e.printStackTrace();
JPanel panelQM = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelQM, "Queue Manager is incorrect", "TLQE - Warning", JOptionPane.WARNING_MESSAGE);
}
try {
QueueName = QueueManager.accessQueue(queue, openOptions, null,
null, null);
} catch (MQException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
JPanel panelQN = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelQN, "Queue Name is incorrect", "TLQE - Warning", JOptionPane.WARNING_MESSAGE);
}
PutMsgOptions = new MQPutMessageOptions();
PutMsgOptions.options = MQC.MQPMO_DEFAULT_CONTEXT;
try {
FileInputStream fstream = new FileInputStream(sFilename);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(
new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
if (strLine.length() > 10) {
MQMessage myPutMessage = new MQMessage();
myPutMessage.clearMessage();
myPutMessage.persistence = MQC.MQPER_PERSISTENT;
myPutMessage.format = MQC.MQFMT_STRING;
myPutMessage.correlationId = MQC.MQCI_NONE;
myPutMessage.messageId = MQC.MQMI_NONE;
//System.out.println(strLine);
myPutMessage.writeString(strLine);
QueueName.put(myPutMessage, PutMsgOptions);
countOfLines++;
}
}
JPanel panel1 = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panel1, countOfLines
+ " messages posted to " + queue + " queue", "TLQE",
JOptionPane.INFORMATION_MESSAGE);
in.close();
br.close();
try {
QueueName.close();
QueueManager.disconnect();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
JPanel panelFNF = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelFNF, "Input Data File not Found", "TLQE - Warning", JOptionPane.WARNING_MESSAGE);
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
JPanel panelIOE = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelIOE, "I/O Exception", "TLQE - Warning", JOptionPane.WARNING_MESSAGE);
e.printStackTrace();
} catch (MQException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JPanel panelMQExp = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelMQExp, "Queue details are incorrect", "TLQE - Warning", JOptionPane.WARNING_MESSAGE);
}
}
if (option == JOptionPane.CANCEL_OPTION) {
JPanel panelCancel = new JPanel(new GridLayout(1, 0));
JOptionPane.showMessageDialog(panelCancel, "Bye Bye", "TLQE", JOptionPane.INFORMATION_MESSAGE);
}
}
}
No comments:
Post a Comment