REM:
1.优化Restful公共接口
2.修改华为设备获取防护对象接口
This commit is contained in:
chenlinghy 2020-11-18 10:37:21 +08:00
parent 2e47fc9ff8
commit e120949e2c
2 changed files with 16 additions and 43 deletions

View File

@ -258,13 +258,13 @@ public class HuaWeiAbilityImpl implements DisposeAbility {
HttpResponse response = restfulInterface.queryAllZones(url, token);
if (response.getStatus() == ErrorCode.ERR_TOKENNOTFOUND.getCode()) {
if (response.getStatus() == HttpServletResponse.SC_PRECONDITION_FAILED) {
// 重新登录获取 token
upgradeToken();
response = restfulInterface.queryAllZones(url, token);
}
return response.getStatus() == ErrorCode.ERR_OK.getCode();
return response.getStatus() == HttpServletResponse.SC_OK;
} catch (
Exception ex) {
log.error(ex.getMessage());

View File

@ -54,12 +54,12 @@ public class RestfulInterface {
* @param url the url
* @param header the header
* @param body the body
* @return the string
* @return the http response
*/
private static String postJson(String url, Map<String, String> header, String body) {
private static HttpResponse postJson(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute().body();
.execute();
}
/**
@ -67,55 +67,28 @@ public class RestfulInterface {
*
* @param url the url
* @param header the header
* @return the json
*/
private static String getJson(String url, Map<String, String> header) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.get(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header)
.execute().body();
}
/**
* Gets http response.
*
* @param url the url
* @param header the header
* @return the http response
*/
private static HttpResponse getHttpResp(String url, Map<String, String> header) {
private static HttpResponse getJson(String url, Map<String, String> header) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.get(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header)
.execute();
}
/**
* Put http response.
* Put json.
*
* @param url the url
* @param header the header
* @param body the body
* @return the http response
*/
private static HttpResponse putHttpResp(String url, Map<String, String> header, String body) {
private static HttpResponse putJson(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.put(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute();
}
/**
* Post http response.
*
* @param url the url
* @param header the header
* @param body the body
* @return the http response
*/
private static HttpResponse postHttpResp(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.post(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute();
}
/**
* Deletes http response.
*
@ -123,7 +96,7 @@ public class RestfulInterface {
* @param header the header
* @return the http response
*/
private static HttpResponse deleteHttpResp(String url, Map<String, String> header, String body) {
private static HttpResponse deleteJson(String url, Map<String, String> header, String body) {
HttpRequest.setGlobalTimeout(timeOutValue);
return HttpRequest.delete(url).header(Header.CONTENT_TYPE, "application/json").addHeaders(header).body(body)
.execute();
@ -149,7 +122,7 @@ public class RestfulInterface {
log.debug("Restful request: {}: {}", url, reqJson);
String svrResp = postJson(url, httpHeadMap, reqJson);
String svrResp = postJson(url, httpHeadMap, reqJson).body();
if (svrResp == null) {
log.debug("Server return null: {}", url);
@ -196,10 +169,10 @@ public class RestfulInterface {
switch (reqType) {
case GET:
svrResp = getJson(url, httpHeadMap);
svrResp = getJson(url, httpHeadMap).body();
break;
case POST:
svrResp = postJson(url, httpHeadMap, reqJson);
svrResp = postJson(url, httpHeadMap, reqJson).body();
break;
default:
log.error("Unknown method: {}", reqType);
@ -255,16 +228,16 @@ public class RestfulInterface {
switch (reqType) {
case GET:
svrResp = getHttpResp(url, httpHeadMap);
svrResp = getJson(url, httpHeadMap);
break;
case POST:
svrResp = postHttpResp(url, httpHeadMap, reqJson);
svrResp = postJson(url, httpHeadMap, reqJson);
break;
case PUT:
svrResp = putHttpResp(url, httpHeadMap, reqJson);
svrResp = putJson(url, httpHeadMap, reqJson);
break;
case DELETE:
svrResp = deleteHttpResp(url, httpHeadMap, reqJson);
svrResp = deleteJson(url, httpHeadMap, reqJson);
break;
default:
log.error("Unknown method: {}", reqType);