From dffa54c9a27bcd9524e2aa75684ff02d70507b59 Mon Sep 17 00:00:00 2001 From: Pamela Dragosh Date: Thu, 26 Mar 2020 10:03:11 -0400 Subject: Remove unused imports and clean logs Unused imports and marked an unused variable. Added m2e eclipse settings (other repos have this). Added some test logback.xml to clear out jetty debug messages. Replaced deprecated newInstance with getDeclaredConstructor. newInstance Either log or throw Exception - chose throw Added some assertions to JUnit test. Issue-ID: POLICY-2305 Change-Id: Ia4e9ce62dc7fb45aea247d470ca7245e694fc26e Signed-off-by: Pamela Dragosh --- .../reception/handling/AbstractReceptionHandler.java | 3 ++- .../distribution/reception/handling/PluginHandler.java | 17 +++++++++++------ ...PolicyDecoderConfigurationParametersJsonAdapter.java | 2 +- ...eptionHandlerConfigurationParametersJsonAdapter.java | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) (limited to 'reception') diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java index 2ea18704..52c34cec 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/AbstractReceptionHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -85,7 +86,7 @@ public abstract class AbstractReceptionHandler implements ReceptionHandler { try { policyForwarder.forward(policies); } catch (final PolicyForwardingException policyForwardingException) { - LOGGER.error("Error when forwarding policies to " + policyForwarder, policyForwardingException); + LOGGER.error("Error when forwarding policies to {}", policyForwarder, policyForwardingException); } } } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java index f837e520..5067c841 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/handling/PluginHandler.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +22,7 @@ package org.onap.policy.distribution.reception.handling; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.Map; @@ -92,11 +94,13 @@ public class PluginHandler { final Class> policyDecoderClass = (Class>) Class .forName(decoderParameters.getDecoderClassName()); - final PolicyDecoder decoder = policyDecoderClass.newInstance(); + final PolicyDecoder decoder = + policyDecoderClass.getDeclaredConstructor().newInstance(); decoder.configure(decoderParameters.getDecoderConfigurationName()); policyDecoders.add(decoder); - } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) { - LOGGER.error("exception occured while initializing decoders", exp); + } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException | NoSuchMethodException + | SecurityException exp) { throw new PluginInitializationException(exp.getMessage(), exp.getCause()); } } @@ -116,11 +120,12 @@ public class PluginHandler { try { final Class policyForwarderClass = (Class) Class.forName(forwarderParameters.getForwarderClassName()); - final PolicyForwarder policyForwarder = policyForwarderClass.newInstance(); + final PolicyForwarder policyForwarder = policyForwarderClass.getDeclaredConstructor().newInstance(); policyForwarder.configure(forwarderParameters.getForwarderConfigurationName()); policyForwarders.add(policyForwarder); - } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException exp) { - LOGGER.error("exception occured while initializing forwarders", exp); + } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException + | IllegalArgumentException | InvocationTargetException | NoSuchMethodException + | SecurityException exp) { throw new PluginInitializationException(exp.getMessage(), exp.getCause()); } } diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java index c30d3d3d..b1c8053b 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/PolicyDecoderConfigurationParametersJsonAdapter.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -75,7 +76,6 @@ public class PolicyDecoderConfigurationParametersJsonAdapter } catch (final ClassNotFoundException exp) { final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \"" + policyDecoderParameterClassName + "\", could not find class"; - LOGGER.warn(errorMessage, exp); throw new IllegalArgumentException(errorMessage, exp); } return policyDecoderParameterClass; diff --git a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java index 9b3a4d2b..9a34ee61 100644 --- a/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java +++ b/reception/src/main/java/org/onap/policy/distribution/reception/parameters/ReceptionHandlerConfigurationParametersJsonAdapter.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2020 AT&T Inc. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +75,6 @@ public class ReceptionHandlerConfigurationParametersJsonAdapter } catch (final ClassNotFoundException e) { final String errorMessage = "parameter \"" + PARAMETER_CLASS_NAME + "\" value \"" + receptionHAndlerParameterClassName + "\", could not find class"; - LOGGER.warn(errorMessage, e); throw new IllegalArgumentException(errorMessage, e); } return receptionHandlerParameterClass; -- cgit 1.2.3-korg