aboutsummaryrefslogtreecommitdiffstats
path: root/sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java')
-rw-r--r--sdclient/discovery-service/src/main/java/org/onap/msb/sdclient/wrapper/util/HttpClientUtil.java29
1 files changed, 29 insertions, 0 deletions
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();