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);
                }
  • 相关阅读:
    Entity Framework+SQLite+DataBaseFirst
    接口的实现方式(显示和隐示)及协变和逆变
    C#线程
    UIScrollView放大缩小图片偏移的问题
    SQL Server 2008在添加用户时弹出错误提示:此版本的 Microsoft Windows 不支持 MUST_CHANGE 选项
    jmeter的正则表达式的使用
    Linux下安装jmeter
    系统测试方案
    [ASP.NET].NET逻辑分层架构总结
    [C#]C#时间日期操作
  • 原文地址:https://www.cnblogs.com/libin6505/p/11890752.html
Copyright © 2011-2022 走看看