diff options
author | Gokul Singaraju <goksing@gmail.com> | 2017-11-02 01:08:36 -0400 |
---|---|---|
committer | Gokul Singaraju <goksing@gmail.com> | 2017-11-02 01:11:23 -0400 |
commit | 2a6d8d9a468469b3b424451d25b47e03745f304b (patch) | |
tree | 95721c8164041f215bb100e3a32daee6da2bdf70 /veslibrary | |
parent | 0d3bbd92ce12ff1f2735a924e007641730dec2ff (diff) |
Fix Javalib logging under server errors
Issue-Id: VNFSDK-121
Change-Id: I118cfae30a559f31588e28ff389d93895d6e9d7f
Signed-Off-by: Gokul Singaraju <goksing@gmail.com>
Diffstat (limited to 'veslibrary')
-rw-r--r-- | veslibrary/ves_javalibrary/evel_javalib2/src/evel_javalibrary/att/com/AgentMain.java | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/evel_javalibrary/att/com/AgentMain.java b/veslibrary/ves_javalibrary/evel_javalib2/src/evel_javalibrary/att/com/AgentMain.java index 22d5a0a..eff9a3e 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/evel_javalibrary/att/com/AgentMain.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/evel_javalibrary/att/com/AgentMain.java @@ -89,7 +89,22 @@ public enum EVEL_ERR_CODES { /* AgentDispatcher loops on messages in RingBuffer and POSTs them * to external Collector */ - private static class AgentDispatcher implements Runnable { + private static class AgentDispatcher implements Runnable { + + private String readStream(InputStream stream) throws Exception { + StringBuilder builder = new StringBuilder(); + try (BufferedReader in = new BufferedReader(new InputStreamReader(stream))) { + String line; + while ((line = in.readLine()) != null) { + builder.append(line); // + "\r\n"(no need, json has no line breaks!) + } + in.close(); + } + logger.error("Resp: " + builder.toString()); + System.out.println("Resp: " + builder.toString()); + return builder.toString(); + } + public void run() { String datatosend=null; @@ -122,7 +137,7 @@ public enum EVEL_ERR_CODES { // No caching, we want the real thing. con.setUseCaches (false); // Specify the content type. - con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); + con.setRequestProperty("Content-Type", "application/json"); //con.setChunkedStreamingMode(0); con.setInstanceFollowRedirects( false ); //Basic username password authentication @@ -163,24 +178,17 @@ public enum EVEL_ERR_CODES { logger.warn(url + " **SERVER ERROR**"); InputStream es = con.getErrorStream(); - if( es != null) - { - int ret = 0; - byte[] buf = null; - // read the response body - while ((ret = es.read(buf)) > 0) { - logger.info("Resp:"+buf); - } - // close the errorstream - es.close(); - } + readStream(es); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } else @@ -319,4 +327,4 @@ public enum EVEL_ERR_CODES { -}
\ No newline at end of file +} |