X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=veslibrary%2Fves_javalibrary%2Fevel_javalib2%2Fsrc%2Fevel_javalibrary%2Fatt%2Fcom%2FAgentMain.java;h=451c5b68618b68d70b33a45d6c299e811a3a78b0;hb=9b3bff3a86a9c32a849640efa8d99d219cc7ba68;hp=53566d03df3f02c00ae55098472cb4790c1b5cbb;hpb=8076e08b82c476f4df8f92d7c38a5e932c4c8452;p=vnfsdk%2Fcompliance.git 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 53566d0..451c5b6 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 @@ -27,7 +27,7 @@ package evel_javalibrary.att.com; import org.apache.log4j.Logger; import org.apache.log4j.Level; -//import java.io.BufferedReader; +import java.io.BufferedReader; import java.io.BufferedWriter; //import java.io.DataOutputStream; import java.io.IOException; @@ -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