diff options
author | Guangrong Fu <fu.guangrong@zte.com.cn> | 2017-03-09 09:12:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@open-o.org> | 2017-03-09 09:12:18 +0000 |
commit | 46c009200583a0e5551e5de1cfc91c8b0b3e42cb (patch) | |
tree | 86666cd51f71ea8cee6000a74acfdf6f45ea5bae /holmes-actions | |
parent | 9a197a9d3edf2d0ef24a3b2f417e918cff07dab5 (diff) | |
parent | 64b3168e1993689c9003ee43b3ae5811b626c866 (diff) |
Merge "Fix register micro service code"
Diffstat (limited to 'holmes-actions')
-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 |