public String a(HttpServletRequest request,HttpServletResponse response) throws JSONException, IOException, ParseException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{ response.addHeader( "Access-Control-Allow-Origin", "*" ); response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS"); response.addHeader("Access-Control-Allow-Headers", "Content-Type, Authorization, Accept,X-Requested-With"); String reqStr=request.getParameter("sendJson"); long startTime = System.currentTimeMillis(); System.out.println("请求参数---" + reqStr); logger.info("请求参数---" + reqStr); String result = ""; String transCode = ""; JSONObject jsObj = net.sf.json.JSONObject.fromObject(reqStr); net.sf.json.JSONObject head = net.sf.json.JSONObject.fromObject(jsObj.getJSONObject("head")); net.sf.json.JSONObject body = net.sf.json.JSONObject.fromObject(jsObj.getJSONObject("body")); if(head.containsKey("transcode")){ transCode = head.getString("transcode"); }else{ logger.info("交易码不存在!"); JSONObject resp = new JSONObject(); resp.put("code", "9999"); resp.put("message", "交易码不存在"); result = resp.toString(); return result; } net.sf.json.JSONObject obj = GetResultByTransCode.getResult(transCode); try { ApplicationContext appContext = ContextLoader.getCurrentWebApplicationContext(); Object serviceObject = appContext.getBean(obj.getString("serviceName")); Method methodName = serviceObject.getClass().getMethod(obj.getString("methodName"), JSONObject.class); result = (String) methodName.invoke(serviceObject, body); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } return result; }
java工具类-接受请求参数,并利用反射调用方法
猜你喜欢
转载自www.cnblogs.com/chaoswu/p/10113768.html
今日推荐
周排行