hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1747904 - in /httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi: impl/ services/
Date Sat, 11 Jun 2016 15:54:55 GMT
Author: olegk
Date: Sat Jun 11 15:54:55 2016
New Revision: 1747904

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

Added:
    httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
  (with props)
    httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
  (with props)
    httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
  (with props)
Modified:
    httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/HttpProxyConfigurationActivator.java

Modified: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/HttpProxyConfigurationActivator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/HttpProxyConfigurationActivator.java?rev=1747904&r1=1747903&r2=1747904&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/HttpProxyConfigurationActivator.java
(original)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/HttpProxyConfigurationActivator.java
Sat Jun 11 15:54:55 2016
@@ -35,6 +35,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.osgi.services.CachingHttpClientBuilderFactory;
 import org.apache.http.osgi.services.HttpClientBuilderFactory;
 import org.apache.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<String, Object>();
         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/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java?rev=1747904&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
(added)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
Sat Jun 11 15:54:55 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.http.osgi.impl;
+
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
+import org.apache.http.osgi.services.CachingHttpClientBuilderFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.List;
+import java.util.Map;
+
+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/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingClientBuilderFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java?rev=1747904&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
(added)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
Sat Jun 11 15:54:55 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.http.osgi.impl;
+
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+import java.util.List;
+import java.util.Map;
+
+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/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/impl/OSGiCachingHttpClientBuilder.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java?rev=1747904&view=auto
==============================================================================
--- httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
(added)
+++ httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
Sat Jun 11 15:54:55 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.http.osgi.services;
+
+import org.apache.http.impl.client.cache.CachingHttpClientBuilder;
+
+public interface CachingHttpClientBuilderFactory {
+
+    CachingHttpClientBuilder newBuilder();
+
+}

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/branches/4.5.x/httpclient-osgi/src/main/java/org/apache/http/osgi/services/CachingHttpClientBuilderFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message