*/\r
package org.openo.holmes.rulemgt.bolt.enginebolt;\r
\r
+import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;\r
+\r
import com.fasterxml.jackson.databind.ObjectMapper;\r
import java.io.ByteArrayOutputStream;\r
import java.io.IOException;\r
+import java.io.InputStream;\r
+import java.io.InputStreamReader;\r
+import java.io.Reader;\r
import java.io.UnsupportedEncodingException;\r
+import java.nio.charset.Charset;\r
import lombok.extern.slf4j.Slf4j;\r
import org.apache.commons.lang3.StringUtils;\r
+import org.apache.http.ConnectionClosedException;\r
import org.apache.http.HttpEntity;\r
import org.apache.http.HttpResponse;\r
import org.apache.http.client.methods.HttpDelete;\r
import org.apache.http.client.methods.HttpRequestBase;\r
import org.apache.http.entity.BufferedHttpEntity;\r
import org.apache.http.entity.ByteArrayEntity;\r
+import org.apache.http.entity.ContentType;\r
import org.apache.http.impl.client.CloseableHttpClient;\r
import org.apache.http.impl.client.HttpClients;\r
+import org.apache.http.protocol.HTTP;\r
import org.apache.http.util.EntityUtils;\r
import org.jvnet.hk2.annotations.Service;\r
import org.openo.holmes.common.config.MicroServiceConfig;\r
httpRequestBase.setHeader("Content-Type", "application/json");\r
}\r
\r
+ public String getResponseContent(HttpResponse response) {\r
+ HttpEntity entity = response.getEntity();\r
+ InputStream is = null;\r
+ if (entity != null) {\r
+ try {\r
+ is = entity.getContent();\r
+ final ContentType contentType = ContentType.getOrDefault(entity);\r
+ Charset charset = contentType.getCharset();\r
+ if (charset == null) {\r
+ charset = HTTP.DEF_CONTENT_CHARSET;\r
+ }\r
+ final StringBuilder b = new StringBuilder();\r
+ final char[] tmp = new char[1024];\r
+ final Reader reader = new InputStreamReader(is, charset);\r
+ try {\r
+ int l;\r
+ while ((l = reader.read(tmp)) != -1) {\r
+ b.append(tmp, 0, l);\r
+ }\r
+ } catch (ConnectionClosedException ignore) {\r
+\r
+ } catch (IOException e) {\r
+ log.info("Failed to read the contents of the input stream of the http entity.", e);\r
+ }\r
+ return b.toString();\r
+ } catch (IOException e) {\r
+ log.info("Failed to read the contents of the http entity.", e);\r
+ } finally {\r
+ try {\r
+ if (is != null) {\r
+ is.close();\r
+ }\r
+ } catch (IOException e) {\r
+ log.info("Failed to close the input stream of the http entity.", e);\r
+ }\r
+ }\r
+ }\r
+ return "{}";\r
+ }\r
+\r
public byte[] getData(HttpEntity httpEntity) throws IOException {\r
log.info("Rule deployed. Package name: " + httpEntity.getContent().toString()\r
+ ". Content length: " + httpEntity.getContentLength());\r
return responseBytes;\r
}\r
\r
- public String getResponseContent(HttpResponse httpResponse) throws CorrelationException {\r
- byte[] dataByte;\r
- String result = null;\r
- try {\r
- HttpEntity httpEntity = httpResponse.getEntity();\r
- if (httpEntity != null) {\r
- byte[] responseBytes = getData(httpEntity);\r
- dataByte = responseBytes;\r
- result = bytesToString(dataByte);\r
- }\r
- return result;\r
- } catch (Exception e) {\r
- throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR, e);\r
- }\r
- }\r
+// public String getResponseContent(HttpResponse httpResponse) throws CorrelationException {\r
+// byte[] dataByte;\r
+// String result = null;\r
+// try {\r
+// HttpEntity httpEntity = httpResponse.getEntity();\r
+// if (httpEntity != null) {\r
+// byte[] responseBytes = getData(httpEntity);\r
+// dataByte = responseBytes;\r
+// result = bytesToString(dataByte);\r
+// }\r
+// return result;\r
+// } catch (Exception e) {\r
+// throw new CorrelationException(I18nProxy.RULE_MANAGEMENT_PARSE_DEPLOY_RESULT_ERROR, e);\r
+// }\r
+// }\r
\r
private String bytesToString(byte[] bytes) throws UnsupportedEncodingException {\r
if (bytes != null) {\r