aboutsummaryrefslogtreecommitdiffstats
path: root/sdclient/discovery-service/src/main/java
diff options
context:
space:
mode:
authorHuabing Zhao <zhaohuabing@gmail.com>2019-03-18 17:10:17 +0800
committerHuabing Zhao <zhaohuabing@gmail.com>2019-03-18 19:08:41 +0800
commit28a0408d050ad5cd10a87088ffdc913b8f4487ab (patch)
tree0641b97b281fbded49338c3e1db803e9b5069a17 /sdclient/discovery-service/src/main/java
parentbb42b10ae85a76fad88a30f50334d6c27cbf4a8b (diff)
Update consul version to 1.4.3
Change-Id: I264fe52ec5e2d6b45298c5c01be427a27116ecb6 Issue-ID: MSB-325 Signed-off-by: Huabing Zhao <zhaohuabing@gmail.com>
Diffstat (limited to 'sdclient/discovery-service/src/main/java')
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulAgentServiceWrapper.java4
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulCatalogServiceWrapper.java4
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java29
3 files changed, 33 insertions, 4 deletions
diff --git a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulAgentServiceWrapper.java b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulAgentServiceWrapper.java
index 114a675..3da17d4 100644
--- a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulAgentServiceWrapper.java
+++ b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulAgentServiceWrapper.java
@@ -42,7 +42,7 @@ public class ConsulAgentServiceWrapper {
int registerResult =
- HttpClientUtil.httpPostWithJSON(consulRegisterurl, JacksonJsonUtil.beanToJson(agentService));
+ HttpClientUtil.httpPutWithJSON(consulRegisterurl, JacksonJsonUtil.beanToJson(agentService));
return registerResult;
@@ -52,7 +52,7 @@ public class ConsulAgentServiceWrapper {
String consulDelurl = (new StringBuilder().append("http://").append(ConfigUtil.getInstance().getConsulAddress())
.append(DiscoverUtil.CONSUL_AGENT_URL).append("/deregister/").append(serviceId)).toString();
- int delResult = HttpClientUtil.httpPostWithJSON(consulDelurl, "");
+ int delResult = HttpClientUtil.httpPutWithJSON(consulDelurl, "");
return delResult;
}
diff --git a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulCatalogServiceWrapper.java b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulCatalogServiceWrapper.java
index d3b0bf4..f8ad593 100644
--- a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulCatalogServiceWrapper.java
+++ b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/ConsulCatalogServiceWrapper.java
@@ -45,7 +45,7 @@ public class ConsulCatalogServiceWrapper {
int registerResult =
- HttpClientUtil.httpPostWithJSON(consulRegisterurl, JacksonJsonUtil.beanToJson(catalogNode));
+ HttpClientUtil.httpPutWithJSON(consulRegisterurl, JacksonJsonUtil.beanToJson(catalogNode));
return registerResult;
@@ -58,7 +58,7 @@ public class ConsulCatalogServiceWrapper {
String nodeJson =
"{\"Node\": \"" + DiscoverUtil.EXTERNAL_NODE_NAME + "\",\"ServiceID\": \"" + serviceId + "\"}";
- int delResult = HttpClientUtil.httpPostWithJSON(consulDelurl, nodeJson);
+ int delResult = HttpClientUtil.httpPutWithJSON(consulDelurl, nodeJson);
return delResult;
}
diff --git a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java
index c91ee98..106653b 100644
--- a/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java
+++ b/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java
@@ -26,6 +26,7 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -40,6 +41,34 @@ public class HttpClientUtil {
private static final Logger logger = LoggerFactory.getLogger(HttpClientUtil.class);
+ public static int httpPutWithJSON(String url, String params) {
+ int result = 0;
+ CloseableHttpClient httpClient = HttpClients.createDefault();
+ HttpPut httpPut = new HttpPut(url);
+ httpPut.addHeader("Content-type", "application/json; charset=utf-8");
+ httpPut.setHeader("Accept", "application/json");
+ httpPut.setEntity(new StringEntity(params, Charset.forName("UTF-8")));
+ try {
+ CloseableHttpResponse res = httpClient.execute(httpPut);
+ result = res.getStatusLine().getStatusCode();
+ if (res.getStatusLine().getStatusCode() != 200) {
+ logger.error(String.valueOf(result));
+ }
+ res.close();
+ } catch (IOException e) {
+ String errorMsg = url + ":httpPutWithJSON connect faild";
+ } finally {
+ try {
+ httpClient.close();
+ } catch (IOException e) {
+ String errorMsg = url + ":close httpClient faild";
+ }
+ }
+
+ return result;
+
+ }
+
public static int httpPostWithJSON(String url, String params) {
int result = 0;
CloseableHttpClient httpClient = HttpClients.createDefault();