Note LR12 call dubbo Interface

       This two-day trading week at several testing centers single quota system, the service is invoked by dubbo direct way to access, and it will learn include dubbo calls, review the basic knowledge of java, etc., make a summary of this article, the key point which achieved record for future operational needs.

1, dubbo general framework is to integrate the spring, so to call the service on dubbo, must prepare the relevant jar package and configuration files. Of course, more than JDK1.8 development environment it is also necessary.

jar package: includes the dubbo and the required spring run. Listed below: The red frame part including but not limited to, some need to be based on project requirements.

Profile : The main consumer profile, because the service requires the use of spring in the form of inversion of control framework to get java bean object.

The main configuration elements include: registration center address, application server cluster group name, as well as service ID (name of the group in the configuration) of each interface, you can name your own in front of the id

 

2, the first notes of the eclipse through the script, new construction, attention to catalog storage methods:

New resouce folder (configured in bulid path to the default path, it will automatically go read the script runs), config inside the store bootstrap.properties file, the file may not work, but because of the need to load the program runs, it must exist. dubbo-consumer.xml also stored inside (if there is loadrunner, as long as consistent with the path to the script) 

3, the program code structure:

package dubbo_test;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.dap.api.IService;
import com.dap.param.ControlData;
import com.dap.param.StringInput;
import com.dap.param.StringOutput;

public class Dubbo_check_before_query {
    
    private IService demoService1 = null;
    private static ClassPathXmlApplicationContext context = null;
    public int init() throws Throwable {
        context = new ClassPathXmlApplicationContext("dubbo-consumer.xml");   //加载消费者配置文件
        demoService1 = (IService)context.getBean("check_before_query");    //获取服务bean
        //System.out.println(demoService1);
        //demoService2 = (IService)context.getBean("scan_limit_recover");    
        return 0;
    }//end of init
    
    
    public int action() throws Throwable {
        //报文头:这部分是公司统一规定的格式,任何通过dubbo调用的报文都指定了这部分的内容和格式
        StringInput input = new StringInput();
        String code = "";
        String transSeqNo = "9A201901040004993885";
        Map<String, Object> map = new HashMap<String, Object>();
        ControlData ctrlData = new ControlData();
        ctrlData.setTransSeqNo(transSeqNo);
        ctrlData.setTransMedium("NM");
        ctrlData.setUserId("UR000000907545");
        ctrlData.setTransTeller("9995003");
        ctrlData.setTransBranch("801000");
        ctrlData.setSysIndicator("9A");
        ctrlData.setReqTime(new Date());
        ctrlData.setHostIp("127.0.0.1");
        ctrlData.setBizTrackNo(transSeqNo);
        ctrlData.setPageIndex(1);
        ctrlData.setPageSize(0);
        ctrlData.setServcId("AS_LCS_RST_CKBFSC"); //服务名为:AS_LCS_RST_CKBFSC
        input.setCtrlData(ctrlData);

//根据报文的内容,构造报文体:该报文的json格式,并且使用map去构建的;不同的系统报文格式不一,构建方式要根据后台解析方式确定,这个需要跟对应的开发人员去确认。
        map.put("tranam","0.13");
        map.put("beanId","queryCKBFSC");
        map.put("acctNo","6235401595722401874");
        map.put("servcId","AS_LCS_RST_CKBFSC");
        map.put("brchno","801000");
        map.put("trantp","03");
        map.put("servtp","NM");
        map.put("dyflag","1");
        map.put("custtp","11");
        map.put("accttp","3");
        map.put("limttp","23");
        map.put("cardno","6235401595722401874");
        map.put("prcsna","扫码支付扣减前检查");
        map.put("risklv","01");
        map.put("custid","UR100468920896");
        map.put("rebktp","99");
        map.put("limttp","23");
        String[] ptp = {"02", "03"};
        map.put("prodtp",ptp);
        
        //入参:将构建的map对象转成json格式
        input.setBody(JSON.toJSONString(map));
        
        StringOutput result1 = (StringOutput) demoService1.handle(input); //发送报文,返回对象存在result1 中
        String resultStr1 =JSON.toJSONString(result1);  //将返回内容转换成json格式

        //获取交易结果信息
        code = resultStr1.substring(resultStr1.indexOf("message") - 11, resultStr1.indexOf("message") -3);
        //返回不是0,就代表失败。
        if(!code.equals("00000000")){
            System.out.println("=====failed:" + resultStr1 + "=====");
            return 0;
          }else {
              System.out.println("=====success:" + resultStr1 + "====="); 
          }
        return 0;
    }

    public static void main(String[] args) throws Throwable {
        //调试主方法
        Dubbo_check_before_query dt = new Dubbo_check_before_query();
        dt.init();
        dt.action();
        
    }

}
 

4、将上述脚本移植到LR12中:

(1)LR协议选择java user

(2)配置运行所需环境,包括jdk和jar包:

(3)根据LR测试脚本结构去移植代码,其实上述eclipse中的代码就是根据LR中的结构写的。唯一的区别就是,要在action中加入LR事务开始和结束的语句。 

发布了53 篇原创文章 · 获赞 4 · 访问量 1万+

Guess you like

Origin blog.csdn.net/figo8875/article/details/104673146