aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Hernandez <jh1730@att.com>2018-04-23 12:17:52 +0000
committerGerrit Code Review <gerrit@onap.org>2018-04-23 12:17:52 +0000
commite7e6522970a2c3b81581fb74bb565d382dc0f1ab (patch)
tree2c3461aab75424c027383a01b0517b38113c0b2f
parentaa6aea30f8d356ccbe9b649eb2416f5955e25534 (diff)
parent519f28e35025d0bab6a0c8bfcfb1d1efd592e953 (diff)
Merge "Fix simple sonar issues in policy-endpoints"
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java28
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusTopicBase.java27
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java38
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java20
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java7
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java50
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java15
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java7
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/TopicBase.java9
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java28
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java16
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java34
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java6
13 files changed, 128 insertions, 157 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
index 8e18bba8..1efaa063 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
@@ -147,9 +147,7 @@ public interface BusPublisher {
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("CambriaPublisherWrapper []");
- return builder.toString();
+ return "CambriaPublisherWrapper []";
}
}
@@ -287,15 +285,10 @@ public interface BusPublisher {
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("DmaapPublisherWrapper [").
- append("publisher.getAuthDate()=").append(publisher.getAuthDate()).
- append(", publisher.getAuthKey()=").append(publisher.getAuthKey()).
- append(", publisher.getHost()=").append(publisher.getHost()).
- append(", publisher.getProtocolFlag()=").append(publisher.getProtocolFlag()).
- append(", publisher.getUsername()=").append(publisher.getUsername()).
- append("]");
- return builder.toString();
+ return "DmaapPublisherWrapper [" + "publisher.getAuthDate()=" + publisher.getAuthDate()
+ + ", publisher.getAuthKey()=" + publisher.getAuthKey() + ", publisher.getHost()="
+ + publisher.getHost() + ", publisher.getProtocolFlag()=" + publisher.getProtocolFlag()
+ + ", publisher.getUsername()=" + publisher.getUsername() + "]";
}
}
@@ -329,13 +322,16 @@ public interface BusPublisher {
String dme2RouteOffer = additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY);
- if (environment == null || environment.isEmpty()) {
+ if (environment == null || environment.isEmpty()) {
throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX);
- } if (aftEnvironment == null || aftEnvironment.isEmpty()) {
+ }
+ if (aftEnvironment == null || aftEnvironment.isEmpty()) {
throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX);
- } if (latitude == null || latitude.isEmpty()) {
+ }
+ if (latitude == null || latitude.isEmpty()) {
throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX);
- } if (longitude == null || longitude.isEmpty()) {
+ }
+ if (longitude == null || longitude.isEmpty()) {
throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX);
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusTopicBase.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusTopicBase.java
index f145f3b8..0bf3d445 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusTopicBase.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusTopicBase.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -67,8 +67,7 @@ public abstract class BusTopicBase extends TopicBase implements ApiKeyEnabled {
String apiKey,
String apiSecret,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
super(servers, topic);
@@ -102,6 +101,26 @@ public abstract class BusTopicBase extends TopicBase implements ApiKeyEnabled {
return allowSelfSignedCerts;
}
+ protected boolean anyNullOrEmpty(String... args) {
+ for (String arg : args) {
+ if (arg == null || arg.isEmpty()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean allNullOrEmpty(String... args) {
+ for (String arg : args) {
+ if (!(arg == null || arg.isEmpty())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
@Override
public String toString() {
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java
index f86c27c7..a50d7b10 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -63,8 +63,7 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi
* @throws IllegalArgumentException in invalid parameters are passed in
*/
public InlineBusTopicSink(List<String> servers, String topic,
- String apiKey, String apiSecret, String partitionId, boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ String apiKey, String apiSecret, String partitionId, boolean useHttps, boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret, useHttps, allowSelfSignedCerts);
@@ -82,7 +81,7 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi
* {@inheritDoc}
*/
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
logger.info("{}: starting", this);
synchronized(this) {
@@ -132,7 +131,7 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi
* {@inheritDoc}
*/
@Override
- public boolean send(String message) throws IllegalArgumentException, IllegalStateException {
+ public boolean send(String message) {
if (message == null || message.isEmpty()) {
throw new IllegalArgumentException("Message to send is empty");
@@ -181,16 +180,33 @@ public abstract class InlineBusTopicSink extends BusTopicBase implements BusTopi
* {@inheritDoc}
*/
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
this.stop();
}
+
+ protected boolean anyNullOrEmpty(String... args) {
+ for (String arg : args) {
+ if (arg == null || arg.isEmpty()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean allNullOrEmpty(String... args) {
+ for (String arg : args) {
+ if (!(arg == null || arg.isEmpty())) {
+ return false;
+ }
+ }
+
+ return true;
+ }
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("InlineBusTopicSink [partitionId=").append(partitionId).append(", alive=").append(alive)
- .append(", publisher=").append(publisher).append("]");
- return builder.toString();
+ return "InlineBusTopicSink [partitionId=" + partitionId + ", alive=" + alive + ", publisher=" + publisher + "]";
}
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
index 718bb21d..48116e34 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
@@ -75,8 +75,7 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop
String partitionKey,
String environment, String aftEnvironment, String partner,
String latitude, String longitude, Map<String,String> additionalProps,
- boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean useHttps, boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret, partitionKey, useHttps, allowSelfSignedCerts);
@@ -96,8 +95,7 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop
public InlineDmaapTopicSink(List<String> servers, String topic,
String apiKey, String apiSecret,
String userName, String password,
- String partitionKey, boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ String partitionKey, boolean useHttps, boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret, partitionKey, useHttps, allowSelfSignedCerts);
@@ -108,11 +106,7 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop
@Override
public void init() {
- if ((this.environment == null || this.environment.isEmpty()) &&
- (this.aftEnvironment == null || this.aftEnvironment.isEmpty()) &&
- (this.latitude == null || this.latitude.isEmpty()) &&
- (this.longitude == null || this.longitude.isEmpty()) &&
- (this.partner == null || this.partner.isEmpty())) {
+ if (allNullOrEmpty(this.environment, this.aftEnvironment, this.latitude, this.longitude, this.partner)) {
this.publisher =
new BusPublisher.CambriaPublisherWrapper(this.servers,
this.topic,
@@ -142,11 +136,9 @@ public class InlineDmaapTopicSink extends InlineBusTopicSink implements DmaapTop
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("InlineDmaapTopicSink [userName=").append(userName).append(", password=").append(password)
- .append(", getTopicCommInfrastructure()=").append(getTopicCommInfrastructure()).append(", toString()=")
- .append(super.toString()).append("]");
- return builder.toString();
+ return "InlineDmaapTopicSink [userName=" + userName + ", password=" + password
+ + ", getTopicCommInfrastructure()=" + getTopicCommInfrastructure() + ", toString()="
+ + super.toString() + "]";
}
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java
index 0c01c8b5..d1218f3f 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,8 +57,7 @@ public class InlineUebTopicSink extends InlineBusTopicSink implements UebTopicSi
String apiSecret,
String partitionId,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret, partitionId, useHttps, allowSelfSignedCerts);
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
index 5e8cf489..768046d0 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
@@ -21,17 +21,15 @@
package org.onap.policy.drools.event.comm.bus.internal;
import java.net.MalformedURLException;
-import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.onap.policy.drools.event.comm.FilterableTopicSource;
import org.onap.policy.drools.event.comm.TopicListener;
import org.onap.policy.drools.event.comm.bus.BusTopicSource;
import org.onap.policy.drools.event.comm.bus.internal.BusConsumer.FilterableBusConsumer;
import org.onap.policy.drools.utils.NetworkUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This topic source implementation specializes in reading messages
@@ -74,23 +72,10 @@ public abstract class SingleThreadedBusTopicSource
protected BusConsumer consumer;
/**
- * Am I running?
- * reflects invocation of start()/stop()
- * !locked & start() => alive
- * stop() => !alive
- */
- protected volatile boolean alive = false;
-
- /**
* Independent thread reading message over my topic
*/
protected Thread busPollerThread;
- /**
- * All my subscribers for new message notifications
- */
- protected final ArrayList<TopicListener> topicListeners = new ArrayList<>();
-
/**
*
@@ -115,8 +100,7 @@ public abstract class SingleThreadedBusTopicSource
int fetchTimeout,
int fetchLimit,
boolean useHttps,
- boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret, useHttps, allowSelfSignedCerts);
@@ -152,8 +136,7 @@ public abstract class SingleThreadedBusTopicSource
public abstract void init() throws MalformedURLException;
@Override
- public void register(TopicListener topicListener)
- throws IllegalArgumentException {
+ public void register(TopicListener topicListener) {
super.register(topicListener);
@@ -182,7 +165,7 @@ public abstract class SingleThreadedBusTopicSource
}
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
logger.info("{}: starting", this);
synchronized(this) {
@@ -299,23 +282,10 @@ public abstract class SingleThreadedBusTopicSource
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
- builder.append("SingleThreadedBusTopicSource [consumerGroup=").append(consumerGroup)
- .append(", consumerInstance=").append(consumerInstance).append(", fetchTimeout=").append(fetchTimeout)
- .append(", fetchLimit=").append(fetchLimit)
- .append(", consumer=").append(this.consumer).append(", alive=")
- .append(alive).append(", locked=").append(locked).append(", uebThread=").append(busPollerThread)
- .append(", topicListeners=").append(topicListeners.size()).append(", toString()=").append(super.toString())
- .append("]");
- return builder.toString();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean isAlive() {
- return alive;
+ return "SingleThreadedBusTopicSource [consumerGroup=" + consumerGroup + ", consumerInstance=" + consumerInstance
+ + ", fetchTimeout=" + fetchTimeout + ", fetchLimit=" + fetchLimit + ", consumer="
+ + this.consumer + ", alive=" + alive + ", locked=" + locked + ", uebThread=" + busPollerThread
+ + ", topicListeners=" + topicListeners.size() + ", toString()=" + super.toString() + "]";
}
/**
@@ -338,7 +308,7 @@ public abstract class SingleThreadedBusTopicSource
* {@inheritDoc}
*/
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
this.stop();
this.topicListeners.clear();
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
index b0c456da..6a9a2d6d 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
@@ -79,8 +79,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
int fetchTimeout, int fetchLimit,
String environment, String aftEnvironment, String partner,
String latitude, String longitude, Map<String,String> additionalProps,
- boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ boolean useHttps, boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret,
consumerGroup, consumerInstance,
@@ -123,8 +122,7 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
String apiKey, String apiSecret,
String userName, String password,
String consumerGroup, String consumerInstance,
- int fetchTimeout, int fetchLimit, boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ int fetchTimeout, int fetchLimit, boolean useHttps, boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret,
@@ -148,19 +146,14 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
*/
@Override
public void init() throws MalformedURLException {
- if (this.userName == null || this.userName.isEmpty() ||
- this.password == null || this.password.isEmpty()) {
+ if (anyNullOrEmpty(this.userName, this.password)) {
this.consumer =
new BusConsumer.CambriaConsumerWrapper(this.servers, this.topic,
this.apiKey, this.apiSecret,
this.consumerGroup, this.consumerInstance,
this.fetchTimeout, this.fetchLimit,
this.useHttps, this.allowSelfSignedCerts);
- } else if ((this.environment == null || this.environment.isEmpty()) &&
- (this.aftEnvironment == null || this.aftEnvironment.isEmpty()) &&
- (this.latitude == null || this.latitude.isEmpty()) &&
- (this.longitude == null || this.longitude.isEmpty()) &&
- (this.partner == null || this.partner.isEmpty())) {
+ } else if (allNullOrEmpty(this.environment, this.aftEnvironment, this.latitude, this.longitude, this.partner)) {
this.consumer =
new BusConsumer.CambriaConsumerWrapper(this.servers, this.topic,
this.apiKey, this.apiSecret,
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java
index e394e3df..fcbee631 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,8 +52,7 @@ public class SingleThreadedUebTopicSource extends SingleThreadedBusTopicSource
public SingleThreadedUebTopicSource(List<String> servers, String topic,
String apiKey, String apiSecret,
String consumerGroup, String consumerInstance,
- int fetchTimeout, int fetchLimit, boolean useHttps, boolean allowSelfSignedCerts)
- throws IllegalArgumentException {
+ int fetchTimeout, int fetchLimit, boolean useHttps, boolean allowSelfSignedCerts) {
super(servers, topic, apiKey, apiSecret,
consumerGroup, consumerInstance,
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/TopicBase.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/TopicBase.java
index b1b29808..22c6b1d5 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/TopicBase.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/TopicBase.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -82,7 +82,7 @@ public abstract class TopicBase implements Topic {
* @return a Topic Base
* @throws IllegalArgumentException if invalid parameters are present
*/
- public TopicBase(List<String> servers, String topic) throws IllegalArgumentException {
+ public TopicBase(List<String> servers, String topic) {
if (servers == null || servers.isEmpty()) {
throw new IllegalArgumentException("Server(s) must be provided");
@@ -97,8 +97,7 @@ public abstract class TopicBase implements Topic {
}
@Override
- public void register(TopicListener topicListener)
- throws IllegalArgumentException {
+ public void register(TopicListener topicListener) {
logger.info("{}: registering {}", this, topicListener);
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
index 9b18cae0..6a254e2e 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,21 +25,16 @@ import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
-
-import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
-
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.onap.policy.drools.http.client.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import com.fasterxml.jackson.annotation.JsonIgnore;
public class JerseyClient implements HttpClient {
@@ -99,17 +94,18 @@ public class JerseyClient implements HttpClient {
if (this.selfSignedCerts) {
sslContext.init(null, new TrustManager[]{new X509TrustManager() {
@Override
- public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
+ public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ // always trusted
+ }
@Override
- public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {}
+ public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
+ // always trusted
+ }
@Override
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
}}, new SecureRandom());
- clientBuilder = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(new HostnameVerifier() {
- @Override
- public boolean verify(String hostname, SSLSession session) {return true;}
- });
+ clientBuilder = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier((host,session) -> true);
} else {
sslContext.init(null, null, null);
clientBuilder = ClientBuilder.newBuilder().sslContext(sslContext);
@@ -147,17 +143,17 @@ public class JerseyClient implements HttpClient {
@Override
- public boolean start() throws IllegalStateException {
+ public boolean start() {
return alive;
}
@Override
- public boolean stop() throws IllegalStateException {
+ public boolean stop() {
return !alive;
}
@Override
- public void shutdown() throws IllegalStateException {
+ public void shutdown() {
synchronized(this) {
alive = false;
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java
index a40bad91..3cd702ae 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,6 +25,12 @@ import org.onap.policy.drools.properties.Startable;
* A Jetty Server to server REST Requests
*/
public interface HttpServletServer extends Startable {
+
+
+ /**
+ * factory for managing and tracking DMAAP sources
+ */
+ public static HttpServletServerFactory factory = new IndexedHttpServletServerFactory();
/**
*
@@ -73,10 +79,4 @@ public interface HttpServletServer extends Startable {
* @throws InterruptedException if the blocking operation is interrupted
*/
public boolean waitedStart(long maxWaitTime) throws InterruptedException;
-
-
- /**
- * factory for managing and tracking DMAAP sources
- */
- public static HttpServletServerFactory factory = new IndexedHttpServletServerFactory();
}
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java
index 8c35602b..f4dc85bc 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java
@@ -1,8 +1,8 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* policy-endpoints
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +48,7 @@ public interface HttpServletServerFactory {
* @throws IllegalArgumentException when invalid parameters are provided
*/
public HttpServletServer build(String name, String host, int port, String contextPath,
- boolean swagger, boolean managed)
- throws IllegalArgumentException;
+ boolean swagger, boolean managed);
/**
* list of http servers per properties
@@ -58,7 +57,7 @@ public interface HttpServletServerFactory {
* @return list of http servers
* @throws IllegalArgumentException when invalid parameters are provided
*/
- public List<HttpServletServer> build(Properties properties) throws IllegalArgumentException;
+ public List<HttpServletServer> build(Properties properties);
/**
* gets a server based on the port
@@ -92,7 +91,9 @@ public interface HttpServletServerFactory {
*/
class IndexedHttpServletServerFactory implements HttpServletServerFactory {
- /**
+ private static final String SPACES_COMMA_SPACES = "\\s*,\\s*";
+
+ /**
* logger
*/
protected static Logger logger = LoggerFactory.getLogger(IndexedHttpServletServerFactory.class);
@@ -105,8 +106,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
@Override
public synchronized HttpServletServer build(String name, String host, int port,
String contextPath, boolean swagger,
- boolean managed)
- throws IllegalArgumentException {
+ boolean managed) {
if (servers.containsKey(port))
return servers.get(port);
@@ -119,8 +119,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
@Override
- public synchronized List<HttpServletServer> build(Properties properties)
- throws IllegalArgumentException {
+ public synchronized List<HttpServletServer> build(Properties properties) {
ArrayList<HttpServletServer> serviceList = new ArrayList<>();
@@ -130,8 +129,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
return serviceList;
}
- List<String> serviceNameList =
- new ArrayList<>(Arrays.asList(serviceNames.split("\\s*,\\s*")));
+ List<String> serviceNameList = Arrays.asList(serviceNames.split(SPACES_COMMA_SPACES));
for (String serviceName : serviceNameList) {
String servicePortString = properties.getProperty(PolicyProperties.PROPERTY_HTTP_SERVER_SERVICES + "." +
@@ -205,15 +203,13 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
if (restClasses != null && !restClasses.isEmpty()) {
- List<String> restClassesList =
- new ArrayList<>(Arrays.asList(restClasses.split("\\s*,\\s*")));
+ List<String> restClassesList = Arrays.asList(restClasses.split(SPACES_COMMA_SPACES));
for (String restClass : restClassesList)
service.addServletClass(restUriPath, restClass);
}
if (restPackages != null && !restPackages.isEmpty()) {
- List<String> restPackageList =
- new ArrayList<>(Arrays.asList(restPackages.split("\\s*,\\s*")));
+ List<String> restPackageList = Arrays.asList(restPackages.split(SPACES_COMMA_SPACES));
for (String restPackage : restPackageList)
service.addServletPackage(restUriPath, restPackage);
}
@@ -225,7 +221,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
@Override
- public synchronized HttpServletServer get(int port) throws IllegalArgumentException {
+ public synchronized HttpServletServer get(int port) {
if (servers.containsKey(port)) {
return servers.get(port);
@@ -240,7 +236,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
@Override
- public synchronized void destroy(int port) throws IllegalArgumentException, IllegalStateException {
+ public synchronized void destroy(int port) {
if (!servers.containsKey(port)) {
return;
@@ -251,7 +247,7 @@ class IndexedHttpServletServerFactory implements HttpServletServerFactory {
}
@Override
- public synchronized void destroy() throws IllegalArgumentException, IllegalStateException {
+ public synchronized void destroy() {
List<HttpServletServer> httpServletServers = this.inventory();
for (HttpServletServer server: httpServletServers) {
server.shutdown();
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java
index 4f7c151e..0cbd983d 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java
@@ -19,15 +19,11 @@
*/
package org.onap.policy.drools.http.server.internal;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.util.HashMap;
-
import org.eclipse.jetty.servlet.ServletHolder;
import org.onap.policy.drools.utils.NetworkUtil;
-import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
-
+import org.slf4j.LoggerFactory;
import io.swagger.jersey.config.JerseyJaxrsConfig;
/**