You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2016/06/11 15:55:28 UTC

svn commit: r1747906 - in /httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi: impl/ services/

Author: olegk
Date: Sat Jun 11 15:55:28 2016
New Revision: 1747906

URL: http://svn.apache.org/viewvc?rev=1747906&view=rev
Log:
HTTPCLIENT-1750: OSGi support for CachingHttpClientBuilder
Contributed by Justin Edelson <justin at justinedelson.com>

Added:
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java   (with props)
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingHttpClientBuilder.java   (with props)
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java   (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java

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=1747906&r1=1747905&r2=1747906&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 Sat Jun 11 15:55:28 2016
@@ -35,6 +35,7 @@ import java.util.List;
 import java.util.Map;
 
 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.HttpClientBuilderFactory;
 import org.apache.hc.client5.http.osgi.services.ProxyConfiguration;
 import org.osgi.framework.BundleActivator;
@@ -49,9 +50,17 @@ import org.osgi.service.cm.ManagedServic
  */
 public final class HttpProxyConfigurationActivator implements BundleActivator, ManagedServiceFactory {
 
-    private static final String SERVICE_FACTORY_NAME = "Apache HTTP Client Proxy Configuration Factory";
+    private static final String PROXY_SERVICE_FACTORY_NAME = "Apache HTTP Client Proxy Configuration Factory";
 
-    private static final String SERVICE_PID = "org.apache.http.proxyconfigurator";
+    private static final String PROXY_SERVICE_PID = "org.apache.http.proxyconfigurator";
+
+    private static final String BUILDER_FACTORY_SERVICE_NAME = "Apache HTTP Client Client Factory";
+
+    private static final String BUILDER_FACTORY_SERVICE_PID = "org.apache.http.httpclientfactory";
+
+    private static final String CACHEABLE_BUILDER_FACTORY_SERVICE_NAME = "Apache HTTP Client Caching Client Factory";
+
+    private static final String CACHEABLE_BUILDER_FACTORY_SERVICE_PID = "org.apache.http.cachinghttpclientfactory";
 
     private ServiceRegistration configurator;
 
@@ -78,12 +87,25 @@ public final class HttpProxyConfiguratio
         final Hashtable<String, Object> props = new Hashtable<>();
         props.put(Constants.SERVICE_PID, getName());
         props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders(Constants.BUNDLE_VENDOR));
-        props.put(Constants.SERVICE_DESCRIPTION, SERVICE_FACTORY_NAME);
+        props.put(Constants.SERVICE_DESCRIPTION, PROXY_SERVICE_FACTORY_NAME);
 
         configurator = context.registerService(ManagedServiceFactory.class.getName(), this, props);
+
+        props.clear();
+        props.put(Constants.SERVICE_PID, BUILDER_FACTORY_SERVICE_PID);
+        props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders(Constants.BUNDLE_VENDOR));
+        props.put(Constants.SERVICE_DESCRIPTION, BUILDER_FACTORY_SERVICE_NAME);
         clientFactory = context.registerService(HttpClientBuilderFactory.class.getName(),
                                                 new OSGiClientBuilderFactory(context, registeredConfigurations, trackedHttpClients),
                                                 props);
+
+        props.clear();
+        props.put(Constants.SERVICE_PID, CACHEABLE_BUILDER_FACTORY_SERVICE_PID);
+        props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders(Constants.BUNDLE_VENDOR));
+        props.put(Constants.SERVICE_DESCRIPTION, CACHEABLE_BUILDER_FACTORY_SERVICE_NAME);
+        clientFactory = context.registerService(CachingHttpClientBuilderFactory.class.getName(),
+                new OSGiCachingClientBuilderFactory(context, registeredConfigurations, trackedHttpClients),
+                props);
     }
 
     /**
@@ -123,7 +145,7 @@ public final class HttpProxyConfiguratio
      */
     @Override
     public String getName() {
-        return SERVICE_PID;
+        return PROXY_SERVICE_PID;
     }
 
     /**

Added: 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=1747906&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java Sat Jun 11 15:55:28 2016
@@ -0,0 +1,59 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+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.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+class OSGiCachingClientBuilderFactory implements CachingHttpClientBuilderFactory {
+
+    private final BundleContext bundleContext;
+
+    private final Map<String, ServiceRegistration> registeredConfigurations;
+
+    private final List<CloseableHttpClient> trackedHttpClients;
+
+    public OSGiCachingClientBuilderFactory(
+            final BundleContext bundleContext,
+            final Map<String, ServiceRegistration> registeredConfigurations,
+            final List<CloseableHttpClient> trackedHttpClients) {
+        this.bundleContext = bundleContext;
+        this.registeredConfigurations = registeredConfigurations;
+        this.trackedHttpClients = trackedHttpClients;
+    }
+
+    @Override
+    public CachingHttpClientBuilder newBuilder() {
+        return new OSGiCachingHttpClientBuilder(bundleContext, registeredConfigurations, trackedHttpClients);
+    }
+}

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

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

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

Added: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingHttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingHttpClientBuilder.java?rev=1747906&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingHttpClientBuilder.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingHttpClientBuilder.java Sat Jun 11 15:55:28 2016
@@ -0,0 +1,61 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+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.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+final class OSGiCachingHttpClientBuilder extends CachingHttpClientBuilder {
+
+    private final List<CloseableHttpClient> trackedHttpClients;
+
+    public OSGiCachingHttpClientBuilder(
+            final BundleContext bundleContext,
+            final Map<String, ServiceRegistration> registeredConfigurations,
+            final List<CloseableHttpClient> trackedHttpClients) {
+        this.trackedHttpClients = trackedHttpClients;
+        setDefaultCredentialsProvider(
+                new OSGiCredentialsProvider(bundleContext, registeredConfigurations));
+        setRoutePlanner(
+                new OSGiHttpRoutePlanner(bundleContext, registeredConfigurations));
+    }
+
+    @Override
+    public CloseableHttpClient build() {
+        final CloseableHttpClient httpClient = super.build();
+        synchronized (trackedHttpClients) {
+            trackedHttpClients.add(httpClient);
+        }
+        return httpClient;
+    }
+
+}

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

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

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

Added: httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java?rev=1747906&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java (added)
+++ httpcomponents/httpclient/trunk/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java Sat Jun 11 15:55:28 2016
@@ -0,0 +1,35 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.client5.http.osgi.services;
+
+import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder;
+
+public interface CachingHttpClientBuilderFactory {
+
+    CachingHttpClientBuilder newBuilder();
+
+}

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

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

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