diff --git a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java index ef39eaa0..0a58604f 100644 --- a/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java +++ b/src/main/java/com/dispose/ability/impl/HuaWeiAbilityImpl.java @@ -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()); diff --git a/src/main/java/com/dispose/restful/RestfulInterface.java b/src/main/java/com/dispose/restful/RestfulInterface.java index 1cd51374..0c61dc6b 100644 --- a/src/main/java/com/dispose/restful/RestfulInterface.java +++ b/src/main/java/com/dispose/restful/RestfulInterface.java @@ -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 header, String body) { + private static HttpResponse postJson(String url, Map 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 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 header) { + private static HttpResponse getJson(String url, Map 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 header, String body) { + private static HttpResponse putJson(String url, Map 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 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 header, String body) { + private static HttpResponse deleteJson(String url, Map 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);