hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsedd...@apache.org
Subject svn commit: r1763260 - /httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/
Date Tue, 04 Oct 2016 11:29:17 GMT
Author: jsedding
Date: Tue Oct  4 11:29:17 2016
New Revision: 1763260

URL: http://svn.apache.org/viewvc?rev=1763260&view=rev
Log:
HTTPCLIENT-1777: [OSGi] remove duplication between OSGiClientBuilderFactory and OSGiCachingClientBuilderFactory

Added:
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java
  (contents, props changed)
      - copied, changed from r1762912, httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpClientBuilder.java
Removed:
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingHttpClientBuilder.java
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpClientBuilder.java
Modified:
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java

Copied: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java
(from r1762912, httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpClientBuilder.java)
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java?p2=httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java&p1=httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpClientBuilder.java&r1=1762912&r2=1763260&rev=1763260&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpClientBuilder.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java
Tue Oct  4 11:29:17 2016
@@ -26,55 +26,58 @@
  */
 package org.apache.hc.client5.http.osgi.impl;
 
-import static org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory.getSocketFactory;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
-import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
 import org.apache.hc.client5.http.impl.sync.HttpClientBuilder;
 import org.apache.hc.client5.http.osgi.services.ProxyConfiguration;
 import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
-import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory;
 import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory;
+import org.apache.hc.core5.http.config.Registry;
 import org.apache.hc.core5.http.config.RegistryBuilder;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.cm.ManagedService;
 
-/**
- * @since 4.3
- */
-final class OSGiHttpClientBuilder extends HttpClientBuilder {
+import java.util.Map;
+
+import static org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory.getSocketFactory;
 
-    private final Collection<CloseableHttpClient> trackedHttpClients;
+final class HttpClientBuilderConfigurator {
 
-    public OSGiHttpClientBuilder(
+    private final OSGiCredentialsProvider credentialsProvider;
+
+    private final OSGiHttpRoutePlanner routePlanner;
+
+    private final Registry<ConnectionSocketFactory> socketFactoryRegistry;
+
+    HttpClientBuilderConfigurator(
             final BundleContext bundleContext,
             final Map<String, ServiceRegistration<ProxyConfiguration>> registeredConfigurations,
-            final ServiceRegistration<ManagedService> trustedHostConfiguration,
-            final List<CloseableHttpClient> trackedHttpClients) {
-        this.trackedHttpClients = trackedHttpClients;
-        setDefaultCredentialsProvider(
-                new OSGiCredentialsProvider(bundleContext, registeredConfigurations));
-        setRoutePlanner(
-                new OSGiHttpRoutePlanner(bundleContext, registeredConfigurations));
-        final LayeredConnectionSocketFactory defaultSocketFactory = getSocketFactory();
-        setConnectionManager(new PoolingHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create()
-                                                                    .register("http", PlainConnectionSocketFactory.INSTANCE)
-                                                                    .register("https", new
RelaxedLayeredConnectionSocketFactory(bundleContext, trustedHostConfiguration, defaultSocketFactory))
-                                                                    .build()));
+            final ServiceRegistration<ManagedService> trustedHostsConfiguration) {
+        credentialsProvider = new OSGiCredentialsProvider(bundleContext, registeredConfigurations);
+        routePlanner = new OSGiHttpRoutePlanner(bundleContext, registeredConfigurations);
+        socketFactoryRegistry = createSocketFactoryRegistry(bundleContext, trustedHostsConfiguration);
+    }
+
+    <T extends HttpClientBuilder> T configure(final T clientBuilder) {
+        clientBuilder
+                .setDefaultCredentialsProvider(credentialsProvider)
+                .setRoutePlanner(routePlanner)
+                .setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry));
+        return clientBuilder;
     }
 
-    @Override
-    public CloseableHttpClient build() {
-        final CloseableHttpClient httpClient = super.build();
-        synchronized (trackedHttpClients) {
-            trackedHttpClients.add(httpClient);
-        }
-        return httpClient;
+    private Registry<ConnectionSocketFactory> createSocketFactoryRegistry(
+            final BundleContext bundleContext,
+            final ServiceRegistration<ManagedService> trustedHostsConfiguration) {
+        return RegistryBuilder.<ConnectionSocketFactory>create()
+                .register("http", PlainConnectionSocketFactory.INSTANCE)
+                .register("https", createSocketFactory(bundleContext, trustedHostsConfiguration))
+                .build();
     }
 
+    private ConnectionSocketFactory createSocketFactory(
+            final BundleContext bundleContext,
+            final ServiceRegistration<ManagedService> trustedHostsConfiguration) {
+        return new RelaxedLayeredConnectionSocketFactory(bundleContext, trustedHostsConfiguration,
getSocketFactory());
+    }
 }

Propchange: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java?rev=1763260&r1=1763259&r2=1763260&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java
Tue Oct  4 11:29:17 2016
@@ -108,15 +108,15 @@ public final class HttpProxyConfiguratio
                                                            new OSGiTrustedHostsConfiguration(),
                                                            props);
 
+        final HttpClientBuilderConfigurator configurator =
+                new HttpClientBuilderConfigurator(context, registeredConfigurations, trustedHostConfiguration);
+
         props.clear();
         props.put(Constants.SERVICE_PID, BUILDER_FACTORY_SERVICE_PID);
         props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders().get(Constants.BUNDLE_VENDOR));
         props.put(Constants.SERVICE_DESCRIPTION, BUILDER_FACTORY_SERVICE_NAME);
         clientFactory = context.registerService(HttpClientBuilderFactory.class,
-                                                new OSGiClientBuilderFactory(context,
-                                                                             registeredConfigurations,
-                                                                             trustedHostConfiguration,
-                                                                             trackedHttpClients),
+                                                new OSGiClientBuilderFactory(configurator,
trackedHttpClients),
                                                 props);
 
         props.clear();
@@ -124,10 +124,7 @@ public final class HttpProxyConfiguratio
         props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders().get(Constants.BUNDLE_VENDOR));
         props.put(Constants.SERVICE_DESCRIPTION, CACHEABLE_BUILDER_FACTORY_SERVICE_NAME);
         cachingClientFactory = context.registerService(CachingHttpClientBuilderFactory.class,
-                                                       new OSGiCachingClientBuilderFactory(context,
-                                                                                        
  registeredConfigurations,
-                                                                                        
  trustedHostConfiguration,
-                                                                                        
  trackedHttpClients),
+                                                       new OSGiCachingClientBuilderFactory(configurator,
trackedHttpClients),
                                                        props);
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java?rev=1763260&r1=1763259&r2=1763260&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java
Tue Oct  4 11:29:17 2016
@@ -27,42 +27,36 @@
 package org.apache.hc.client5.http.osgi.impl;
 
 import java.util.List;
-import java.util.Map;
 
 import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder;
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
 import org.apache.hc.client5.http.osgi.services.CachingHttpClientBuilderFactory;
-import org.apache.hc.client5.http.osgi.services.ProxyConfiguration;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ManagedService;
 
-class OSGiCachingClientBuilderFactory implements CachingHttpClientBuilderFactory {
+/**
+ * @since 4.3
+ */
+final class OSGiCachingClientBuilderFactory implements CachingHttpClientBuilderFactory {
 
-    private final BundleContext bundleContext;
+    private final HttpClientBuilderConfigurator configurator;
 
-    private final Map<String, ServiceRegistration<ProxyConfiguration>> registeredConfigurations;
+    private List<CloseableHttpClient> trackedHttpClients;
 
-    private final ServiceRegistration<ManagedService> trustedHostConfiguration;
-
-    private final List<CloseableHttpClient> trackedHttpClients;
-
-    public OSGiCachingClientBuilderFactory(
-            final BundleContext bundleContext,
-            final Map<String, ServiceRegistration<ProxyConfiguration>> registeredConfigurations,
-            final ServiceRegistration<ManagedService> trustedHostConfiguration,
+    OSGiCachingClientBuilderFactory(
+            final HttpClientBuilderConfigurator configurator,
             final List<CloseableHttpClient> trackedHttpClients) {
-        this.bundleContext = bundleContext;
-        this.registeredConfigurations = registeredConfigurations;
-        this.trustedHostConfiguration = trustedHostConfiguration;
+        this.configurator = configurator;
         this.trackedHttpClients = trackedHttpClients;
     }
 
     @Override
     public CachingHttpClientBuilder newBuilder() {
-        return new OSGiCachingHttpClientBuilder(bundleContext,
-                                                registeredConfigurations,
-                                                trustedHostConfiguration,
-                                                trackedHttpClients);
+        return configurator.configure(new CachingHttpClientBuilder() {
+            @Override
+            public CloseableHttpClient build() {
+                final CloseableHttpClient client = super.build();
+                trackedHttpClients.add(client);
+                return client;
+            }
+        });
     }
 }

Modified: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java?rev=1763260&r1=1763259&r2=1763260&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java
Tue Oct  4 11:29:17 2016
@@ -27,43 +27,36 @@
 package org.apache.hc.client5.http.osgi.impl;
 
 import java.util.List;
-import java.util.Map;
 
 import org.apache.hc.client5.http.impl.sync.CloseableHttpClient;
 import org.apache.hc.client5.http.impl.sync.HttpClientBuilder;
 import org.apache.hc.client5.http.osgi.services.HttpClientBuilderFactory;
-import org.apache.hc.client5.http.osgi.services.ProxyConfiguration;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ManagedService;
 
 /**
  * @since 4.3
  */
-public final class OSGiClientBuilderFactory implements HttpClientBuilderFactory {
+final class OSGiClientBuilderFactory implements HttpClientBuilderFactory {
 
-    private final BundleContext bundleContext;
-
-    private final Map<String, ServiceRegistration<ProxyConfiguration>> registeredConfigurations;
-
-    private final ServiceRegistration<ManagedService> trustedHostConfiguration;
+    private final HttpClientBuilderConfigurator configurator;
 
     private final List<CloseableHttpClient> trackedHttpClients;
 
-    public OSGiClientBuilderFactory(
-            final BundleContext bundleContext,
-            final Map<String, ServiceRegistration<ProxyConfiguration>> registeredConfigurations,
-            final ServiceRegistration<ManagedService> trustedHostConfiguration,
+    OSGiClientBuilderFactory(
+            final HttpClientBuilderConfigurator configurator,
             final List<CloseableHttpClient> trackedHttpClients) {
-        this.bundleContext = bundleContext;
-        this.registeredConfigurations = registeredConfigurations;
-        this.trustedHostConfiguration = trustedHostConfiguration;
+        this.configurator = configurator;
         this.trackedHttpClients = trackedHttpClients;
     }
 
     @Override
     public HttpClientBuilder newBuilder() {
-        return new OSGiHttpClientBuilder(bundleContext, registeredConfigurations, trustedHostConfiguration,
trackedHttpClients);
+        return configurator.configure(new HttpClientBuilder() {
+            @Override
+            public CloseableHttpClient build() {
+                final CloseableHttpClient client = super.build();
+                trackedHttpClients.add(client);
+                return client;
+            }
+        });
     }
-
 }



Mime
View raw message