diff options
author | 6092002067 <wu.youbo@zte.com.cn> | 2017-03-09 17:06:23 +0800 |
---|---|---|
committer | 6092002067 <wu.youbo@zte.com.cn> | 2017-03-09 17:06:23 +0800 |
commit | 64b3168e1993689c9003ee43b3ae5811b626c866 (patch) | |
tree | f331aa006d3bca5dbc058554de5f96606dcac900 /holmes-actions/src/main/java/org/openo | |
parent | b74fa798b62bfa5b45e567c9b2c9c57b5dae97ad (diff) |
Fix register micro service code
Issue-ID:HOLMES-50
Change-Id: I02ccf2ea367e4d2be3f2a4d034a1c960d2c28915
Signed-off-by: youbowu <wu.youbo@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java/org/openo')
-rw-r--r-- | holmes-actions/src/main/java/org/openo/holmes/common/utils/MSBRegisterUtil.java | 14 |
1 files changed, 12 insertions, 2 deletions
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 |