X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=holmes-actions%2Fsrc%2Fmain%2Fjava%2Forg%2Fopeno%2Fholmes%2Fcommon%2Futils%2FMSBRegisterUtil.java;h=5e806e418f49ec9e13bbd473cc8a0de1a74178f4;hb=31c419d91ab4f6b5644e1cb9c7a477038fbd3dea;hp=fc5e88213948a4bacc5566bcffff075bc91ff606;hpb=b74fa798b62bfa5b45e567c9b2c9c57b5dae97ad;p=holmes%2Fcommon.git 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..5e806e4 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; @@ -40,10 +41,11 @@ public class MSBRegisterUtil { ObjectMapper mapper = new ObjectMapper(); String content = mapper.writeValueAsString(entity); HttpPost httpPost = new HttpPost("http://" + MicroServiceConfig.getMsbServerAddr() - + ":8086/api/microservices/v1/services?createOrUpdate=false"); + + "/api/microservices/v1/services?createOrUpdate=false"); if (StringUtils.isNotEmpty(content)) { httpPost.setEntity(new ByteArrayEntity(content.getBytes())); } + this.setHeader(httpPost); HttpResponse response; try { response = httpClient.execute(httpPost); @@ -51,16 +53,23 @@ public class MSBRegisterUtil { log.warn("Registering the service to the bus failure", e); return false; } - if (response.getStatusLine().getStatusCode() == AlarmConst.RESPONSE_STATUS_OK) { + if (response.getStatusLine().getStatusCode() == AlarmConst.MICRO_SERVICE_STATUS_SUCCESS) { 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()); 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