RequestContext ctx = RequestContext.getCurrentContext();
HttpServletRequest request = ctx.getRequest();
//给请求添加orgId参数
String method = request.getMethod();
if ("POST".equals(method.toUpperCase())) {
String charSet = ctx.getRequest().getCharacterEncoding();
try {
InputStream inputStream = ctx.getRequest().getInputStream();
String body = StreamUtils.copyToString(inputStream, Charset.forName(charSet));
JSONObject param = JSONObject.parseObject(body);
if (Objects.isNull(param) || param.isEmpty()) {
param = new JSONObject();
param.put("orgId", orgId);
} else {
param.put("orgId", orgId);
}
final byte[] paramBytes = param.toJSONString().getBytes(charSet);
rewriteRequest(ctx, paramBytes);
ctx.addZuulRequestHeader("Content-type", "application/json");
} catch (IOException e) {
e.printStackTrace();
}
}