Fix simple sonar issues in policy-endpoints 23/44023/2
authorJim Hahn <jrh3@att.com>
Fri, 20 Apr 2018 21:44:29 +0000 (17:44 -0400)
committerJim Hahn <jrh3@att.com>
Fri, 20 Apr 2018 21:55:41 +0000 (17:55 -0400)
Fixed various sonar issues.  Did not fix issues in BusConsumer,
as that has an update that is yet to be merged.
Update license dates.

Change-Id: I393dbb3852a218a62129f59cc84886fb10122ee1
Issue-ID: POLICY-728
Signed-off-by: Jim Hahn <jrh3@att.com>
13 files changed:
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusTopicBase.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineBusTopicSink.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineDmaapTopicSink.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/InlineUebTopicSink.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedUebTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/TopicBase.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServerFactory.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java

index 8e18bba..1efaa06 100644 (file)
@@ -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);
                        }
                        
index f145f3b..0bf3d44 100644 (file)
@@ -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() {
index f86c27c..a50d7b1 100644 (file)
@@ -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 + "]";
        }
 }
index 718bb21..48116e3 100644 (file)
@@ -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() + "]";
        }
 
 }
index 0c01c8b..d1218f3 100644 (file)
@@ -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);
        }
        
index 5e8cf48..768046d 100644 (file)
 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
@@ -73,24 +71,11 @@ 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();
        }
index b0c456d..6a9a2d6 100644 (file)
@@ -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,
index e394e3d..fcbee63 100644 (file)
@@ -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, 
index b1b2980..22c6b1d 100644 (file)
@@ -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);
                
index 9b18cae..6a254e2 100644 (file)
@@ -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;
                }
index a40bad9..3cd702a 100644 (file)
@@ -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();
 }
index 8c35602..f4dc85b 100644 (file)
@@ -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();
index 4f7c151..0cbd983 100644 (file)
  */
 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;
 
 /**