zoukankan      html  css  js  c++  java
  • Java 透传

    这次任务是接口透传

    1 首先外部有一个提供一个完整的接口,可以调的通。

    测试时候可以postman调用。外部系统得要提供完成API文档。以助于更好的对接。

    例如确定请求方式,入参的格式。

    将外部接口配置

     3 调用

     这里用的是post请求,返回数据的json格式,已经封装成result.

    @Override
        public Result storeInforMation(StoreInformation storeInformation) throws Exception {
            Result result =new Result();
            List<StoreListinfo> storeListinfo = new ArrayList<>();
            StoreListinfoBound storeListinfoBound=new StoreListinfoBound();
            Map<String, Object> map = new HashMap<>();
            map.put("code", storeInformation.getCode());
            map.put("provinceId", storeInformation.getProvinceId());
            map.put("cityId", storeInformation.getCityId());
            map.put("areaId", storeInformation.getAreaId());
            map.put("agentName", storeInformation.getAgentName());
            String response = HttpClientUtil.httpPostRequest(wmsZngUrl,JSON.toJSONString(map));
            log.info("wmsZngUrl={} and  response is: {}",wmsZngUrl,response);
             com.jiutong.entity.flagshipStore.Result result1 = JSONObject.parseObject(response, com.jiutong.entity.flagshipStore.Result.class);
             if( result1.getCode()==-1){
                  result.setResultCode(new ResultCode(-1,"请求失败"));
             }else{
                  JSONObject data=JSONObject.parseObject(String.valueOf(result1.getData()));
                 if(data==null){
                     result.setResultCode(new ResultCode(0,"请求成功,暂无数据"));
                 }else{
                     Object storeList = Optional.ofNullable(getFromJson(data, "storeList")).orElse("");
                     Object bound = Optional.ofNullable(getFromJson(data, "bound")).orElse("");
                     com.alibaba.fastjson.JSONArray jsonArray= JSON.parseArray(JSONUtil.toJson(storeList));
                     for(int i=0;i<jsonArray.size();i++){
                        JSONObject jsonObject = jsonArray.getJSONObject(i);
                         String address = Optional.ofNullable(getFromJson(jsonObject,"address")).orElse("").toString();
                         String storeName = Optional.ofNullable(getFromJson(jsonObject,"storeName")).orElse("").toString();
                         Integer  id = (Integer) Optional.ofNullable(getFromJson(jsonObject,"id")).orElse("");
                         StoreListinfo storeListinfo1 = new StoreListinfo();
                         storeListinfo1.setId(id);
                         storeListinfo1.setStoreName(storeName);
                         storeListinfo1.setAddress(address);
                         storeListinfo.add(storeListinfo1);
                     }
                     storeListinfoBound.setBound(bound.toString());
                     storeListinfoBound.setStoreListinfo(storeListinfo);
                     result.setData(storeListinfoBound);
                 }
             }
           return  result;
        }
    
        private Object getFromJson(JSONObject jsonObject, String key){
            if(jsonObject.containsKey(key)){
                return jsonObject.get(key);
            }
            return null;
        }

    4

     JSON.parseObject(String str)是将str转化为相应的JSONObject对象


    5 HttpClientUtil.httpPostRequest方法

     

     

    任务也是比较简单的,在联调的时候,花的时间比较多,两者很多事情没有说清楚,需要一个详细的API文档。

  • 相关阅读:
    部署phpmyadmin登录不进去
    无法获取快照信息:锁定文件失败
    nginx: [emerg] BIO_new_file("/etc/nginx/ssl_key/server.crt") failed (SSL: error:02001002:syste
    nginx重启失败
    An error occurred (500 Error)
    Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.
    clnt_create: RPC: Program not registered
    [error] 2230#2230: *84 client intended to send too large body: 1711341 bytes
    lnmp部署知乎出现403
    easyui下拉框过滤优化
  • 原文地址:https://www.cnblogs.com/zq1003/p/14646830.html
Copyright © 2011-2022 走看看