From e173fc5ab13b095d8f70fd8a8d4d063adeba6e6b Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 5 Jul 2019 10:52:20 -0400 Subject: Fix sonar issues in policy/endpoints Sonar fixes, other than code coverage. These changes are disruptive and will likely cause breakage in a number of policy repos. Renamed constants. Moved constants/factories from interfaces to classes. Change-Id: I182d50320aa6b53e383081af806c60dd2f806cbe Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn --- .../common/endpoints/http/client/HttpClient.java | 9 +---- .../http/client/HttpClientConfigException.java | 44 ++++++++++++++++++++++ .../endpoints/http/client/HttpClientFactory.java | 17 ++++----- .../http/client/HttpClientFactoryInstance.java | 37 ++++++++++++++++++ .../http/client/IndexedHttpClientFactory.java | 14 ++++--- .../endpoints/http/server/HttpServletServer.java | 28 ++++++-------- .../server/HttpServletServerFactoryInstance.java | 38 +++++++++++++++++++ 7 files changed, 147 insertions(+), 40 deletions(-) create mode 100644 policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientConfigException.java create mode 100644 policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactoryInstance.java create mode 100644 policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactoryInstance.java (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http') diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java index 2e3b9afb..2fe46fb3 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClient.java @@ -7,9 +7,9 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -32,11 +32,6 @@ import org.onap.policy.common.capabilities.Startable; */ public interface HttpClient extends Startable { - /** - * Factory. - */ - HttpClientFactory factory = new IndexedHttpClientFactory(); - /** * GET request. * diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientConfigException.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientConfigException.java new file mode 100644 index 00000000..98ec576f --- /dev/null +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientConfigException.java @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.endpoints.http.client; + +/** + * Exception generated by HttpClient builder. + */ +public class HttpClientConfigException extends Exception { + private static final long serialVersionUID = 1L; + + public HttpClientConfigException() { + super(); + } + + public HttpClientConfigException(String message) { + super(message); + } + + public HttpClientConfigException(Throwable cause) { + super(cause); + } + + public HttpClientConfigException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java index 5f4c4c9d..b155f729 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactory.java @@ -8,9 +8,9 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,8 +21,6 @@ package org.onap.policy.common.endpoints.http.client; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; import java.util.List; import java.util.Properties; import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams; @@ -35,17 +33,16 @@ public interface HttpClientFactory { /** * Build and http client with the following parameters. */ - HttpClient build(BusTopicParams busTopicParams) - throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException; + HttpClient build(BusTopicParams busTopicParams) throws HttpClientConfigException; /** * Build http client from properties. */ - List build(Properties properties) throws KeyManagementException, NoSuchAlgorithmException; + List build(Properties properties) throws HttpClientConfigException; /** * Get http client. - * + * * @param name the name * @return the http client */ @@ -53,14 +50,14 @@ public interface HttpClientFactory { /** * List of http clients. - * + * * @return http clients */ List inventory(); /** * Destroy by name. - * + * * @param name name */ void destroy(String name); diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactoryInstance.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactoryInstance.java new file mode 100644 index 00000000..c2921640 --- /dev/null +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/HttpClientFactoryInstance.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.endpoints.http.client; + +import lombok.Getter; + +public class HttpClientFactoryInstance { + + /** + * The client factory. + */ + @Getter + private static final HttpClientFactory clientFactory = new IndexedHttpClientFactory(); + + + private HttpClientFactoryInstance() { + // do nothing + } +} diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/IndexedHttpClientFactory.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/IndexedHttpClientFactory.java index c2d0e400..edf8ff6f 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/IndexedHttpClientFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/client/IndexedHttpClientFactory.java @@ -47,14 +47,17 @@ class IndexedHttpClientFactory implements HttpClientFactory { protected HashMap clients = new HashMap<>(); @Override - public synchronized HttpClient build(BusTopicParams busTopicParams) - throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException { + public synchronized HttpClient build(BusTopicParams busTopicParams) throws HttpClientConfigException { if (clients.containsKey(busTopicParams.getClientName())) { return clients.get(busTopicParams.getClientName()); } - JerseyClient client = - new JerseyClient(busTopicParams); + JerseyClient client; + try { + client = new JerseyClient(busTopicParams); + } catch (KeyManagementException | NoSuchAlgorithmException | ClassNotFoundException e) { + throw new HttpClientConfigException(e); + } if (busTopicParams.isManaged()) { clients.put(busTopicParams.getClientName(), client); @@ -64,8 +67,7 @@ class IndexedHttpClientFactory implements HttpClientFactory { } @Override - public synchronized List build(Properties properties) - throws KeyManagementException, NoSuchAlgorithmException { + public synchronized List build(Properties properties) throws HttpClientConfigException { ArrayList clientList = new ArrayList<>(); String clientNames = properties.getProperty(PolicyEndPointProperties.PROPERTY_HTTP_CLIENT_SERVICES); diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java index b674e265..73b1e544 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServer.java @@ -7,9 +7,9 @@ * 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 - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,22 +27,16 @@ import org.onap.policy.common.capabilities.Startable; */ public interface HttpServletServer extends Startable { - - /** - * Factory of Http Servlet Servers. - */ - HttpServletServerFactory factory = new IndexedHttpServletServerFactory(); - /** * Get the port. - * + * * @return port */ int getPort(); /** * Enables basic authentication with user and password on the the relative path relativeUriPath. - * + * * @param user user * @param password password * @param relativeUriPath relative path @@ -63,7 +57,7 @@ public interface HttpServletServer extends Startable { /** * Sets the serialization provider to be used when classes are added to the service. - * + * * @param provider the provider to use for message serialization and de-serialization */ void setSerializationProvider(String provider); @@ -78,10 +72,10 @@ public interface HttpServletServer extends Startable { /** * Adds a JAX-RS servlet class to serve REST requests. - * + * * @param servletPath servlet path * @param restClass JAX-RS API Class - * + * * @throws IllegalArgumentException unable to process because of invalid input * @throws IllegalStateException unable to process because of invalid state */ @@ -89,10 +83,10 @@ public interface HttpServletServer extends Startable { /** * Adds a package containing JAX-RS classes to serve REST requests. - * + * * @param servletPath servlet path * @param restPackage JAX-RS package to scan - * + * * @throws IllegalArgumentException unable to process because of invalid input * @throws IllegalStateException unable to process because of invalid state */ @@ -100,10 +94,10 @@ public interface HttpServletServer extends Startable { /** * Blocking start of the http server. - * + * * @param maxWaitTime max time to wait for the start to take place * @return true if start was successful - * + * * @throws IllegalArgumentException if arguments are invalid * @throws InterruptedException if the blocking operation is interrupted */ diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactoryInstance.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactoryInstance.java new file mode 100644 index 00000000..a56be701 --- /dev/null +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/http/server/HttpServletServerFactoryInstance.java @@ -0,0 +1,38 @@ +/* + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.common.endpoints.http.server; + +import lombok.Getter; + +public class HttpServletServerFactoryInstance { + + /** + * The servlet factory. + */ + @Getter + private static final HttpServletServerFactory serverFactory = new IndexedHttpServletServerFactory(); + + + private HttpServletServerFactoryInstance() { + // do nothing + } + +} -- cgit 1.2.3-korg