2001-07-12 11:57:24 +02:00
|
|
|
// $RCSfile: MQSLoad.java,v $
|
2002-04-15 12:46:14 +02:00
|
|
|
// $Revision: 1.2 $
|
2001-07-12 11:57:24 +02:00
|
|
|
// $Name: $
|
2002-04-15 12:46:14 +02:00
|
|
|
// $Date: 2002/04/15 10:46:14 $
|
2001-07-12 11:57:24 +02:00
|
|
|
// $Author: giberta1 $
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 07/12/2001 - 11:45:14
|
|
|
|
*
|
|
|
|
* MQSLoad.java - MQ/Seires data file to queue loader
|
|
|
|
* Copyright (C) 2001 Arnaud G. Gibert
|
|
|
|
* arnaud.gibert@midas-kapiti.fr
|
|
|
|
* www.midas-kapiti.fr
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import com.ibm.mq.*;
|
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class MQSLoad
|
|
|
|
{
|
|
|
|
private MQQueueManager QMng;
|
|
|
|
private String QMng_Name = "";
|
|
|
|
private MQQueue MsgQ;
|
|
|
|
private String MsgQ_Name;
|
|
|
|
private int MsgQ_Open_Options = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING;
|
|
|
|
private String File_Name;
|
|
|
|
|
|
|
|
|
|
|
|
public static void main( String args[])
|
|
|
|
{
|
|
|
|
new MQSLoad( args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
private void MQSInit() throws Exception
|
2001-07-12 11:57:24 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
QMng = new MQQueueManager( QMng_Name);
|
|
|
|
System.out.println( "QManager Open: (" + QMng + ") !");
|
|
|
|
}
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
throw Expt;
|
2001-07-12 11:57:24 +02:00
|
|
|
}
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
try
|
2001-07-12 11:57:24 +02:00
|
|
|
{
|
2002-04-15 12:46:14 +02:00
|
|
|
MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null);
|
|
|
|
System.out.println( "MsgQ Open: (" + MsgQ + ") !");
|
2001-07-12 11:57:24 +02:00
|
|
|
}
|
2002-04-15 12:46:14 +02:00
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
QMng.disconnect();
|
|
|
|
System.out.println( "QManager Close: (" + QMng + ") !");
|
|
|
|
|
|
|
|
throw Expt;
|
|
|
|
}
|
2001-07-12 11:57:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
private void MQSDeInit() throws Exception
|
2001-07-12 11:57:24 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MsgQ.close();
|
|
|
|
System.out.println( "MsgQ Close: (" + MsgQ + ") !");
|
|
|
|
QMng.disconnect();
|
|
|
|
System.out.println( "QManager Close: (" + QMng + ") !");
|
|
|
|
}
|
2002-04-15 12:46:14 +02:00
|
|
|
|
|
|
|
catch( Exception Expt)
|
2001-07-12 11:57:24 +02:00
|
|
|
{
|
2002-04-15 12:46:14 +02:00
|
|
|
throw Expt;
|
2001-07-12 11:57:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
private void MQSPut_Msg( MQMessage Msg) throws Exception
|
2001-07-12 11:57:24 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
MQPutMessageOptions pmo = new MQPutMessageOptions();
|
|
|
|
MsgQ.put( Msg, pmo);
|
|
|
|
}
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
catch( Exception Expt)
|
2001-07-12 11:57:24 +02:00
|
|
|
{
|
2002-04-15 12:46:14 +02:00
|
|
|
throw Expt;
|
2001-07-12 11:57:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MQSLoad( String args[])
|
|
|
|
{
|
2002-04-15 12:46:14 +02:00
|
|
|
byte input_char;
|
|
|
|
int msg_nb = 0;
|
|
|
|
MQMessage output_msg = new MQMessage();
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2001-07-12 11:57:24 +02:00
|
|
|
if( args.length != 2)
|
|
|
|
{
|
|
|
|
System.out.println( "Usage: MQSLoad <Output_MsgQueue_Name> <Input_File_Name>");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
System.out.println( "MQS Load Starting...");
|
|
|
|
|
|
|
|
MsgQ_Name = args[0];
|
|
|
|
File_Name = args[1];
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
System.out.println( "Output MsgQueue Name: (" + MsgQ_Name + ") Input File Name: (" + File_Name + ")");
|
2001-07-12 11:57:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
MQSInit();
|
|
|
|
|
2002-04-15 12:46:14 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
output_msg.format = MQC.MQFMT_STRING;
|
|
|
|
|
|
|
|
BufferedInputStream input_file = new BufferedInputStream( new FileInputStream(File_Name));
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
System.out.println("Input File Open: (" + input_file + ") !");
|
|
|
|
|
|
|
|
while( ( input_char = (byte)input_file.read()) != -1)
|
|
|
|
{
|
|
|
|
switch( input_char)
|
|
|
|
{
|
|
|
|
case '\r':
|
|
|
|
case ';':
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
{
|
|
|
|
System.out.println( "Sending Msg Nb (" + ++msg_nb + ") !");
|
|
|
|
|
|
|
|
output_msg.messageId = MQC.MQMI_NONE;
|
|
|
|
MQSPut_Msg(output_msg);
|
|
|
|
output_msg.clearMessage();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
output_msg.writeByte( input_char);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
input_file.close();
|
|
|
|
throw Expt;
|
|
|
|
}
|
|
|
|
|
|
|
|
input_file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
|
|
|
MQSDeInit();
|
|
|
|
throw Expt;
|
|
|
|
}
|
2001-07-12 11:57:24 +02:00
|
|
|
|
|
|
|
MQSDeInit();
|
|
|
|
System.out.println( "MQS Load Completed !");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
catch( Exception Expt)
|
|
|
|
{
|
2002-04-15 12:46:14 +02:00
|
|
|
System.out.println("Exception: (" + Expt + ") !");
|
2001-07-12 11:57:24 +02:00
|
|
|
Expt.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|