From 64b3168e1993689c9003ee43b3ae5811b626c866 Mon Sep 17 00:00:00 2001 From: 6092002067 Date: Thu, 9 Mar 2017 17:06:23 +0800 Subject: Fix register micro service code Issue-ID:HOLMES-50 Change-Id: I02ccf2ea367e4d2be3f2a4d034a1c960d2c28915 Signed-off-by: youbowu --- .../org/openo/holmes/common/utils/MSBRegisterUtil.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'holmes-actions/src/main/java/org/openo') diff --git a/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java b/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java index fc5e882..30e411f 100644 --- a/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java +++ b/holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java @@ -22,6 +22,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; @@ -44,6 +45,7 @@ public class MSBRegisterUtil { if (StringUtils.isNotEmpty(content)) { httpPost.setEntity(new ByteArrayEntity(content.getBytes())); } + this.setHeader(httpPost); HttpResponse response; try { response = httpClient.execute(httpPost); @@ -55,12 +57,20 @@ public class MSBRegisterUtil { log.info("Registration successful service to the bus :" + response.getEntity()); return true; } else { - log.warn("Registering the service to the bus failure:"+response.getStatusLine().getStatusCode()+" "+ - response.getStatusLine().getReasonPhrase()+response.getStatusLine().getProtocolVersion()); + log.warn( + "Registering the service to the bus failure:" + response.getStatusLine().getStatusCode() + " " + + response.getStatusLine().getReasonPhrase() + response.getStatusLine() + .getProtocolVersion()); return false; } } finally { httpClient.close(); } } + + private void setHeader(HttpRequestBase httpRequestBase) { + httpRequestBase.setHeader("Content-Type", "text/html;charset=UTF-8"); + httpRequestBase.setHeader("Accept", "application/json"); + httpRequestBase.setHeader("Content-Type", "application/json"); + } } \ No newline at end of file -- cgit 1.2.3-korg