1.

Eclipse中调试Java脚本,脚本调试通过后,打成jar包;
2. 新建lr脚本,选择Java vuser协议;
3. Run-time Settings中Classpath设置jar包,没用的jar包一律删除,或不选择,否则会出现错误;然后添加Java脚本所需要的jar包;
4. jar可以放在Java vuser根目录,直接使用;
5. 写Java脚本,调试。
6. controller中并发时,使用Run Vuser as  a process模式并发。
 
Java程序:  public static void main(String[] args) { 。。。。}

 
Lr脚本:
import com.p2p.test.*;
import lrapi.lr;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
 
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
 
 
 
public class Actions
{
public static HttpClient httpClient = new HttpClient();
public int init() throws Throwable {
 
 
return 0;
}//end of init
 
 
public int action() throws Throwable {
 
 
 
      //   HttpClient httpClient = new HttpClient();
 PostMethod postMethod = new PostMethod(
      //http://172.30.1.44:8899/entruSettleNotify
      //http://10.7.3.94:8899/frontAPI/entruSettleNotify
             "http://172.30.1.44:8899/entruSettleNotify");//http://172.30.1.44:8899/entruSettleNotify   http://10.7.3.94:8899/frontAPI/entruSettleNotify
     // 设置用户浏览器为MicrosoftIE6.0
     postMethod.setRequestHeader("User-Agent",
             "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
     // 设置编码
     postMethod.getParams().setParameter(
             HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
     // 设置请求参数
     
    //String BatchNo = "20140707109257829643";
    //String childBatchNo = "140387";
 
     String reid = "2233344450";   // 还款用 要改
     try{
         String xmldsES0003="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
                 + "<message xmlns=\"http://www.w3school.com.cn\">    "
                 + "<head>        "
                 + "<version>01</version>        "
                 + "<type>0002</type>        "
                 + "<channelNo>HM</channelNo>        "
                 + "<tradDate>20140515</tradDate>        "
                 + "<tradTime>141558</tradTime>        "
                 + "<tradFlowNo>ES000320140515100591</tradFlowNo>        "
                 + "<tradNo>ES0003</tradNo>    "
                 + "</head>    "
                 + "<body>        "
                 + "<merchantNo>1092</merchantNo>        "
                 //20140712109264712593
                 //20140712109289216534
                 + "<batchNo>20140715109258670149</batchNo>        " // 要改
                 + "<submitDate>790538</submitDate>        "
                 + "<batchStatus>06</batchStatus>        "
                 + "<batchUse>01</batchUse>        "
                 + "<batchRemark></batchRemark>        "
                 + "<batchSumCount>1</batchSumCount>        "
                 + "<batchSumAmt>100</batchSumAmt>        "  // 要改
                 + "<batchSumSuccCount>0</batchSumSuccCount>        "
                 + "<batchSumSuccAmt>0.00</batchSumSuccAmt>        "
                 + "<list name=\"batchList\">            "
                 + "<row>                "
                 //961754
                 //160759
                 + "<childBatchNo>578936</childBatchNo>                "  // 要改
                 //102100009545
                 //305100001057
                 + "<cnaps>102100009545</cnaps>                "
                 + "<bankAcc>1</bankAcc>                "
                 + "<rcvName>1</rcvName>                "
                 + "<acctAttribute>02</acctAttribute>                "
                 //中国工商银行股份有限公司北京玉林支行
                 //中国民生银行股份有限公司北京中关村支行
                 + "<branchName>中国工商银行股份有限公司北京玉林支行</branchName>                "
                 + "<branchProvince></branchProvince>                "
                 + "<branchCity></branchCity>                "
                 + "<branchSite></branchSite>                "
                 + "<amount>100</amount>                "  // 要改
                 + "<currencyType>CNY</currencyType>                "
                 + "<state>02</state>                "
                 + "<procTime>20140515131232</procTime>                "
                 + "<remark>转账成功</remark>            "
                 + "</row>            "
                 + "</list>    "
                 + "</body>"
                 + "</message>";
     String xmldsES0006="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
             + "<message xmlns=\"http://www.w3school.com.cn\">    "
             + "<head>        "
             + "<version>01</version>        "
             + "<type>0002</type>        "
             + "<channelNo>HM</channelNo>        "
             + "<tradDate>20140613</tradDate>        "
             + "<tradTime>105500</tradTime>        "
             + "<tradFlowNo>ES000620140410100821</tradFlowNo>        "
             + "<tradNo>ES0006</tradNo>    "
             + "</head>    "
             + "<body>  "
             + "<rechargeId>"+reid+"</rechargeId>      "
                     + "<merchantNo>1054</merchantNo>        "
                     + "<balanceId>161</balanceId>        "
                     + "<rechargeAmt>1003315.07</rechargeAmt>        "
                     + "<tradeDate>20140621</tradeDate>        "
                     + "<state>1</state>        "
                     + "<businessType>2</businessType>        "
                     + "<info>161</info>        "
                     + "<remark>161</remark>    "
                     + "</body>"
                     + "</message>";
     String xmlds = xmldsES0003;//xmldsES0003;   //要改
//
     String aa = xmlds+"111111";
     String mac=DigestUtils.md5Hex(aa);
//   System.out.println("上送报文:"+xmlds);
//   System.out.println("上送摘要:"+mac);
     postMethod.addParameter("tradNo","ES0003");  // 要改 03放款  06还款
     postMethod.addParameter("type","0002");//0002
     postMethod.addParameter("data",xmlds);
     postMethod.addParameter("mac",mac);
 
     }catch (Exception e) {
             e.printStackTrace();
     }
 
     String bankResultValue = "";
     // 获取执行结果
     int status = 0;
     try {
         status = httpClient.executeMethod(postMethod);
     } catch (HttpException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
     }
 
     if(status != 200){
         System.out.println("连接失败");
     }else{
         //连接成功,获取response中的xml数据
 
         try {
             bankResultValue = new String(postMethod.getResponseBody(), "UTF-8");
             System.out.println("返回结果:"+bankResultValue);
//             System.out.println("第"+args[0]+"次返回结果:"+bankResultValue);
 
         } catch (UnsupportedEncodingException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
 
 
 
//   return bankResultValue;
//
//
     }
 
return 0;
}//end of action
 
 
public int end() throws Throwable {
return 0;
}//end of end
}
 
 

Loadrunner执行Java脚本的更多相关文章

  1. Spring项目中执行Java脚本

    问题:在已搭建好Spring环境的JavaWeb项目中,怎么运行一段Java代码,执行一些类似脚本的功能. 情况一:测试局部功能,不需要依赖Spring框架的. 方法:IDEA中新建一个类,编写主函数 ...

  2. 执行Java脚本firefox启动成功,不运行test方法,且提示NullPointerException

    在ideal中新建maven项目,将录制好的Java脚本文件,直接复制到项目中,添加相关的依赖脚本. 代码不报错之后,运行录制好的Java脚本,启动了firefox之后,不执行test方法,报错Nul ...

  3. Jmeter 执行java脚本结束时提示:he JVM should have exitted but did not

    使用jmeter执行java协议测试结束时会提示:he JVM should have exitted but did not ,jmeter2.11以后的可以 通过设置:      jmeteren ...

  4. Jmeter执行java脚本结束时提示:The JVM should have exited but did not.

    使用jmeter对dubbo进行压测时,需要使用jmeter的sampler里的java请求 使用./jmeter.sh -n -t test.jmx -l test.jmx -o -e test后台 ...

  5. Windows自动执行java脚本

    1.打包 idea 1).File-Project Structure-Arifacts 2). 3). 4). 5). 目录位于  根目录/out\artifacts\ 2.Windows定时任务 ...

  6. 老李分享:loadrunner的java user脚本开发

    老李分享:loadrunner的java user脚本开发 poptest在性能测试loadrunner的课程里,以web协议为主,同时也讲解其他协议的脚本开发,对于一个性能测试工程师需要掌握一个以上 ...

  7. Java SSH远程执行Shell脚本实现(转)

    前言 此程序需要ganymed-ssh2-build210.jar包(下载地址:http://www.ganymed.ethz.ch/ssh2/) 为了调试方便,可以将\ganymed-ssh2-bu ...

  8. Java 执行 SQL 脚本文件

    转自:http://blog.csdn.net/hongmin118/article/details/4588941 package com.unmi.db; import java.io.FileI ...

  9. sh脚本执行Java程序

    1.不引用Jar包或者资源文件夹 最简单的程序Hello World. 首先创建Hello.java public class Hello { public static void main(Stri ...

随机推荐

  1. 让hyper-v虚拟机中类ubuntu系统可以全屏

    很久之前一直都没有方法让linux虚拟机支持hyper-v的全屏,只能以1024x768或者800x600等方形屏幕 如果是windows7以前的电脑,可以用mstsc远程桌面修改分辨率,window ...

  2. git 使用事项

    基本安装可查看 http://help.github.com 如果删除了本地的文件,要恢复相关文件,在github存在(别人增加的),则:git pull <远程主机名> <远程分支 ...

  3. 使用jQuery.FileUpload和Backload自定义控制器上传多个文件

    当需要在控制器中处理除了文件的其他表单字段,执行控制器独有的业务逻辑......等等,这时候我们可以自定义控制器. 通过继承BackloadController □ 思路 BackloadContro ...

  4. mui 重写back 调用back方法,实现返回就即时刷新页面

    需求: 从A-----b页面  B操作完后再返回A ,这时A页面数据变化 1.先是针对安卓机可以点击按钮返回,也可以用本机的返回键返回 监听本机的返回按钮,如果点击就调用写好的自定义刷新事件 (fun ...

  5. VB-获取本机计算机名,登录名、ip地址

    真的是很简单,执行结果:Computer:不平凡总在于坚持  User:Administrator  IP:192.168.0.111     '获取计算机名.用户名.本机ip     Dim Loc ...

  6. Python之路----文件操作

    文件操作 1.能调用方法的一定是对象,比如数值.字符串.列表.元组.字典,甚至文件也是对象,Python中一切皆为对象. str1 = 'hello' str2 = 'world' str3 = ' ...

  7. python函数的返回值 讲解

    我们一起来聊聊python函数返回值的特殊情况,之前我也碰到过类似方面的问题,到后来查阅了一些资料后,发现原来是这样. 首先,写函数的时候,一定要写函数的文档,这样方便我们识别函数是做什么的.我记得很 ...

  8. EventLog组件

    1.使用EventLog组件读写事件日志 SourceExists方法  确定事件源是否已在本地计算机上注册 DeleteEventSource方法  用于从事件日志中移除应用程序的事件源注册 pri ...

  9. 洛谷 P1541 乌龟棋

    题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起 ...

  10. ExtJS4加载FormPanel数据的几种方式

    我们做web应用最多的就是处理表单,extjs为我们提供了很多处理表单的功能,很多初学者疑惑怎么加载表单数据,到底能用什么方式加载?本文中,我将我自己实验过的进行一下总结,自己备忘,也希望能帮助到其他 ...