• 逐层解析请求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);
                }
  • 相关阅读:
    Javascript&Html-系统对话框
    Javascript&Html-延迟调用和间歇调用
    Javascript&Html-弹出窗口的屏蔽程序
    iPhone屏幕旋转
    iPhone深度学习-ARM
    xCode控制台的使用-应用闪退原因跟踪
    IOS-内存检测以及优化
    Javascript-Array
    http与https的区别
    Nginx:处理HTTP请求
  • 原文地址:https://www.cnblogs.com/libin6505/p/11890752.html
Copyright © 2020-2023  润新知