/*
 * LoadRunner Java script. (Build: 670)
 *
 * ״̬£º²¢·¢²âÊÔͨ¹ý
 * ²âÊÔÈË£ºÕÔС±ò
 * ÈÕÆÚ£º2013-09-25
 * °æ±¾£º
 * ±ä¸ü£º                  
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.IOException;  
import java.io.OutputStream;
import java.util.Hashtable;

import com.ibm.mq.*;

import lrapi.lr;
public class Actions
{

String host = "10.20.101.23";//MQ·þÎñÆ÷IP

int port =11101; //MQ¶ÓÁйÜÀíÆ÷¶Ë¿Ú
  String channel = "TELLER.DEF.SVRCONN";//MQÇþµÀÃû
  String qmname = "MQESBPRO1";//MQ¶ÓÁйÜÀíÆ÷¶Ë¿Ú
  String qnamereq = "LOCALQ.ESB.SECONDHTCSACCTSERVICE_V1.REQ" ;//MQ·¢Ëͱ¨ÎĶÓÁÐÃû

//LOCALQ.ESB.LBEACCTSERVICE_V1.REQ

int port1 = 11101; //MQ¶ÓÁйÜÀíÆ÷¶Ë¿Ú
  String channel1 = "TELLER.DEF.SVRCONN";//MQÇþµÀÃû
  String qmname1 = "MQESBPRO1";//MQ¶ÓÁйÜÀíÆ÷¶Ë¿Ú
  String qnameres = "LOCALQ.AFA.SECONDHTCSACCTSERVICE_V1.RSP" ;//MQ½ÓÊܱ¨ÎĶÓÁÐÃû

int ccsid = 1208;
                                 //The configuration for queueManager is required!!!  REMOTEQ.ESB.BK1.LBEACCTSERVICE_V1.RSP

MQQueueManager qm ;//ÉùÃ÷¶ÓÁйÜÀíÆ÷ 
  MQQueue qreq;//ÉùÃ÷¶ÓÁР -·¢ËÍ
  MQQueue qres;//ÉùÃ÷¶ÓÁР -½ÓÊÕ

MQPutMessageOptions pmo;//PutÏûÏ¢ÉèÖöÔÏó
    
 MQGetMessageOptions gmo;//GetÏûÏ¢ÉèÖöÔÏó

//¶ÓÁÐÊôÐÔ
  int sendOption= MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
  int resOption=MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;

byte[] content;//´æ·Å ±¨ÎÄ

Hashtable<String,Object> props = new Hashtable<String,Object>(); 
  
 public int init() throws Exception {
     try
  {

props.put(MQC.HOST_NAME_PROPERTY, host);
  props.put(MQC.PORT_PROPERTY, new Integer(port));
  props.put(MQC.CHANNEL_PROPERTY, channel);
  props.put(MQC.CCSID_PROPERTY, new Integer(ccsid));

//³õʼ»¯¶ÓÁйÜÀíÆ÷AFA
  qm = new MQQueueManager(qmname, props); 
         //System.out.println("==========>³õʹ»¯¶ÓÁйÜÀíÆ÷OK");  
                            
  //³õʼ»¯ ·¢ËͶÓÁÐ
         qreq = qm.accessQueue(qnamereq, sendOption);
                //  System.out.println("==========>³õʹ·¢ËͶÓÁÐOK");

// pmo ÏûϢдÈë ¹æÔò
  pmo = new MQPutMessageOptions();

//³õʼ»¯ ½ÓÊÕ¶ÓÁÐ
  qres = qm.accessQueue(qnameres, resOption);

// pmo ÏûÏ¢¶ÁÈ¡ ¹æÔò
  gmo = new MQGetMessageOptions();
  gmo.waitInterval = 10*1000;
  gmo.options = MQC.MQGMO_WAIT;

//ÒÔÉÏ£¬³õʼ»¯ ¶ÓÁйÜÀíÆ÷¶ÔÏ󣬷¢ËͶÓÁУ¬½ÓÊÕ¶ÓÁС£
  }catch (MQException e) {   
      System.out.println("==========>³õʹ»¯MQ³ö´í");  
      e.printStackTrace();
      return -1;
  }

System.out.println("==========>³õʹ»¯MQ³É¹¦");
      return 0;

}//end of init

/** 
  * action·½·¨
  * ·¢ËÍÏûÏ¢
  * ½ÓÊÕÏûÏ¢
         */
 public int action() throws Exception {

content = ("<?xml version=\'1.0\' encoding=\'UTF-8\'?> <soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">  <soapenv:Body>   <ns3:ptEnterCacount xmlns:ns3=\"http://esb.srcb.com/SecondHTCSAcctService/v1\" xmlns:ns2=\"http://esb.srcb.com/SecondHTCSAcctService/schema/v1\">    <requestHeader xmlns=\"http://esb.srcb.com\">     <version>1.00</version>     <serialNo>011060014082931299550003693870000000</serialNo>     <refSerialNo></refSerialNo>     <requestId>TELLER</requestId>     <requestTime></requestTime>     <timeOutTime></timeOutTime>     <channelId>TELLER</channelId>     <channelSerialNo>011060014082931299550003693870000000</channelSerialNo>    </requestHeader>    <ns2:accountAlterServiceRequest>     <ns2:M_CustomerNo>IFES</ns2:M_CustomerNo>     <ns2:M_PackageType>XML</ns2:M_PackageType>     <ns2:M_ServicerNo>UPBS</ns2:M_ServicerNo>     <ns2:M_ServiceCode>upbs.htcs.t007.01</ns2:M_ServiceCode>     <ns2:M_MesgSndDate>20140829</ns2:M_MesgSndDate>     <ns2:M_MesgSndTime>134249</ns2:M_MesgSndTime>     <ns2:M_MesgId>1408293129955000102014-08-29 13:42:49.092</ns2:M_MesgId>     <ns2:M_MesgRefId>137002</ns2:M_MesgRefId>     <ns2:M_Direction>1</ns2:M_Direction>     <ns2:M_CallMethod>1</ns2:M_CallMethod>     <ns2:M_Reserve>3129961</ns2:M_Reserve>     <ns2:brno>31299</ns2:brno>     <ns2:tellerNo>3129955</ns2:tellerNo>     <ns2:templateCode>BPUB</ns2:templateCode>     <ns2:tradeCode>UPSHNSXML</ns2:tradeCode>     <ns2:terminalNo>161</ns2:terminalNo>     <ns2:channelCode>106</ns2:channelCode>     <ns2:channelDate>20140829</ns2:channelDate>     <ns2:channelTime>134249</ns2:channelTime>     <ns2:channelSerNo>140829312995500010</ns2:channelSerNo>     <ns2:authTellerId></ns2:authTellerId>    </ns2:accountAlterServiceRequest>    <ns2:payChannelCode>05</ns2:payChannelCode>    <ns2:payerAcctName>å±±ä?Üè^ýæº^Ðé^?Æå^Û¢??Éé^?Ðå^Ŭ?ϸ</ns2:payerAcctName>    <ns2:withdrawMethod>2</ns2:withdrawMethod>    <ns2:transPswd></ns2:transPswd>    <ns2:payeeCorpPrivFlag>1</ns2:payeeCorpPrivFlag>    <ns2:payeeAcctNo>8010001033</ns2:payeeAcctNo>    <ns2:payeeAcctName>??Ñç^?Ìå?Öå?Æå.</ns2:payeeAcctName>    <ns2:draftDate>20140828</ns2:draftDate>    <ns2:voucherType>6666</ns2:voucherType>    <ns2:voucherNo>987654</ns2:voucherNo>    <ns2:bizType>A100</ns2:bizType>    <ns2:currCode>CNY</ns2:currCode>    <ns2:transAmt>60000</ns2:transAmt>    <ns2:fee>100</ns2:fee>    <ns2:headNo></ns2:headNo>    <ns2:billType></ns2:billType>    <ns2:authType></ns2:authType>    <ns2:writeOffNum></ns2:writeOffNum>    <ns2:usageRemark></ns2:usageRemark>    <ns2:postscript></ns2:postscript>    <ns2:payeeAcctType></ns2:payeeAcctType>    <ns2:bizKind>2001</ns2:bizKind>    <ns2:origTransSerialNo>0041027519</ns2:origTransSerialNo>    <ns2:recvSettleBankNo>103290032030</ns2:recvSettleBankNo>    <ns2:payerCorpPrivFlag>1</ns2:payerCorpPrivFlag>    <ns2:payerAcctType></ns2:payerAcctType>    <ns2:cardPassbookFlag></ns2:cardPassbookFlag>    <ns2:payerAcctNo>50131000300002639</ns2:payerAcctNo>    <ns2:realPayerAcctNo>50131000300002639</ns2:realPayerAcctNo>    <ns2:realPayerAcctType></ns2:realPayerAcctType>    <ns2:realPayerName>å±±ä?Üè^ýæº^Ðé^?Æå^Û¢??Éé^?Ðå^Ŭ?ϸ</ns2:realPayerName>    <ns2:payerOpenBankNo></ns2:payerOpenBankNo>    <ns2:payeeOpenBankNo>103290032030</ns2:payeeOpenBankNo>    <ns2:chargeFlag>1</ns2:chargeFlag>    <ns2:feeInfo></ns2:feeInfo>    <ns2:remark></ns2:remark>    <ns2:remark1></ns2:remark1>    <ns2:remark2></ns2:remark2>    <ns2:remark3></ns2:remark3>    <ns2:remark4></ns2:remark4>    <ns2:remark5></ns2:remark5>   </ns3:ptEnterCacount>  </soapenv:Body> </soapenv:Envelope> ").getBytes("UTF-8");

try {
  //³õʼ»¯msg ¶ÔÏó
  MQMessage reqMsg = new MQMessage();

//µ÷ÓÃMsg¶ÔÏóµÄ write·½·¨ дÈë ±¨ÎÄcontent
  reqMsg.write(content);
  //System.out.println("================>·¢Ë͵ı¨ÎÄÊÇ"+new String(content, "UTF-8"));

//System.out.println("==========>±¾ÐéÄâÓû§¡¾"+"<count>"+"¡¿±Ê½»Ò׿ªÊ¼");

//lr½»Ò׿ªÊ¼ Åж¨
  
 //lr.rendezvous("Íù_Ö§¸¶Ã÷ϸ²éѯ");

//pmo.resolvedQueueName ="LOCALQ.AFA.SECONDBEPSCREDICSERVICE_V1.RSP";
  //pmo.resolvedQueueManagerName = "MQESBPRO1";
  //
  reqMsg.replyToQueueName = "LOCALQ.AFA.SECONDHTCSACCTSERVICE_V1.RSP";//·¢Ëͱ¨Îĵķµ»Ø¶ÓÁÐÃû
  reqMsg.replyToQueueManagerName = "MQESBPRO1";//·¢Ëͱ¨Îĵķµ»Ø¶ÓÁйÜÀíÆ÷Ãû

lr.start_transaction("´û¼ÇÍùÕËÆÕͨ¼Èë");

//¸ù¾Ýpmo¹æÔò £¬Ïò¡°·¢ËͶÓÁÐqreqÖзÅÖà ÏûÏ¢
   qreq.put(reqMsg, pmo);

//´òÓ¡msgid
//   System.out.print("==========>PutMsgId£º[");
//   for (int i = 0; i < reqMsg.messageId.length; i++) {
//      System.out.print(reqMsg.messageId[i]);
//    }
//   System.out.println("]");

//³õʼ»¯½ÓÊÕ msg ¶ÔÏó
  MQMessage resMsg = new MQMessage();

//ÏûϢƥÅä¹æÔò¡£2Ñ¡Ò»£¬Ä¿Ç°¸ù¾ÝmsgidÈ¡ÏûÏ¢
  //resMsg.correlationId = reqMsg.correlationId;
 // resMsg.messageId = reqMsg.messageId;

//¹æ¾Øgmo¹æÔò£¬È¡ÏûÏ¢
  qres.get(resMsg, gmo);

//´òÓ¡msgid
//   System.out.print("==========>GetMsgId£º[");
//   for (int i = 0; i < reqMsg.messageId.length; i++) {
//      System.out.print(reqMsg.messageId[i]);
//    }
//   System.out.println("]");

byte[] msgContent = new byte[resMsg.getMessageLength()];
  resMsg.readFully(msgContent);

//qm.commit();//ÌáʾÏûÏ¢ÒÑÈ¡×ß

if (0<=new String(msgContent, "UTF-8").indexOf("000000") ) {
   //Åжϱ¾´Î½»Ò׳ɹ¦£¨Ö¸³É¹¦·¢ËÍÏûÏ¢£¬²¢Êܵ½·µ»Ø£©
   lr.end_transaction("´û¼ÇÍùÕËÆÕͨ¼Èë", lr.PASS);
                        //System.out.println(new String(msgContent, "UTF-8").indexOf("²éѯ³É¹¦"));
   //lr.error_message(new String(msgContent, "UTF-8"));

}
      else {
                             lr.end_transaction("´û¼ÇÍùÕËÆÕͨ¼Èë", lr.FAIL);
        lr.error_message("==========>ÔËÐнá¹û·Ç³É¹¦"+new String(msgContent, "UTF-8").indexOf("000000")+"\n       ==========>½ÓÊյı¨ÎÄÐÅÏ¢ÈçÏÂ\n"+new String(msgContent, "UTF-8"));

}

} catch(MQException ex){
                   System.out.println("An error occurred during the put operation:" +"CC = " + ex.completionCode +"RC = " + ex.reasonCode);
                   System.out.println("Cause exception:" + ex.getCause());
                   lr.end_transaction("´û¼ÇÍùÕËÆÕͨ¼Èë", lr.FAIL);//Òì³£Çé¿ö£¬Åж¨ ±¾´Î½»Ò×ʧ°Ü
     lr.error_message("½ÓÊÕÏûÏ¢³¬Ê±"+"==========>service sn:"+"9<Random_9_001><Random_9_002>"+"==========>service time:"+"<time>");
     return 0;

}
    catch (java.io.IOException ex){
      System.out.println("An error occurred whilst writing to the message buffer: " + ex);
  }
           catch(Exception ex){  
      ex.printStackTrace();  
  }

return 0;
 }//end of action

public int end() throws Exception {

try { 
   qreq.close();
   qres.close();
   qm.disconnect();
   qm.close();

}catch (MQException e){  
   e.printStackTrace();  
      }
  return 0;
 }//end of end
}

05-06 03:30