zoukankan      html  css  js  c++  java
  • 逐层解析请求json参数字符串【我】

     import net.sf.json.JSONObject;

    逐层解析请求json参数字符串:

            
            InputStream inStream =null;
            BufferedReader br =null;
            String reJson="";
            String rtJson="";
            String tranId="";
            
            //返回报文字段
            String resultCode = "1";
            String resultMsg = "失败";
            try {
                httpRequest.setCharacterEncoding("UTF-8");  
                inStream = httpRequest.getInputStream();
                String reqUrl= httpRequest.getRequestURI();
                syslogger.info(reqUrl);
                String[] method = reqUrl.split("/", 0);
                Map headMap = this.getHeaderMap(httpRequest);
                Map params = this.getParameterMap(httpRequest);
                syslogger.info(params);
                 br = new BufferedReader(new InputStreamReader(inStream,"UTF-8"));
                 String str=br.readLine();
                 StringBuffer json = new StringBuffer();
                 while (str != null) {
                    try {
                        json.append(str);
                        str =  br.readLine();
                    } catch (Exception blExc) {
                        System.out.println("请求参数获取出错------------str:"+str);
                        throw new CommonRunException(blExc.getMessage(), blExc, "");
                    }
                }
                 reJson=json.toString();
                 syslogger.info("resultlog 请求------------"+json);
    //             String httpMethod = httpRequest.getMethod().toUpperCase();
                 System.out.println("resultlog 请求------------"+json);
                 //调用相关的程序逻辑
                 tranId=RequestUtil.getMapValue(headMap,"X-CTG-Request-Id");
                if("".equals(tranId)){
                    tranId=RequestUtil.getMapValue(headMap,"X-CTG-Request-ID");
                }
                //调用实现类参数
                 String param = "";
                try {
                    //逐层解析报文获取请求参数
                    JSONObject jsobRst1 = JSONObject.fromObject(json.toString());
                    syslogger.info("jsobRst1 请求------------"+jsobRst1); 
                    String svcCont = jsobRst1.getString("svcCont");
                    JSONObject requestObject = JSONObject.fromObject(svcCont);
                    param = requestObject.get("requestObject").toString();
                    param = jsobRst1.toString();
                } catch (Exception e) {
                    System.out.println("请求参数解析出错------------str:"+json);
                    syslogger.info("解析报文出错  请求------------"+e); 
                    throw new Exception("解析报文出错  请求------------"+e);
                }
  • 相关阅读:
    最小圆覆盖
    BZOJ3572 [Hnoi2014]世界树 【虚树 + 树形dp】
    一些组合数学
    BZOJ3611 [Heoi2014]大工程 【虚树】
    线段树合并
    BZOJ4446 [Scoi2015]小凸玩密室 【树形Dp】
    生成函数小记
    BZOJ2337 [HNOI2011]XOR和路径 【概率dp + 高斯消元】
    连续数字异或和
    POJ2976:Dropping tests——题解
  • 原文地址:https://www.cnblogs.com/libin6505/p/11890752.html
Copyright © 2011-2022 走看看