summaryrefslogtreecommitdiffstats
path: root/holmes-actions/src/main/java
diff options
context:
space:
mode:
authorGuangrongFu <fu.guangrong@zte.com.cn>2021-06-08 10:17:05 +0800
committerGuangrongFu <fu.guangrong@zte.com.cn>2021-06-08 10:17:05 +0800
commit4242b93bdf5079fee5339a50d8126e4ea56ad9b6 (patch)
treeba6b5e16e773c057b3371d595494163540910422 /holmes-actions/src/main/java
parent7218f0b8e91bc61b6f5a9db44f706da1bf669f4b (diff)
Refactored JerseyClient
Change-Id: I0a6c83b50380affdc723c07df0b1ca41947a3d8e Issue-ID: HOLMES-442 Signed-off-by: GuangrongFu <fu.guangrong@zte.com.cn>
Diffstat (limited to 'holmes-actions/src/main/java')
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java4
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java4
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java2
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java17
-rw-r--r--holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java2
5 files changed, 17 insertions, 12 deletions
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
index 4a4ffcb..a73eb22 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQuery.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2017 ZTE Corporation.
+ * Copyright 2017 - 2021 ZTE Corporation.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
@@ -92,7 +92,7 @@ public class AaiQuery {
private String getResponse(String url) throws CorrelationException {
try {
- return new JerseyClient().headers(getHeaders()).get(url);
+ return JerseyClient.newInstance().headers(getHeaders()).get(url);
} catch (Exception e) {
throw new CorrelationException("Failed to get data from aai", e);
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java
index 892638b..c557003 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/aai/AaiQueryMdons.java
@@ -66,7 +66,7 @@ public class AaiQueryMdons {
private String getResponse(String url) throws CorrelationException {
try {
- return new JerseyClient().headers(getHeaders()).get(url);
+ return JerseyClient.newInstance().headers(getHeaders()).get(url);
} catch (Exception e) {
throw new CorrelationException("Failed to get data from aai", e);
}
@@ -174,7 +174,7 @@ public class AaiQueryMdons {
private void put(String url, String content) throws CorrelationException {
try {
- new JerseyClient().headers(getHeaders()).put(url, Entity.json(content));
+ JerseyClient.newInstance().headers(getHeaders()).put(url, Entity.json(content));
} catch (Exception e) {
throw new CorrelationException("Failed to put data in AAI", e);
}
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
index a4024ea..23a04d6 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/dmaap/Publisher.java
@@ -29,7 +29,7 @@ import java.util.concurrent.TimeUnit;
@Service
public class Publisher {
private String url;
- private JerseyClient client = new JerseyClient(TimeUnit.SECONDS.toMillis(30));
+ private JerseyClient client = JerseyClient.newInstance(TimeUnit.SECONDS.toMillis(30));
public void publish(PolicyMsg msg) {
client.post(url, Entity.json(msg));
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java
index 09d9f64..cd87ebe 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/JerseyClient.java
@@ -16,7 +16,6 @@
package org.onap.holmes.common.utils;
-import org.eclipse.jetty.http.HttpStatus;
import org.onap.holmes.common.exception.HttpException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,12 +62,19 @@ public class JerseyClient {
private Map<String, Object> parameters = new HashMap();
private List<String> paths = new ArrayList();
+ public static JerseyClient newInstance() {
+ return new JerseyClient();
+ }
+
+ public static JerseyClient newInstance(long timeout) {
+ return new JerseyClient(timeout);
+ }
- public JerseyClient() {
+ private JerseyClient() {
this(DEFAULT_TIMEOUT);
}
- public JerseyClient(long timeout) {
+ private JerseyClient(long timeout) {
this.client = ClientBuilder.newBuilder()
.connectTimeout(timeout, TimeUnit.MILLISECONDS)
.readTimeout(timeout, TimeUnit.MILLISECONDS)
@@ -189,9 +195,8 @@ public class JerseyClient {
}
private boolean isSuccessful(Response response) {
- int status = response.getStatus();
- if (!HttpStatus.isSuccess(status)) {
- throw new HttpException(status, String.format("Failed to get response from the server. Info: %s",
+ if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
+ throw new HttpException(response.getStatus(), String.format("Failed to get response from the server. Info: %s",
response.readEntity(String.class)));
}
return true;
diff --git a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
index ff5b48a..79ccbdc 100644
--- a/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
+++ b/holmes-actions/src/main/java/org/onap/holmes/common/utils/MsbRegister.java
@@ -36,7 +36,7 @@ import static org.onap.holmes.common.utils.JerseyClient.PROTOCOL_HTTPS;
public class MsbRegister {
private static final Logger log = LoggerFactory.getLogger(MsbRegister.class);
- private JerseyClient client = new JerseyClient();
+ private JerseyClient client = JerseyClient.newInstance();
public MsbRegister() {
}