* ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
  *  Copyright (C) 2019 Intel Corp. All rights reserved.
+ *  Modifications 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.
 
 package org.onap.policy.distribution.forwarding.xacml.pdp;
 
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
 import java.util.Collection;
 import java.util.Collections;
 import javax.ws.rs.client.Entity;
 import org.onap.policy.api.PushPolicyParameters;
 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
 import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.distribution.forwarding.PolicyForwarder;
 import org.onap.policy.distribution.forwarding.xacml.pdp.adapters.XacmlPdpOptimizationPolicyAdapter;
 import org.onap.policy.distribution.model.OptimizationPolicy;
 import org.onap.policy.distribution.model.Policy;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.http.HttpStatus;
                         method, policyName, response.getStatus(), response.getStatusInfo());
                 return false;
             }
-        } catch (KeyManagementException | NoSuchAlgorithmException | ClassNotFoundException exception) {
+        } catch (HttpClientConfigException exception) {
             LOGGER.error("Invocation of method " + method + " failed for policy " + policyName
                     + " due to error opening Http client", exception);
             return false;
         return true;
     }
 
-    private HttpClient getHttpClient() 
-            throws KeyManagementException, NoSuchAlgorithmException, ClassNotFoundException {
+    private HttpClient getHttpClient() throws HttpClientConfigException {
         boolean useHttps = configurationParameters.isUseHttps();
         String hostname = configurationParameters.getHostname();
         int port = configurationParameters.getPort();
         boolean managed = configurationParameters.isManaged();
         BusTopicParams params = BusTopicParams.builder().clientName("SDC Dist").useHttps(useHttps).hostname(hostname)
                 .port(port).userName(userName).password(password).basePath(BASE_PATH).managed(managed).build();
-        return HttpClient.factory.build(params);
+        return getHttpClientFactory().build(params);
     }
 
     @Override
         configurationParameters = ParameterService.get(parameterGroupName);
     }
 
+    // these may be overridden by junit tests
+
+    protected HttpClientFactory getHttpClientFactory() {
+        return HttpClientFactoryInstance.getClientFactory();
+    }
 }
 
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2018 Ericsson. All rights reserved.
+ *  Modifications 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.
- * 
+ *
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.security.KeyManagementException;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import org.onap.policy.api.PushPolicyParameters;
 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
 import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
 import org.onap.policy.common.parameters.ParameterGroup;
 import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarder;
 import org.onap.policy.distribution.forwarding.xacml.pdp.XacmlPdpPolicyForwarderParameterGroup.XacmlPdpPolicyForwarderParameterGroupBuilder;
-import org.onap.policy.distribution.main.PolicyDistributionException;
 import org.onap.policy.distribution.model.OptimizationPolicy;
 import org.onap.policy.distribution.model.Policy;
 
     }
 
     @Test
-    public void testForwardPolicy()
-            throws KeyManagementException, NoSuchAlgorithmException, NoSuchFieldException,SecurityException,
-            IllegalArgumentException, IllegalAccessException, PolicyDistributionException, ClassNotFoundException {
+    public void testForwardPolicy() throws Exception {
 
         HttpClient httpClientMock = mock(HttpClient.class);
         headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE);
         HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class);
         when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock);
 
-        overwriteField(HttpClient.class, "factory", null, httpClientFactoryMock);
-
-        XacmlPdpPolicyForwarder forwarder = new XacmlPdpPolicyForwarder();
+        XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock);
         forwarder.configure("xacmlPdpConfiguration");
 
         Collection<Policy> policies = new ArrayList<>();
     }
 
     @Test
-    public void testForwardPolicy_CreateFailsPushNotInvoked()
-            throws KeyManagementException, NoSuchAlgorithmException, NoSuchFieldException, SecurityException,
-            IllegalArgumentException, IllegalAccessException, PolicyDistributionException, ClassNotFoundException {
+    public void testForwardPolicy_CreateFailsPushNotInvoked() throws Exception {
 
         HttpClient httpClientMock = mock(HttpClient.class);
         headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE);
         HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class);
         when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock);
 
-        overwriteField(HttpClient.class, "factory", null, httpClientFactoryMock);
-
-        XacmlPdpPolicyForwarder forwarder = new XacmlPdpPolicyForwarder();
+        XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock);
         forwarder.configure("xacmlPdpConfiguration");
 
         Collection<Policy> policies = new ArrayList<>();
     }
 
     @Test
-    public void testForwardPolicy_PushFails()
-            throws KeyManagementException, NoSuchAlgorithmException, NoSuchFieldException, SecurityException,
-            IllegalArgumentException, IllegalAccessException, PolicyDistributionException, ClassNotFoundException {
+    public void testForwardPolicy_PushFails() throws Exception {
 
         HttpClient httpClientMock = mock(HttpClient.class);
         headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE);
         HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class);
         when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock);
 
-        overwriteField(HttpClient.class, "factory", null, httpClientFactoryMock);
-
-        XacmlPdpPolicyForwarder forwarder = new XacmlPdpPolicyForwarder();
+        XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock);
         forwarder.configure("xacmlPdpConfiguration");
 
         Collection<Policy> policies = new ArrayList<>();
     }
 
     @Test
-    public void testForwardPolicy_HttpClientInitFailureForPolicyCreate()
-            throws KeyManagementException, NoSuchAlgorithmException, NoSuchFieldException, SecurityException,
-            IllegalArgumentException, IllegalAccessException, PolicyDistributionException, ClassNotFoundException {
+    public void testForwardPolicy_HttpClientInitFailureForPolicyCreate() throws Exception {
 
         HttpClient httpClientMock = mock(HttpClient.class);
         headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE);
         when(httpClientMock.put(eq("pushPolicy"), anyObject(), eq(headers))).thenReturn(Response.status(400).build());
 
         HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class);
-        when(httpClientFactoryMock.build(argThat(matcher))).thenThrow(new KeyManagementException());
-
-        overwriteField(HttpClient.class, "factory", null, httpClientFactoryMock);
+        when(httpClientFactoryMock.build(argThat(matcher))).thenThrow(new HttpClientConfigException());
 
-        XacmlPdpPolicyForwarder forwarder = new XacmlPdpPolicyForwarder();
+        XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock);
         forwarder.configure("xacmlPdpConfiguration");
 
         Collection<Policy> policies = new ArrayList<>();
     }
 
     @Test
-    public void testForwardPolicy_HttpClientInitFailureForPolicyPush()
-            throws KeyManagementException, NoSuchAlgorithmException, NoSuchFieldException, SecurityException,
-            IllegalArgumentException, IllegalAccessException, PolicyDistributionException, ClassNotFoundException {
+    public void testForwardPolicy_HttpClientInitFailureForPolicyPush() throws Exception {
 
         HttpClient httpClientMock = mock(HttpClient.class);
         headers.put(CLIENT_AUTH, CLIENT_AUTH_VALUE);
 
         HttpClientFactory httpClientFactoryMock = mock(HttpClientFactory.class);
         when(httpClientFactoryMock.build(argThat(matcher))).thenReturn(httpClientMock)
-                .thenThrow(new KeyManagementException());
+                .thenThrow(new HttpClientConfigException());
 
-        overwriteField(HttpClient.class, "factory", null, httpClientFactoryMock);
-
-        XacmlPdpPolicyForwarder forwarder = new XacmlPdpPolicyForwarder();
+        XacmlPdpPolicyForwarder forwarder = new MyXacmlPdpPolicyForwarder(httpClientFactoryMock);
         forwarder.configure("xacmlPdpConfiguration");
 
         Collection<Policy> policies = new ArrayList<>();
         verify(httpClientMock, times(0)).put(eq("pushPolicy"), anyObject(), anyObject());
     }
 
-    private void overwriteField(final Class<?> clazz, final String fieldName, final Object object, final Object value)
-            throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
-        Field field = clazz.getField(fieldName);
-        field.setAccessible(true);
-        Field modifiersField = Field.class.getDeclaredField("modifiers");
-        modifiersField.setAccessible(true);
-        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
-        field.set(object, value);
-    }
-
     class BusTopicParamsMatcher extends BaseMatcher<BusTopicParams> {
 
         private BusTopicParams busTopicParams;
             return "unsupported";
         }
     }
+
+    private class MyXacmlPdpPolicyForwarder extends XacmlPdpPolicyForwarder {
+        private HttpClientFactory factory;
+
+        public MyXacmlPdpPolicyForwarder(HttpClientFactory httpClientFactory) {
+            this.factory = httpClientFactory;
+        }
+
+        @Override
+        protected HttpClientFactory getHttpClientFactory() {
+            return this.factory;
+        }
+    }
 }