import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.Response;
+import java.util.UUID;
+
import lombok.Getter;
import lombok.Setter;
-import org.glassfish.jersey.client.ClientConfig;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
import org.onap.holmes.common.api.stat.VesAlarm;
import org.onap.holmes.common.dropwizard.ioc.utils.ServiceLocatorHolder;
import org.onap.holmes.common.exception.CorrelationException;
+import org.onap.holmes.common.utils.GsonUtil;
+import org.onap.holmes.common.utils.HttpsUtils;
@Getter
@Setter
+@Slf4j
public class Subscriber {
private DMaaPResponseUtil dMaaPResponseUtil = ServiceLocatorHolder.getLocator()
* The number of milliseconds to poll interval time. This should normally be used, and set at
* 15000 or higher.
*/
- private int period = 15000;
+ private int period = timeout;
private boolean secure;
private String topic;
private String url;
- private String consumerGroup = "homlesGrounp1";
- private String consumer = "homlesGrounp1";
+ private String uuid = UUID.randomUUID() + "";
+ private String consumerGroup = "homlesGroup" + uuid;
+ private String consumer = "homles" + uuid;
private String authInfo;
private String authExpDate;
try {
response = getDMaaPData();
} catch (Exception e) {
- throw new CorrelationException("Failed to get DMapp data.", e);
+ throw new CorrelationException("Failed to get data from DMaaP.", e);
}
try {
return extractVesAlarm(response);
}
}
- private List<String> getDMaaPData() {
- Client client = ClientBuilder.newClient(new ClientConfig());
- WebTarget webTarget = client.target(url + "/" + consumerGroup + "/" + consumer);
- Response response = webTarget.request().get();
- return response.readEntity(List.class);
+ private List<String> getDMaaPData() throws Exception {
+ String response;
+ CloseableHttpClient closeableHttpClient = null;
+ HttpGet httpGet = new HttpGet(url + "/" + consumerGroup + "/" + consumer + "?timeout=" + period);
+ try {
+ closeableHttpClient = HttpsUtils.getHttpClient(timeout);
+ HttpResponse httpResponse = HttpsUtils
+ .get(httpGet, new HashMap<>(), closeableHttpClient);
+ response = HttpsUtils.extractResponseEntity(httpResponse);
+ } catch (Exception e) {
+ throw e;
+ } finally {
+ httpGet.releaseConnection();
+ if (closeableHttpClient != null) {
+ try {
+ closeableHttpClient.close();
+ } catch (IOException e) {
+ log.warn("Failed to close http client!");
+ }
+ }
+ }
+ return GsonUtil.jsonToBean(response, List.class);
}
private List<VesAlarm> extractVesAlarm(List<String> responseEntity) throws IOException {