From a856b96b595580ab863a3b61e2ec6a9e3b252943 Mon Sep 17 00:00:00 2001 From: "heavyrain.lee" Date: Fri, 10 Jan 2020 11:32:25 +0800 Subject: [PATCH] update --- .../loServer/action/UnknownErrorAction.java | 2 +- .../sdk/utilities/AdminHttpUtils.java | 24 ++++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java index 40a3ad4d..d0eaf109 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/UnknownErrorAction.java @@ -28,7 +28,7 @@ public class UnknownErrorAction extends Action{ @Override public boolean action(Request request, Response response) { - response.setStatus(HttpResponseStatus.NOT_FOUND); + response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR); return true; } } diff --git a/sdk/src/main/java/cn/wildfirechat/sdk/utilities/AdminHttpUtils.java b/sdk/src/main/java/cn/wildfirechat/sdk/utilities/AdminHttpUtils.java index 92254d58..fb9341f1 100644 --- a/sdk/src/main/java/cn/wildfirechat/sdk/utilities/AdminHttpUtils.java +++ b/sdk/src/main/java/cn/wildfirechat/sdk/utilities/AdminHttpUtils.java @@ -67,31 +67,33 @@ public class AdminHttpUtils { HttpResponse response = httpClient.execute(post); int statusCode = response.getStatusLine().getStatusCode(); - if(statusCode != HttpStatus.SC_OK){ - LOG.info("Request error: "+statusCode); - throw new Exception("Http request error with code:" + statusCode); - }else{ - BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity() - .getContent(),"utf-8")); - StringBuffer sb = new StringBuffer(); + String content = null; + if (response.getEntity().getContentLength() > 0) { + BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "utf-8")); + StringBuilder sb = new StringBuilder(); String line; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { - sb.append(line + NL); + sb.append(line).append(NL); } in.close(); - String content = sb.toString(); + content = sb.toString(); LOG.info("http request response content: {}", content); + } + if(statusCode != HttpStatus.SC_OK){ + LOG.info("Request error: " + statusCode + " error msg:" + content); + throw new Exception("Http request error with code:" + statusCode); + } else { return fromJsonObject(content, clazz); } } catch (Exception e) { e.printStackTrace(); throw e; - }finally{ - if(post != null){ + } finally { + if(post != null) { post.releaseConnection(); } }