Optimize WebUtils.java

This commit is contained in:
hongqiaowei
2021-10-29 16:43:25 +08:00
parent e24116032b
commit a40ba2672f
11 changed files with 223 additions and 149 deletions

View File

@@ -75,13 +75,13 @@ public class ApiDocAuthPluginFilter implements FizzPluginFilter {
response.getHeaders().setExpires(0);
String respJson = WebUtils.jsonRespBody(HttpStatus.UNAUTHORIZED.value(),
HttpStatus.UNAUTHORIZED.getReasonPhrase(), WebUtils.getTraceId(exchange));
return WebUtils.buildDirectResponse(exchange, HttpStatus.UNAUTHORIZED, null, respJson);
return WebUtils.response(exchange, HttpStatus.UNAUTHORIZED, null, respJson);
}
} catch (Exception e) {
log.error("{} exception", API_DOC_AUTH_PLUGIN_FILTER, e);
String respJson = WebUtils.jsonRespBody(HttpStatus.INTERNAL_SERVER_ERROR.value(),
HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), WebUtils.getTraceId(exchange));
return WebUtils.buildDirectResponse(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, respJson);
return WebUtils.response(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, respJson);
}
}

View File

@@ -103,11 +103,11 @@ public class BasicAuthPluginFilter implements FizzPluginFilter {
response.getHeaders().setCacheControl("no-store");
response.getHeaders().setExpires(0);
response.getHeaders().add("WWW-authenticate", "Basic Realm=\"input username and password\"");
return WebUtils.buildDirectResponse(exchange, HttpStatus.UNAUTHORIZED, null, null);
return WebUtils.response(exchange, HttpStatus.UNAUTHORIZED, null, null);
}
} catch (Exception e) {
log.error("Basic Auth plugin Exception", e);
return WebUtils.buildDirectResponse(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, null);
return WebUtils.response(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, null);
}
}

View File

@@ -80,13 +80,13 @@ public class ApiPairingPluginFilter implements FizzPluginFilter {
response.getHeaders().setExpires(0);
String respJson = WebUtils.jsonRespBody(HttpStatus.UNAUTHORIZED.value(),
HttpStatus.UNAUTHORIZED.getReasonPhrase(), WebUtils.getTraceId(exchange));
return WebUtils.buildDirectResponse(exchange, HttpStatus.UNAUTHORIZED, null, respJson);
return WebUtils.response(exchange, HttpStatus.UNAUTHORIZED, null, respJson);
}
} catch (Exception e) {
log.error("{} Exception", API_PAIRING_PLUGIN_FILTER, e);
String respJson = WebUtils.jsonRespBody(HttpStatus.INTERNAL_SERVER_ERROR.value(),
HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), WebUtils.getTraceId(exchange));
return WebUtils.buildDirectResponse(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, respJson);
return WebUtils.response(exchange, HttpStatus.INTERNAL_SERVER_ERROR, null, respJson);
}
}