restful接口,入参以流的形式接收,出参流返回

@PostMapping("Statusback")
  public void Statusback(HttpServletRequest request, HttpServletResponse response) {
    StringBuilder sb = new StringBuilder();
    try {
      request.getReader().lines().forEach(sb::append);
    } catch (IOException e) {
      log.error("回传解析异常:{}", Throwables.getStackTraceAsString(e));
      writeResponse(response, "F参数解析异常!");
    }
    log.info("-----接口回调入参--------:  ", sb.toString());
    Map map = getParamMap(sb.toString());
    Return ReturnParam = JSON.parseObject(JSON.toJSONString(map), Return.class);
    String responseStr = storageNotifyService.acceptNotify(ReturnParam);
    log.info("-----接口回调返回参数--------:  ", responseStr);
    writeResponse(response, responseStr);
  }

  private void writeResponse(HttpServletResponse response, String str) {
    try {
      response.getWriter().println(str);
    } catch (IOException ex) {
      log.error("回传结果报错!{}", Throwables.getStackTraceAsString(ex));
    }
  }

  private Map getParamMap(String str) {
    String[] kvArray = str.split("&");
    Map map = new HashMap<>();
    Arrays.stream(kvArray).forEach(kvStr -> {
      String[] kv = kvStr.split("=", 2);
      String key = kv[0];
      String value = kv[1];
      map.put(key, value);
    });
    return map;
  }

你可能感兴趣的:(restful接口,入参以流的形式接收,出参流返回)