import java.io.*;
import java.util.*;
import com.ibm.mq.*;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Session;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Actions
{
private MQQueueManager myQueueManager;
private MQPutMessageOptions myPutMsgOptions;
private MQQueue myQueue;
private String xmlStr = null;
private String finalFileName = null;
private String xmlDocument = null;
private Session session = null;
private MessageProducer producer = null;
private Connection conn = null;
private Message message = null;
private String Formatted_msg = null;
public int init() throws Throwable {
try {
MQEnvironment.hostname = "abcd.com";
MQEnvironment.properties.put(MQC.TRANSPORT_PROPERTY,MQC.TRANSPORT_MQSERIES_CLIENT);
MQEnvironment.channel = "SYSTEM.DEF.SVRCONN";
MQEnvironment.port = 100;
myQueueManager = new MQQueueManager("aa.bb.cc.dd");
int openOptions = MQC.MQOO_OUTPUT | MQC.MQOO_INQUIRE | MQC.MQOO_FAIL_IF_QUIESCING;
myQueue = myQueueManager.accessQueue("DI.DC.WMS.MIF.DISTRIBUTIONORDER", openOptions, null, null, null);
myPutMsgOptions = new MQPutMessageOptions();
myPutMsgOptions.options = MQC.MQPMO_NONE;
} catch (Exception e) {
System.out.println(e);
}
return 0;
}//end of init
public int action() throws Throwable {
try {
MQMessage myPutMessage = new MQMessage();
myPutMessage.clearMessage();
myPutMessage.persistence = MQC.MQPER_PERSISTENT;
myPutMessage.format = MQC.MQFMT_STRING;
FileReader fr = null;
File f=new File("C:\\AdvXMLs\\<pInputXML>.xml");
int fileLength = (int) f.length();
char[] cbuf = new char[fileLength];
try {
fr = new FileReader(f);
fr.read(cbuf);
} catch (FileNotFoundException e) {
lr.error_message("Could not find data file: " + f);
lr.abort();
} catch (IOException e) {
lr.error_message("Error reading file: " + f);
lr.abort();
} finally{
try{
if(fr!=null){
fr.close();
}
}catch(IOException ioe){
lr.error_message("Error closing file reader: " + ioe);
lr.abort();
}
}
new String(cbuf);
String xmlDocument = String.valueOf(cbuf);
System.out.println("Read XML:\n" +xmlDocument);
Pattern pattern1 = Pattern.compile("(<DistributionOrderId>)+(\\d)+(</DistributionOrderId>)");
Pattern pattern2 = Pattern.compile("(<DistroNumber>)+(\\d)+(</DistroNumber>)");
Pattern pattern3 = Pattern.compile("(<ARAcctNbr>)+(\\d)+(</ARAcctNbr>)");
Pattern pattern4 = Pattern.compile("(<PurchaseOrderNbr>)+(\\d)+(</PurchaseOrderNbr>)");
Pattern pattern5 = Pattern.compile("(<AssortmentNbr>)+(\\d)+(</AssortmentNbr>)");
Matcher m1 = pattern1.matcher(xmlDocument);
String str2 = m1.replaceAll("<DistributionOrderId><pOrderId></DistributionOrderId>");
Matcher m2 = pattern2.matcher(str2);
str2 = m2.replaceAll("<DistroNumber><pOrderId></DistroNumber>");
Matcher m3 = pattern3.matcher(str2);
str2 = m3.replaceAll("<ARAcctNbr><pOrderId></ARAcctNbr>");
Matcher m4 = pattern4.matcher(str2);
str2 = m4.replaceAll("<PurchaseOrderNbr><pOrderId></PurchaseOrderNbr>");
Matcher m5 = pattern5.matcher(str2);
str2 = m5.replaceAll("<AssortmentNbr><pAssortmentNo></AssortmentNbr>");
Formatted_msg = str2;
System.out.println("str3:\n" +str2);
lr.start_transaction("Create_DO");
// myQueue.put(myPutMessage, myPutMsgOptions);
} catch (Exception e) {
System.out.println(e);
}
lr.end_transaction("Create_DO", lr.AUTO);
return 0;
}//end of action
public int end() throws Throwable {
try {
myQueue.close();
myQueueManager.disconnect();
} catch (Exception e ) {
System.out.println(e);
}
return 0;
}//end of end
}
No comments:
Post a Comment