http proxy settings need a different connector 21/120221/2
authorRavi Pendurty <ravi.pendurty@highstreet-technologies.com>
Tue, 6 Apr 2021 09:41:09 +0000 (11:41 +0200)
committerRavi Pendurty <ravi.pendurty@highstreet-technologies.com>
Thu, 8 Apr 2021 12:14:15 +0000 (14:14 +0200)
ApacheConnectorProvider supports the http proxy properties defined by DMAAP MR and not the default HttpUrlConnectorProvider

Issue-ID: DMAAP-1548
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
Change-Id: Ie1cff823ff247133c69434110b04b8191b46a1f6
Signed-off-by: Ravi Pendurty <ravi.pendurty@highstreet-technologies.com>
pom.xml
src/main/java/org/onap/dmaap/mr/client/impl/DmaapClientUtil.java
src/test/java/org/onap/dmaap/mr/client/impl/DMaapClientUtilTest.java

diff --git a/pom.xml b/pom.xml
index 3d1785b..134971a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
             <artifactId>jersey-common</artifactId>
             <version>${jersey.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.connectors</groupId>
+            <artifactId>jersey-apache-connector</artifactId>
+            <version>2.29.1</version>
+        </dependency>
         <dependency>
             <groupId>org.glassfish.jersey.core</groupId>
             <artifactId>jersey-client</artifactId>
index 4c50596..948ca31 100644 (file)
@@ -8,7 +8,7 @@
  *  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.
  *  ============LICENSE_END=========================================================
  *
  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
- *  
+ *
  *******************************************************************************/
 package org.onap.dmaap.mr.client.impl;
 
 import java.util.Properties;
-
 import javax.ws.rs.client.Client;
 import javax.ws.rs.client.ClientBuilder;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.Response;
-
+import org.glassfish.jersey.apache.connector.ApacheConnectorProvider;
 import org.glassfish.jersey.client.ClientConfig;
 import org.glassfish.jersey.client.ClientProperties;
 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
@@ -55,6 +54,10 @@ public class DmaapClientUtil {
                                config.property(httpClientProperties[i], properties.getProperty(httpClientProperties[i]));
                        }
                }
+               if ((properties.getProperty(ClientProperties.PROXY_URI) != null) &&
+                       !(properties.getProperty(ClientProperties.PROXY_URI).isEmpty())) {
+                   config.connectorProvider(new ApacheConnectorProvider());
+               } // else the default connectorProvider (HttpConnectorProvider) will be used
 
        }
 
index 4378942..5d63759 100644 (file)
@@ -26,11 +26,14 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import java.util.Properties;
+
 import javax.ws.rs.client.Invocation.Builder;
 import javax.ws.rs.client.WebTarget;
 import javax.ws.rs.core.Response;
 
 import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.ClientProperties;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -78,6 +81,15 @@ public class DMaapClientUtilTest {
         verify(target).request();
         verify(builder, times(2)).header((String) any(), any());
     }
+    
+    @Test
+    public void testSetHttpClientProperties() {
+       Properties properties = new Properties();
+       properties.setProperty(ClientProperties.PROXY_URI, "http://localhost:1234");
+       ClientConfig cConfig = DmaapClientUtil.getClientConfig(properties);
+
+       assertEquals(cConfig.getConnectorProvider().getClass().getSimpleName(), "ApacheConnectorProvider");
+    }
 
        private ClientConfig getClientConfig(){
                if(config==null){