From 5797e2475a8709cdfe7faed16ef96c30cfa73976 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Tue, 4 Dec 2018 15:51:21 +0100 Subject: [PATCH] Removed OSGi module --- httpclient5-osgi/pom.xml | 186 --------------- .../client5/http/osgi/impl/HostMatcher.java | 158 ------------- .../impl/HttpClientBuilderConfigurator.java | 79 ------- .../impl/HttpProxyConfigurationActivator.java | 219 ------------------ .../impl/OSGiCachingClientBuilderFactory.java | 60 ----- .../osgi/impl/OSGiClientBuilderFactory.java | 60 ----- .../osgi/impl/OSGiCredentialsProvider.java | 118 ---------- .../http/osgi/impl/OSGiHttpRoutePlanner.java | 73 ------ .../osgi/impl/OSGiProxyConfiguration.java | 142 ------------ .../impl/OSGiTrustedHostsConfiguration.java | 104 --------- .../http/osgi/impl/PropertiesUtils.java | 205 ---------------- ...RelaxedLayeredConnectionSocketFactory.java | 91 -------- .../hc/client5/http/osgi/impl/WeakList.java | 129 ----------- .../client5/http/osgi/impl/package-info.java | 27 --- .../hc/client5/http/osgi/package-info.java | 31 --- .../CachingHttpClientBuilderFactory.java | 35 --- .../services/HttpClientBuilderFactory.java | 38 --- .../osgi/services/ProxyConfiguration.java | 46 ---- .../services/TrustedHostsConfiguration.java | 57 ----- .../http/osgi/services/package-info.java | 31 --- .../OSGI-INF/metatype/metatype.properties | 94 -------- .../resources/OSGI-INF/metatype/metatype.xml | 108 --------- .../http/osgi/impl/HostMatcherTest.java | 87 ------- .../impl/OSGiCredentialsProviderTest.java | 105 --------- .../osgi/impl/OSGiProxyConfigurationTest.java | 61 ----- .../osgi/impl/TestOSGiHttpRoutePlanner.java | 117 ---------- .../TestOSGiTrustedHostsConfiguration.java | 73 ------ .../http/osgi/impl/TestPropertiesUtils.java | 132 ----------- ...RelaxedLayeredConnectionSocketFactory.java | 127 ---------- .../client5/http/osgi/impl/WeakListTest.java | 73 ------ .../src/test/resources/log4j2.xml | 29 --- pom.xml | 1 - 32 files changed, 2896 deletions(-) delete mode 100644 httpclient5-osgi/pom.xml delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HostMatcher.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProvider.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfiguration.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiTrustedHostsConfiguration.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/PropertiesUtils.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/WeakList.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/package-info.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/package-info.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/HttpClientBuilderFactory.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/ProxyConfiguration.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/TrustedHostsConfiguration.java delete mode 100644 httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/package-info.java delete mode 100644 httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.properties delete mode 100644 httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.xml delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/HostMatcherTest.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProviderTest.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfigurationTest.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiTrustedHostsConfiguration.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestPropertiesUtils.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestRelaxedLayeredConnectionSocketFactory.java delete mode 100644 httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java delete mode 100644 httpclient5-osgi/src/test/resources/log4j2.xml diff --git a/httpclient5-osgi/pom.xml b/httpclient5-osgi/pom.xml deleted file mode 100644 index 371f23f6b..000000000 --- a/httpclient5-osgi/pom.xml +++ /dev/null @@ -1,186 +0,0 @@ - - - 4.0.0 - - org.apache.httpcomponents.client5 - httpclient5-parent - 5.0-beta3-SNAPSHOT - - httpclient5-osgi - Apache HttpClient OSGi bundle - 1999 - - Apache HttpComponents Client (OSGi bundle) - - http://hc.apache.org/httpcomponents-client - bundle - - - "5.0-beta1" - "[1.7, 1.8)" - 5.0.0 - - - - - org.apache.httpcomponents.client5 - httpclient5 - ${project.version} - - - - org.apache.httpcomponents.core5 - httpcore5-osgi - ${httpcore.version} - provided - - - commons-codec - commons-codec - ${commons-codec.version} - - - org.apache.httpcomponents.client5 - httpclient5-cache - ${project.version} - - - org.apache.httpcomponents.client5 - httpclient5-fluent - ${project.version} - - - org.osgi - org.osgi.core - ${osgi.framework.version} - provided - - - org.osgi - org.osgi.compendium - ${osgi.framework.version} - provided - - - junit - junit - test - - - org.mockito - mockito-core - test - - - - - - - src/main/resources - - - - - org.apache.felix - maven-bundle-plugin - true - - - Apache ${project.name} - ${project.groupId}.httpclient - <_exportcontents> - org.apache.hc.client5.*;version=${project.version} - - *;scope=compile|runtime;inline=true - - javax.crypto, - javax.crypto.spec, - javax.naming, - javax.naming.directory, - javax.naming.ldap, - javax.net, - javax.net.ssl, - javax.security.auth.x500, - org.ietf.jgss,, - org.osgi.framework, - org.osgi.service.cm, - org.slf4j;version=${slf4j.osgi.import.version}, - org.apache.hc.core5.*;version=${httpcore.osgi.import.version}, - org.ehcache.*;resolution:=optional, - net.spy.memcached.*;resolution:=optional - - org.apache.hc.client5.http.osgi.impl.HttpProxyConfigurationActivator - - <_removeheaders>JAVA_1_3_HOME,JAVA_1_4_HOME - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 2.22.0 - - - - integration-test - verify - - - - true - ${project.build.directory} - ${project.version} - - - - - - - org.apache.httpcomponents.httpclient_${project.version} - - - - - - - maven-project-info-reports-plugin - false - - - - dependencies - dependency-info - summary - - - - - - - - - diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HostMatcher.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HostMatcher.java deleted file mode 100644 index 27f2c2f55..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HostMatcher.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import java.util.Locale; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -interface HostMatcher { - - public static final String DOT = "."; - - /** - * The IP mask pattern against which hosts are matched. - */ - public static final Pattern IP_MASK_PATTERN = Pattern.compile("^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + - "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + - "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + - "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"); - - boolean matches(String host); - - public static class HostMatcherFactory { - - public static HostMatcher createMatcher(final String name) { - final NetworkAddress na = NetworkAddress.parse(name); - if (na != null) { - return new IPAddressMatcher(na); - } - - if (name.startsWith(DOT)) { - return new DomainNameMatcher(name); - } - - return new HostNameMatcher(name); - } - - } - - public static class HostNameMatcher implements HostMatcher { - - private final String hostName; - - HostNameMatcher(final String hostName) { - this.hostName = hostName; - } - - @Override - public boolean matches(final String host) { - return hostName.equalsIgnoreCase(host); - } - } - - public static class DomainNameMatcher implements HostMatcher { - - private final String domainName; - - DomainNameMatcher(final String domainName) { - this.domainName = domainName.toLowerCase(Locale.ROOT); - } - - @Override - public boolean matches(final String host) { - return host.toLowerCase(Locale.ROOT).endsWith(domainName); - } - } - - public static class IPAddressMatcher implements HostMatcher { - - private final NetworkAddress address; - - IPAddressMatcher(final NetworkAddress address) { - this.address = address; - } - - @Override - public boolean matches(final String host) { - final NetworkAddress hostAddress = NetworkAddress.parse(host); - return hostAddress != null && address.address == (hostAddress.address & address.mask); - } - - } - - public static class NetworkAddress { - - final int address; - - final int mask; - - static NetworkAddress parse(final String adrSpec) { - - if (null != adrSpec) { - final Matcher nameMatcher = IP_MASK_PATTERN.matcher(adrSpec); - if (nameMatcher.matches()) { - try { - final int i1 = toInt(nameMatcher.group(1), 255); - final int i2 = toInt(nameMatcher.group(2), 255); - final int i3 = toInt(nameMatcher.group(3), 255); - final int i4 = toInt(nameMatcher.group(4), 255); - final int ip = i1 << 24 | i2 << 16 | i3 << 8 | i4; - - int mask = toInt(nameMatcher.group(4), 32); - mask = (mask == 32) ? -1 : -1 - (-1 >>> mask); - - return new NetworkAddress(ip, mask); - } catch (final NumberFormatException nfe) { - // not expected after the pattern match ! - } - } - } - - return null; - } - - private static int toInt(final String value, final int max) { - if (value == null || value.isEmpty()) { - return max; - } - - int number = Integer.parseInt(value); - if (number > max) { - number = max; - } - return number; - } - - NetworkAddress(final int address, final int mask) { - this.address = address; - this.mask = mask; - } - - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java deleted file mode 100644 index 47f54713b..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpClientBuilderConfigurator.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory.getSocketFactory; - -import java.util.List; - -import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager; -import org.apache.hc.client5.http.osgi.services.ProxyConfiguration; -import org.apache.hc.client5.http.osgi.services.TrustedHostsConfiguration; -import org.apache.hc.client5.http.socket.ConnectionSocketFactory; -import org.apache.hc.client5.http.socket.PlainConnectionSocketFactory; -import org.apache.hc.core5.http.URIScheme; -import org.apache.hc.core5.http.config.Registry; -import org.apache.hc.core5.http.config.RegistryBuilder; - -final class HttpClientBuilderConfigurator { - - private final OSGiCredentialsProvider credentialsProvider; - - private final OSGiHttpRoutePlanner routePlanner; - - private final Registry socketFactoryRegistry; - - HttpClientBuilderConfigurator( - final List proxyConfigurations, - final TrustedHostsConfiguration trustedHostsConfiguration) { - credentialsProvider = new OSGiCredentialsProvider(proxyConfigurations); - routePlanner = new OSGiHttpRoutePlanner(proxyConfigurations); - socketFactoryRegistry = createSocketFactoryRegistry(trustedHostsConfiguration); - } - - T configure(final T clientBuilder) { - clientBuilder - .setDefaultCredentialsProvider(credentialsProvider) - .setRoutePlanner(routePlanner) - .setConnectionManager(new PoolingHttpClientConnectionManager(socketFactoryRegistry)); - return clientBuilder; - } - - private Registry createSocketFactoryRegistry( - final TrustedHostsConfiguration trustedHostsConfiguration) { - return RegistryBuilder.create() - .register(URIScheme.HTTP.id, PlainConnectionSocketFactory.INSTANCE) - .register(URIScheme.HTTPS.id, createSocketFactory(trustedHostsConfiguration)) - .build(); - } - - private ConnectionSocketFactory createSocketFactory( - final TrustedHostsConfiguration trustedHostsConfiguration) { - return new RelaxedLayeredConnectionSocketFactory(trustedHostsConfiguration, getSocketFactory()); - } -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java deleted file mode 100644 index ffcd99901..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/HttpProxyConfigurationActivator.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; - -import org.apache.hc.client5.http.impl.classic.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.apache.hc.core5.io.Closer; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; -import org.osgi.framework.ServiceReference; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.cm.ConfigurationException; -import org.osgi.service.cm.ManagedService; -import org.osgi.service.cm.ManagedServiceFactory; - -/** - * @since 4.3 - */ -public final class HttpProxyConfigurationActivator implements BundleActivator, ManagedServiceFactory { - - private static final String PROXY_SERVICE_FACTORY_NAME = "Apache HTTP Client Proxy Configuration Factory"; - - private static final String PROXY_SERVICE_PID = "org.apache.hc.client5.http.proxyconfigurator"; - - private static final String TRUSTED_HOSTS_SERVICE_NAME = "Apache HTTP Client Trusted Hosts Configuration"; - - private static final String TRUSTED_HOSTS_PID = "org.apache.hc.client5.http.trustedhosts"; - - private static final String BUILDER_FACTORY_SERVICE_NAME = "Apache HTTP Client Client Factory"; - - private static final String BUILDER_FACTORY_SERVICE_PID = "org.apache.hc.client5.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.hc.client5.http.cachinghttpclientfactory"; - - private ServiceRegistration configurator; - - private ServiceRegistration trustedHostConfiguration; - - private ServiceRegistration clientFactory; - - private ServiceRegistration cachingClientFactory; - - private BundleContext context; - - private final Map> registeredConfigurations = new LinkedHashMap<>(); - - private final List proxyConfigurations = new CopyOnWriteArrayList<>(); - - private final HttpClientTracker httpClientTracker = new HttpClientTracker(); - - /** - * {@inheritDoc} - */ - @Override - public void start(final BundleContext context) throws Exception { - this.context = context; - - // ensure we receive configurations for the proxy selector - final Hashtable props = new Hashtable<>(); - props.put(Constants.SERVICE_PID, getName()); - props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders().get(Constants.BUNDLE_VENDOR)); - props.put(Constants.SERVICE_DESCRIPTION, PROXY_SERVICE_FACTORY_NAME); - - configurator = context.registerService(ManagedServiceFactory.class, this, props); - - props.clear(); - props.put(Constants.SERVICE_PID, TRUSTED_HOSTS_PID); - props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders().get(Constants.BUNDLE_VENDOR)); - props.put(Constants.SERVICE_DESCRIPTION, TRUSTED_HOSTS_SERVICE_NAME); - final OSGiTrustedHostsConfiguration trustedHosts = new OSGiTrustedHostsConfiguration(); - trustedHostConfiguration = context.registerService(ManagedService.class, trustedHosts, props); - - final HttpClientBuilderConfigurator configurator = - new HttpClientBuilderConfigurator(proxyConfigurations, trustedHosts); - - 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(configurator, httpClientTracker), - props); - - props.clear(); - props.put(Constants.SERVICE_PID, CACHEABLE_BUILDER_FACTORY_SERVICE_PID); - 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(configurator, httpClientTracker), - props); - } - - /** - * {@inheritDoc} - */ - @Override - public void stop(final BundleContext context) throws Exception { - // unregister services - for (final ServiceRegistration registeredConfiguration : registeredConfigurations.values()) { - safeUnregister(registeredConfiguration); - } - // remove all tracked services - registeredConfigurations.clear(); - - safeUnregister(configurator); - safeUnregister(clientFactory); - safeUnregister(cachingClientFactory); - safeUnregister(trustedHostConfiguration); - - // ensure all http clients are closed - httpClientTracker.closeAll(); - } - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return PROXY_SERVICE_PID; - } - - /** - * {@inheritDoc} - */ - @Override - public void updated(final String pid, final Dictionary config) throws ConfigurationException { - final ServiceRegistration registration = registeredConfigurations.get(pid); - final OSGiProxyConfiguration proxyConfiguration; - - if (registration == null) { - proxyConfiguration = new OSGiProxyConfiguration(); - final ServiceRegistration configurationRegistration = - context.registerService(ProxyConfiguration.class, - proxyConfiguration, - config); - registeredConfigurations.put(pid, configurationRegistration); - proxyConfigurations.add(proxyConfiguration); - } else { - proxyConfiguration = (OSGiProxyConfiguration) context.getService(registration.getReference()); - } - - proxyConfiguration.update(config); - } - - /** - * {@inheritDoc} - */ - @Override - public void deleted(final String pid) { - final ServiceRegistration registration = registeredConfigurations.remove(pid); - if (registration != null) { - final ServiceReference ref = registration.getReference(); - final ProxyConfiguration config = context.getService(ref); - proxyConfigurations.remove(config); - context.ungetService(ref); - safeUnregister(registration); - } - } - - private static boolean safeUnregister(final ServiceRegistration serviceRegistration) { - if (serviceRegistration != null) { - serviceRegistration.unregister(); - return true; - } - return false; - } - - static class HttpClientTracker { - - private final List trackedHttpClients = new WeakList<>(); - - synchronized void track(final CloseableHttpClient client) { - trackedHttpClients.add(client); - } - - synchronized void closeAll() { - for (final CloseableHttpClient client : trackedHttpClients) { - Closer.closeQuietly(client); - } - trackedHttpClients.clear(); - } - } -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java deleted file mode 100644 index 3de724b0c..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCachingClientBuilderFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder; -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.osgi.services.CachingHttpClientBuilderFactory; - -/** - * @since 4.3 - */ -final class OSGiCachingClientBuilderFactory implements CachingHttpClientBuilderFactory { - - private final HttpClientBuilderConfigurator configurator; - - private final HttpProxyConfigurationActivator.HttpClientTracker httpClientTracker; - - OSGiCachingClientBuilderFactory( - final HttpClientBuilderConfigurator configurator, - final HttpProxyConfigurationActivator.HttpClientTracker httpClientTracker) { - this.configurator = configurator; - this.httpClientTracker = httpClientTracker; - } - - @Override - public CachingHttpClientBuilder newBuilder() { - return configurator.configure(new CachingHttpClientBuilder() { - @Override - public CloseableHttpClient build() { - final CloseableHttpClient client = super.build(); - httpClientTracker.track(client); - return client; - } - }); - } -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java deleted file mode 100644 index 2474d2795..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiClientBuilderFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; -import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; -import org.apache.hc.client5.http.osgi.services.HttpClientBuilderFactory; - -/** - * @since 4.3 - */ -final class OSGiClientBuilderFactory implements HttpClientBuilderFactory { - - private final HttpClientBuilderConfigurator configurator; - - private final HttpProxyConfigurationActivator.HttpClientTracker httpClientTracker; - - OSGiClientBuilderFactory( - final HttpClientBuilderConfigurator configurator, - final HttpProxyConfigurationActivator.HttpClientTracker httpClientTracker) { - this.configurator = configurator; - this.httpClientTracker = httpClientTracker; - } - - @Override - public HttpClientBuilder newBuilder() { - return configurator.configure(new HttpClientBuilder() { - @Override - public CloseableHttpClient build() { - final CloseableHttpClient client = super.build(); - httpClientTracker.track(client); - return client; - } - }); - } -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProvider.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProvider.java deleted file mode 100644 index d49a7c45f..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProvider.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import java.util.List; - -import org.apache.hc.client5.http.auth.AuthScope; -import org.apache.hc.client5.http.auth.Credentials; -import org.apache.hc.client5.http.auth.CredentialsStore; -import org.apache.hc.client5.http.auth.NTCredentials; -import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; -import org.apache.hc.client5.http.osgi.services.ProxyConfiguration; -import org.apache.hc.core5.http.protocol.HttpContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @since 4.3 - */ -final class OSGiCredentialsProvider implements CredentialsStore { - - private static final Logger log = LoggerFactory.getLogger(OSGiCredentialsProvider.class); - - private static final int HOST_AND_PORT_MATCH = 12; - - private static final String BASIC_SCHEME_NAME = "BASIC"; - - private static final String NTLM_SCHEME_NAME = "NTLM"; - - private final List proxyConfigurations; - - OSGiCredentialsProvider(final List proxyConfigurations) { - this.proxyConfigurations = proxyConfigurations; - } - - /** - * {@inheritDoc} - */ - @Override - public void setCredentials(final AuthScope authscope, final Credentials credentials) { - // do nothing, not used in this version - } - - /** - * {@inheritDoc} - */ - @Override - public Credentials getCredentials(final AuthScope authScope, final HttpContext context) { - // iterate over all active proxy configurations at the moment of getting the credential - for (final ProxyConfiguration config : proxyConfigurations) { - if (config.isEnabled() && isSuitable(config, authScope)) { - final String scheme = authScope.getAuthScheme(); - if (BASIC_SCHEME_NAME.equals(scheme)) { - return new UsernamePasswordCredentials(config.getUsername(), config.getPassword().toCharArray()); - } else if (NTLM_SCHEME_NAME.equals(scheme)) { - return createNTCredentials(config); - } else { - log.debug("credentials requested for unsupported authentication scheme " + scheme); - } - } - } - // credentials no longer available! - return null; - } - - /** - * {@inheritDoc} - */ - @Override - public void clear() { - // do nothing, not used in this version - } - - // suitable configurations match at least the host and port of the AuthScope - private boolean isSuitable(final ProxyConfiguration config, final AuthScope authScope) { - return authScope.match(new AuthScope(config.getHostname(), config.getPort())) >= HOST_AND_PORT_MATCH; - } - - private static Credentials createNTCredentials(final ProxyConfiguration config) { - final String domainAndUsername = config.getUsername(); - final String username; - final String domain; - final int index = domainAndUsername.indexOf("\\"); - if (index > -1) { - username = domainAndUsername.substring(index + 1); - domain = domainAndUsername.substring(0, index); - } else { - username = domainAndUsername; - domain = null; - } - return new NTCredentials(username, config.getPassword().toCharArray(), null, domain); - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java deleted file mode 100644 index 2807b29cc..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiHttpRoutePlanner.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.apache.hc.client5.http.osgi.impl.HostMatcher.HostMatcherFactory.createMatcher; - -import java.util.List; - -import org.apache.hc.client5.http.impl.routing.DefaultRoutePlanner; -import org.apache.hc.client5.http.osgi.services.ProxyConfiguration; -import org.apache.hc.core5.http.HttpException; -import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.protocol.HttpContext; - -/** - * @since 4.3 - */ -final class OSGiHttpRoutePlanner extends DefaultRoutePlanner { - - private final List proxyConfigurations; - - public OSGiHttpRoutePlanner(final List proxyConfigurations) { - super(null); - this.proxyConfigurations = proxyConfigurations; - } - - /** - * {@inheritDoc} - */ - @Override - protected HttpHost determineProxy(final HttpHost target, final HttpContext context) throws HttpException { - HttpHost proxyHost = null; - for (final ProxyConfiguration proxyConfiguration : proxyConfigurations) { - if (proxyConfiguration.isEnabled()) { - for (final String exception : proxyConfiguration.getProxyExceptions()) { - if (createMatcher(exception).matches(target.getHostName())) { - return null; - } - } - if (null == proxyHost) { - proxyHost = new HttpHost(proxyConfiguration.getHostname(), proxyConfiguration.getPort()); - } - } - } - - return proxyHost; - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfiguration.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfiguration.java deleted file mode 100644 index 27897e54b..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfiguration.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static java.lang.String.format; -import static java.util.Arrays.asList; -import static org.apache.hc.client5.http.osgi.impl.PropertiesUtils.to; - -import java.util.Dictionary; - -import org.apache.hc.client5.http.osgi.services.ProxyConfiguration; - -/** - * @since 4.3 - */ -public final class OSGiProxyConfiguration implements ProxyConfiguration { - - /** - * Property indicating whether this particular proxy is enabled (shall be used or not). Defaults to true. - */ - private static final String PROPERTYNAME_PROXY_ENABLED = "proxy.enabled"; - - private static final Boolean PROPERTYDEFAULT_PROXY_ENABLED = Boolean.TRUE; - - /** - * Property representing the hostname of the proxy. Defaults to empty. - */ - private static final String PROPERTYNAME_PROXY_HOSTNAME = "proxy.host"; - - private static final String PROPERTYDEFAULT_PROXY_HOSTNAME = ""; - - /** - * Property representing the port of the proxy. Defaults to 0. - */ - private static final String PROPERTYNAME_PROXY_PORT = "proxy.port"; - - private static final Integer PROPERTYDEFAULT_PROXY_PORT = Integer.valueOf(0); - - /** - * Property representing the username to authenticate with towards the proxy. Defaults to empty. - */ - private static final String PROPERTYNAME_PROXY_USERNAME = "proxy.user"; - - private static final String PROPERTYDEFAULT_PROXY_USERNAME = ""; - - /** - * Property representing the password to authenticate with towards the proxy. Defaults to empty. - */ - private static final String PROPERTYNAME_PROXY_PASSWORD = "proxy.password"; - - private static final String PROPERTYDEFAULT_PROXY_PASSWORD = ""; - - /** - * A multivalue property representing host patterns for which no proxy shall be used. By default localhost is - * excluded. - */ - private static final String PROPERTYNAME_PROXY_EXCEPTIONS = "proxy.exceptions"; - - private static final String[] PROPERTYDEFAULT_PROXY_EXCEPTIONS = new String[]{"localhost", "127.0.0.1"}; - - private Boolean enabled = Boolean.FALSE; // fewer boxing conversions needed when stored as an object - - private String hostname; - - private Integer port = Integer.valueOf(0); // fewer boxing conversions needed when stored as an object - - private String username; - - private String password; - - private String[] proxyExceptions; - - @Override - public boolean isEnabled() { - return enabled.booleanValue(); - } - - @Override - public String getHostname() { - return hostname; - } - - @Override - public int getPort() { - return port.intValue(); - } - - @Override - public String getUsername() { - return username; - } - - @Override - public String getPassword() { - return password; - } - - @Override - public String[] getProxyExceptions() { - return proxyExceptions; - } - - public void update(final Dictionary config) { - enabled = to(config.get(PROPERTYNAME_PROXY_ENABLED), boolean.class, PROPERTYDEFAULT_PROXY_ENABLED); - hostname = to(config.get(PROPERTYNAME_PROXY_HOSTNAME), String.class, PROPERTYDEFAULT_PROXY_HOSTNAME); - port = to(config.get(PROPERTYNAME_PROXY_PORT), int.class, PROPERTYDEFAULT_PROXY_PORT); - username = to(config.get(PROPERTYNAME_PROXY_USERNAME), String.class, PROPERTYDEFAULT_PROXY_USERNAME); - password = to(config.get(PROPERTYNAME_PROXY_PASSWORD), String.class, PROPERTYDEFAULT_PROXY_PASSWORD); - proxyExceptions = to(config.get(PROPERTYNAME_PROXY_EXCEPTIONS), String[].class, PROPERTYDEFAULT_PROXY_EXCEPTIONS); - } - - @Override - public String toString() { - return format("ProxyConfiguration [enabled=%s, hostname=%s, port=%s, username=%s, password=%s, proxyExceptions=%s]", - enabled, hostname, port, username, password, asList(proxyExceptions)); - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiTrustedHostsConfiguration.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiTrustedHostsConfiguration.java deleted file mode 100644 index d6c37011c..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/OSGiTrustedHostsConfiguration.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static java.lang.String.format; -import static java.util.Arrays.asList; -import static org.apache.hc.client5.http.osgi.impl.PropertiesUtils.to; - -import java.util.Dictionary; - -import org.apache.hc.client5.http.osgi.services.TrustedHostsConfiguration; -import org.osgi.service.cm.ConfigurationException; -import org.osgi.service.cm.ManagedService; - -/** - * @since 5.0-alpha2 - */ -final class OSGiTrustedHostsConfiguration implements ManagedService, TrustedHostsConfiguration { - - /** - * Property indicating whether this particular configuration is enabled (shall be used or not). Defaults to true. - */ - private static final String PROPERTYNAME_TRUSTEDHOSTS_ENABLED = "trustedhosts.enabled"; - - private static final Boolean PROPERTYDEFAULT_TRUSTEDHOSTS_ENABLED = Boolean.TRUE; - - /** - * Property indicating whether this particular configuration . Defaults to false. - */ - private static final String PROPERTYNAME_TRUST_ALL = "trustedhosts.trustAll"; - - private static final Boolean PROPERTYDEFAULT_TRUST_ALL = Boolean.FALSE; - - /** - * A multivalue property representing host patterns which is an acceptable match with the server's authentication scheme. - * By default localhost (127.0.0.1) is trusted. - */ - private static final String PROPERTYNAME_TRUSTED_HOSTS = "trustedhosts.hosts"; - - private static final String[] PROPERTYDEFAULT_TRUSTED_HOSTS = new String[]{ "localhost", "127.0.0.1" }; - - private Boolean enabled = PROPERTYDEFAULT_TRUSTEDHOSTS_ENABLED; // fewer boxing conversions needed when stored as an object - - private Boolean trustAll = PROPERTYDEFAULT_TRUST_ALL; // fewer boxing conversions needed when stored as an object - - private String[] trustedHosts; - - @Override - public boolean isEnabled() { - return enabled; - } - - @Override - public boolean trustAll() { - return trustAll; - } - - @Override - public String[] getTrustedHosts() { - return trustedHosts; - } - - @Override - public void updated(final Dictionary config) throws ConfigurationException { - if (config == null) { - return; - } - - enabled = to(config.get(PROPERTYNAME_TRUSTEDHOSTS_ENABLED), boolean.class, PROPERTYDEFAULT_TRUSTEDHOSTS_ENABLED); - trustAll = to(config.get(PROPERTYNAME_TRUST_ALL), boolean.class, PROPERTYDEFAULT_TRUST_ALL); - trustedHosts = to(config.get(PROPERTYNAME_TRUSTED_HOSTS), String[].class, PROPERTYDEFAULT_TRUSTED_HOSTS); - } - - @Override - public String toString() { - return format("ProxyConfiguration [enabled=%s, trustAll=%s, trustedHosts=%s]", - enabled, trustAll, asList(trustedHosts)); - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/PropertiesUtils.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/PropertiesUtils.java deleted file mode 100644 index faa385029..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/PropertiesUtils.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @since 4.3 - */ -final class PropertiesUtils { - - private static final Map, PropertyConverter> CONVERTERS_REGISTRY = - new HashMap<>(); - - static { - register(new BooleanPropertyConverter(), boolean.class, Boolean.class); - register(new StringPropertyConverter(), String.class); - register(new StringArrayPropertyConverter(), String[].class); - register(new IntegerPropertyConverter(), int.class, Integer.class); - register(new LongPropertyConverter(), long.class, Long.class); - register(new DoublePropertyConverter(), double.class, Double.class); - } - - private static void register(final PropertyConverter converter, final Class...targetTypes) { - for (final Class targetType : targetTypes) { - CONVERTERS_REGISTRY.put(targetType, converter); - } - } - - public static T to(final Object propValue, final Class targetType, final T defaultValue) { - Object v = propValue; - if (v == null) { - return defaultValue; - } - - if (!targetType.isArray()) { - v = toObject(v); - } - - if (targetType.isInstance(v)) { - return targetType.cast(v); - } - - if (CONVERTERS_REGISTRY.containsKey(targetType)) { - @SuppressWarnings("unchecked") final // type driven by targetType - PropertyConverter converter = (PropertyConverter) CONVERTERS_REGISTRY.get(targetType); - try { - return converter.to(v); - } catch (final Exception ignore) { - } - } - - return defaultValue; - } - - /** - * Returns the parameter as a single value. If the - * parameter is neither an array nor a {@code java.util.Collection} the - * parameter is returned unmodified. If the parameter is a non-empty array, - * the first array element is returned. If the property is a non-empty - * {@code java.util.Collection}, the first collection element is returned. - * - * @param propValue the parameter to convert. - */ - private static Object toObject(final Object propValue) { - if (propValue.getClass().isArray()) { - final Object[] prop = (Object[]) propValue; - return prop.length > 0 ? prop[0] : null; - } - - if (propValue instanceof Collection) { - final Collection prop = (Collection) propValue; - return prop.isEmpty() ? null : prop.iterator().next(); - } - - return propValue; - } - - /** - * Hidden constructor, this class must not be instantiated. - */ - private PropertiesUtils() { - // do nothing - } - - private interface PropertyConverter { - - T to(Object propValue); - - } - - private static class BooleanPropertyConverter implements PropertyConverter { - - @Override - public Boolean to(final Object propValue) { - return Boolean.valueOf(String.valueOf(propValue)); - } - - } - - private static class StringPropertyConverter implements PropertyConverter { - - @Override - public String to(final Object propValue) { - return String.valueOf(propValue); - } - - } - - private static class StringArrayPropertyConverter implements PropertyConverter { - - @Override - public String[] to(final Object propValue) { - if (propValue instanceof String) { - // single string - return new String[] { (String) propValue }; - } - - if (propValue.getClass().isArray()) { - // other array - final Object[] valueArray = (Object[]) propValue; - final List values = new ArrayList<>(valueArray.length); - for (final Object value : valueArray) { - if (value != null) { - values.add(value.toString()); - } - } - return values.toArray(new String[values.size()]); - - } - - if (propValue instanceof Collection) { - // collection - final Collection valueCollection = (Collection) propValue; - final List valueList = new ArrayList<>(valueCollection.size()); - for (final Object value : valueCollection) { - if (value != null) { - valueList.add(value.toString()); - } - } - return valueList.toArray(new String[valueList.size()]); - } - - // don't care, fall through to default value - throw new IllegalArgumentException(); - } - - } - - private static class IntegerPropertyConverter implements PropertyConverter { - - @Override - public Integer to(final Object propValue) { - return Integer.valueOf(String.valueOf(propValue)); - } - - } - - private static class LongPropertyConverter implements PropertyConverter { - - @Override - public Long to(final Object propValue) { - return Long.valueOf(String.valueOf(propValue)); - } - - } - - private static class DoublePropertyConverter implements PropertyConverter { - - @Override - public Double to(final Object propValue) { - return Double.valueOf(String.valueOf(propValue)); - } - - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java deleted file mode 100644 index f0858571d..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/RelaxedLayeredConnectionSocketFactory.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.apache.hc.client5.http.osgi.impl.HostMatcher.HostMatcherFactory.createMatcher; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; - -import org.apache.hc.client5.http.osgi.services.TrustedHostsConfiguration; -import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory; -import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.protocol.HttpContext; -import org.apache.hc.core5.util.TimeValue; - -final class RelaxedLayeredConnectionSocketFactory implements LayeredConnectionSocketFactory { - - private final TrustedHostsConfiguration trustedHostsConfiguration; - - private final LayeredConnectionSocketFactory defaultSocketFactory; - - public RelaxedLayeredConnectionSocketFactory(final TrustedHostsConfiguration trustedHostsConfiguration, - final LayeredConnectionSocketFactory defaultSocketFactory) { - this.trustedHostsConfiguration = trustedHostsConfiguration; - this.defaultSocketFactory = defaultSocketFactory; - } - - @Override - public Socket createLayeredSocket(final Socket socket, - final String target, - final int port, - final HttpContext context) throws IOException { - if (trustedHostsConfiguration.isEnabled()) { - // if trust all there is no check to perform - if (trustedHostsConfiguration.trustAll()) { - return socket; - } - - // blindly verify the host if in the trust list - for (final String trustedHost : trustedHostsConfiguration.getTrustedHosts()) { - if (createMatcher(trustedHost).matches(target)) { - return socket; - } - } - } - - // fall back to the default behavior - return defaultSocketFactory.createLayeredSocket(socket, target, port, context); - } - - @Override - public Socket createSocket(final HttpContext context) throws IOException { - return defaultSocketFactory.createSocket(context); - } - - @Override - public Socket connectSocket(final TimeValue connectTimeout, - final Socket sock, - final HttpHost host, - final InetSocketAddress remoteAddress, - final InetSocketAddress localAddress, - final HttpContext context) throws IOException { - return defaultSocketFactory.connectSocket(connectTimeout, sock, host, remoteAddress, localAddress, context); - } - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/WeakList.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/WeakList.java deleted file mode 100644 index 815bc046f..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/WeakList.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import java.lang.ref.WeakReference; -import java.util.AbstractList; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.NoSuchElementException; - -/** - * Implementation of a list backed by WeakReference objects. - * This is not a general purpose list and is only meant to be used by this package. It cannot correctly manage null entries by design. - */ -class WeakList extends AbstractList { - - private final List> innerList; - - public WeakList() { - this.innerList = new ArrayList<>(); - } - - @Override - public T get(final int index) { - return innerList.get(index).get(); - } - - @Override - public int size() { - checkReferences(); - return innerList.size(); - } - - @Override - public boolean add(final T t) { - return innerList.add(new WeakReference<>(t)); - } - - @Override - public void clear() { - innerList.clear(); - } - - private void checkReferences() { - final ListIterator> references = innerList.listIterator(); - while (references.hasNext()) { - final WeakReference reference = references.next(); - if (reference.get() == null) { - references.remove(); - } - } - } - - @Override - public Iterator iterator() { - return new WeakIterator<>(innerList.iterator()); - } - - private class WeakIterator implements Iterator { - - private final Iterator> innerIterator; - - private WeakReference next; - - public WeakIterator(final Iterator> innerIterator) { - this.innerIterator = innerIterator; - fetchNext(); - } - - @Override - public boolean hasNext() { - return next != null; - } - - @Override - public T next() { - if (next != null) { - final T result = next.get(); - fetchNext(); - return result; - } - throw new NoSuchElementException(); - } - - private void fetchNext() { - while (innerIterator.hasNext()) { - final WeakReference ref = innerIterator.next(); - final T obj = ref.get(); - if (obj != null) { - next = ref; - return; - } - } - next = null; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - } -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/package-info.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/package-info.java deleted file mode 100644 index eeef61586..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/impl/package-info.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/package-info.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/package-info.java deleted file mode 100644 index 1cb82bc9d..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/package-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ - -/** - * @since 4.3 - */ -package org.apache.hc.client5.http.osgi; diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java deleted file mode 100644 index d94e84b2f..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/CachingHttpClientBuilderFactory.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.services; - -import org.apache.hc.client5.http.impl.cache.CachingHttpClientBuilder; - -public interface CachingHttpClientBuilderFactory { - - CachingHttpClientBuilder newBuilder(); - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/HttpClientBuilderFactory.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/HttpClientBuilderFactory.java deleted file mode 100644 index b0b62b4f6..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/HttpClientBuilderFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.services; - -import org.apache.hc.client5.http.impl.classic.HttpClientBuilder; - -/** - * @since 4.3 - */ -public interface HttpClientBuilderFactory { - - HttpClientBuilder newBuilder(); - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/ProxyConfiguration.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/ProxyConfiguration.java deleted file mode 100644 index f539762ee..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/ProxyConfiguration.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.services; - -/** - * @since 4.3 - */ -public interface ProxyConfiguration { - - boolean isEnabled(); - - String getHostname(); - - int getPort(); - - String getUsername(); - - String getPassword(); - - String[] getProxyExceptions(); - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/TrustedHostsConfiguration.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/TrustedHostsConfiguration.java deleted file mode 100644 index fc23316f7..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/TrustedHostsConfiguration.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.services; - -/** - * @since 5.0-alpha2 - */ -public interface TrustedHostsConfiguration { - - /** - * Flag to mark if current configuration has to be processed when creating SSL sessions.. - * - * @return true if current configuration has to be processed when creating an SSL session, false otherwise. - */ - boolean isEnabled(); - - /** - * Flag to mark all SSL certificates are blindly trusted by the client. - * - * Pay attention on no enabling this feature in production environment as it is totally insecure. - * - * @return true if all SSL certificates are blindly trusted by the client, false otherwise. - */ - boolean trustAll(); - - /** - * The list of trusted hosts for which self-signed certificate is acceptable. - * - * @return an array representing the list of trusted hosts for which self-signed certificate is acceptable. - */ - String[] getTrustedHosts(); - -} diff --git a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/package-info.java b/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/package-info.java deleted file mode 100644 index a8e2267c6..000000000 --- a/httpclient5-osgi/src/main/java/org/apache/hc/client5/http/osgi/services/package-info.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ - -/** - * @since 4.3 - */ -package org.apache.hc.client5.http.osgi.services; diff --git a/httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.properties b/httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.properties deleted file mode 100644 index 888a023ae..000000000 --- a/httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.properties +++ /dev/null @@ -1,94 +0,0 @@ -# -# 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. -# - -proxyconfigurator.name = Apache HTTP Components Proxy Configurator -proxyconfigurator.description = Factory configuration for transparent proxies used by every HTTP Client. - -proxyconfig.name = Apache HTTP Components Proxy Configuration -proxyconfig.description = Proxy configuration for central and transparent proxying of http client connections. - -proxy.enabled.name = Enable HTTP Proxy -proxy.enabled.description = Whether to enable or disable this particular proxy configuration. \ -The default value is false. - -proxy.host.name = HTTP Proxy Host -proxy.host.description = Host name (or IP Address) of the HTTP Proxy. This property is ignored if \ - this proxy configuration is disabled. This property does not have a default value. Enabling \ - this proxy but not setting the HTTP Proxy Host effectively disables this configuration. - -proxy.port.name = HTTP Proxy Port -proxy.port.description = TCP port of the HTTP Proxy. This property is ignored if \ - this proxy configuration is disabled. This property does not have a default value. Enabling \ - this proxy but not setting the HTTP Proxy Port effectively disables this configuration. - -proxy.user.name = HTTP Proxy User -proxy.user.description = The name of the user to authenticate as with the HTTP \ - Proxy Host. If this field is empty, the proxy is considered to not be \ - authenticated. The default is empty. This property is ignored if proxying is \ - disabled or the proxy host is not properly configured. - -proxy.password.name = HTTP Proxy Password -proxy.password.description = The password of the HTTP Proxy user to authenticate \ - with. The default is empty. This property is ignored if proxying is \ - disabled or the proxy host is not properly configured. - -proxy.ntlm.host.name = HTTP Proxy NTLM Host -proxy.ntlm.host.description = The host the authentication request is \ - originating from. Essentially, the computer name for this machine. By default \ - the credentials assume simple username password authentication. If the proxy \ - happens to be a Microsoft IIS Server using NTLM authentication this property \ - must be set to the NT Domain name of the user to authenticate as. This is \ - not set by default. - -proxy.ntlm.domain.name = HTTP Proxy NTLM Domain -proxy.ntlm.domain.description = The NTLM domain to authenticate within. By \ - default the credentials assume simple username password authentication. If \ - the proxy happens to be a Microsoft IIS Server using NTLM authentication this \ - property must be set to the NT Domain name of the user to authenticate as. \ - This is not set by default. - -proxy.exceptions.name = No Proxy For -proxy.exceptions.description = Lists domain names, host names, IP Addresses or \ - or network addresses for which this proxy configuration should not be used. A domain \ - name indicating all hosts of a domain is indicated by a leading dot, e.g. \ - ".day.com". A network address is indicated with subnet mask notation indicating \ - the number of bits make up the network address, e.g 192.168.1.0/24 means the \ - class C network "192.168.1". Note that for proxy selection, the host name of \ - URL is not resolved but directly compared to the list of exceptions. For this \ - reason you might want to indicate both the network address and the domain for \ - targets which should not be passed through the proxy. This property has no \ - effect if this proxy configuration is disabled. The default value is [ localhost, \ - 127.0.0.1 ]. - -trustedhosts.name = Apache HTTP Client Trusted Hosts Configuration -trustedhosts.description = SSL configuration for trusted SSL connections with server self-signed certificates. - -trustedhosts.enabled.name = SSL configuration enabled -trustedhosts.enabled.description = Mark this SSL configuration be taken in consideration \ - when creating a new HTTP CLient instance. - -trustedhosts.trustAll.name = Trust all SSL certificates -trustedhosts.trustAll.description = Allows the new HTTP Client instance to \ - blindly trust all SSL certificates.\ - Pay attention on no enabling this feature in production environment as it is totally insecure! - -trustedhosts.hosts.name = Trust SSL self-signed certificates only for specified hosts -trustedhosts.hosts.description = Allows the new HTTP Client instance to \ - trust all SSL self-signed certificates coming only from the specified hosts. \ - The default value is [ localhost, 127.0.0.1 ]. diff --git a/httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.xml b/httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.xml deleted file mode 100644 index 8f481edfd..000000000 --- a/httpclient5-osgi/src/main/resources/OSGI-INF/metatype/metatype.xml +++ /dev/null @@ -1,108 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/HostMatcherTest.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/HostMatcherTest.java deleted file mode 100644 index f5acde9fa..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/HostMatcherTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import org.apache.hc.client5.http.osgi.impl.HostMatcher.DomainNameMatcher; -import org.apache.hc.client5.http.osgi.impl.HostMatcher.HostMatcherFactory; -import org.apache.hc.client5.http.osgi.impl.HostMatcher.HostNameMatcher; -import org.apache.hc.client5.http.osgi.impl.HostMatcher.IPAddressMatcher; -import org.apache.hc.client5.http.osgi.impl.HostMatcher.NetworkAddress; -import org.junit.Test; - -public final class HostMatcherTest { - - @Test - public void testNetworkAddress() { - final NetworkAddress nullNetworkAddress = NetworkAddress.parse("www.apache.org"); - assertNull(nullNetworkAddress); - - final NetworkAddress na = NetworkAddress.parse("127.0.0.1"); - assertEquals(2130706433, na.address); - assertEquals(-2147483648, na.mask); - } - - @Test - public void testIPAddressMatcher() { - final NetworkAddress na = NetworkAddress.parse("127.0.0.1"); - final IPAddressMatcher ipam = new IPAddressMatcher(na); - assertFalse(ipam.matches("127.0.0.255")); - } - - @Test - public void testDomainNameMatcher() { - final DomainNameMatcher dnm = new DomainNameMatcher(".apache.org"); - assertTrue(dnm.matches("www.apache.org")); - assertTrue(dnm.matches("hc.apache.org")); - assertTrue(dnm.matches("commons.apache.org")); - assertTrue(dnm.matches("cocoon.apache.org")); - assertFalse(dnm.matches("www.gnu.org")); - } - - @Test - public void testHostNameMatcher() { - final HostNameMatcher hnm = new HostNameMatcher("www.apache.org"); - assertTrue(hnm.matches("www.apache.org")); - assertTrue(hnm.matches("WwW.APACHE.org")); - assertTrue(hnm.matches("wWw.apache.ORG")); - assertTrue(hnm.matches("WWW.APACHE.ORG")); - assertFalse(hnm.matches("www.gnu.org")); - } - - @Test - public void testHostMatcherFactory() { - assertTrue(HostMatcherFactory.createMatcher("127.0.0.1") instanceof IPAddressMatcher); - assertTrue(HostMatcherFactory.createMatcher(".apache.org") instanceof DomainNameMatcher); - assertTrue(HostMatcherFactory.createMatcher("www.apache.org") instanceof HostNameMatcher); - } - -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProviderTest.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProviderTest.java deleted file mode 100644 index 43b7e0ad9..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiCredentialsProviderTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static java.util.Arrays.asList; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; - -import java.util.Hashtable; - -import org.apache.hc.client5.http.auth.AuthScope; -import org.apache.hc.client5.http.auth.Credentials; -import org.apache.hc.client5.http.auth.CredentialsProvider; -import org.apache.hc.client5.http.auth.NTCredentials; -import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; -import org.apache.hc.client5.http.osgi.services.ProxyConfiguration; -import org.apache.hc.core5.http.protocol.BasicHttpContext; -import org.apache.hc.core5.http.protocol.HttpContext; -import org.junit.Test; - -public class OSGiCredentialsProviderTest { - - private static final String HOST = "proxy.example.org"; - - private static final int PORT = 8080; - - private static final HttpContext HTTP_CONTEXT = new BasicHttpContext(); - - @Test - public void basicAuthentication() { - final CredentialsProvider provider = credentialsProvider(proxy("user", "secret")); - final Credentials credentials = provider.getCredentials(new AuthScope("http", HOST, PORT, null, "BASIC"), HTTP_CONTEXT); - assertThat(credentials, instanceOf(UsernamePasswordCredentials.class)); - assertCredentials((UsernamePasswordCredentials) credentials, "user", "secret"); - } - - @Test - public void ntlmAuthenticationWithoutDomain() { - final CredentialsProvider provider = credentialsProvider(proxy("user", "secret")); - final Credentials credentials = provider.getCredentials(new AuthScope("http", HOST, PORT, null, "NTLM"), HTTP_CONTEXT); - assertThat(credentials, instanceOf(NTCredentials.class)); - assertCredentials((NTCredentials) credentials, "user", "secret", null); - } - - @Test - public void ntlmAuthenticationWithDomain() { - final CredentialsProvider provider = credentialsProvider(proxy("DOMAIN\\user", "secret")); - final Credentials credentials = provider.getCredentials(new AuthScope("http", HOST, PORT, null, "NTLM"), HTTP_CONTEXT); - assertThat(credentials, instanceOf(NTCredentials.class)); - assertCredentials((NTCredentials) credentials, "user", "secret", "DOMAIN"); - } - - private CredentialsProvider credentialsProvider(final ProxyConfiguration... proxies) { - return new OSGiCredentialsProvider(asList(proxies)); - } - - private void assertCredentials(final UsernamePasswordCredentials credentials, final String user, final String password) { - assertThat("Username mismatch", credentials.getUserName(), equalTo(user)); - assertThat("Password mismatch", credentials.getPassword(), equalTo(password.toCharArray())); - } - - private void assertCredentials(final NTCredentials credentials, final String user, final String password, final String domain) { - assertThat("Username mismatch", credentials.getUserName(), equalTo(user)); - assertThat("Password mismatch", credentials.getPassword(), equalTo(password.toCharArray())); - assertThat("Domain mismatch", credentials.getDomain(), equalTo(domain)); - } - - private ProxyConfiguration proxy(final String username, final String password) { - final OSGiProxyConfiguration proxyConfiguration = new OSGiProxyConfiguration(); - final Hashtable config = new Hashtable<>(); - config.put("proxy.enabled", true); - config.put("proxy.host", HOST); - config.put("proxy.port", PORT); - config.put("proxy.user", username); - config.put("proxy.password", password); - config.put("proxy.exceptions", new String[0]); - proxyConfiguration.update(config); - return proxyConfiguration; - } -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfigurationTest.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfigurationTest.java deleted file mode 100644 index 7d99ff42b..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/OSGiProxyConfigurationTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; - -import java.util.Dictionary; -import java.util.Hashtable; - -import org.junit.Test; - -public class OSGiProxyConfigurationTest { - - @Test - public void testToString() { - - final Dictionary config = new Hashtable<>(); - config.put("proxy.enabled", false); - config.put("proxy.host", "h"); - config.put("proxy.port", 1); - config.put("proxy.user", "u"); - config.put("proxy.password", "p"); - config.put("proxy.exceptions", new String[]{"e"}); - - final OSGiProxyConfiguration configuration = new OSGiProxyConfiguration(); - configuration.update(config); - - final String string = configuration.toString(); - assertThat(string, containsString("enabled=false")); - assertThat(string, containsString("hostname=h")); - assertThat(string, containsString("port=1")); - assertThat(string, containsString("username=u")); - assertThat(string, containsString("password=p")); - assertThat(string, containsString("proxyExceptions=[e]")); - } -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java deleted file mode 100644 index 57fb99aa2..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiHttpRoutePlanner.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.net.InetAddress; -import java.util.Hashtable; - -import org.apache.hc.client5.http.osgi.services.ProxyConfiguration; -import org.apache.hc.core5.http.HttpHost; -import org.junit.Test; - -/** - * @since 4.4.3 - */ -public class TestOSGiHttpRoutePlanner { - - private final ProxyConfiguration pc1 = proxy("proxy1", 8080, "localhost", "127.0.0.1", ".apache.org"); - private final ProxyConfiguration pc2 = proxy("proxy2", 9090, "localhost", "127.0.0.1", ".oracle.com", "12.34.34.8"); - - @Test - public void testDeterminProxy() throws Exception { - OSGiHttpRoutePlanner planner = new OSGiHttpRoutePlanner(singletonList(pc1)); - - HttpHost proxy = planner.determineProxy(new HttpHost("localhost", 8090), null); - assertNull(proxy); - - proxy = planner.determineProxy(new HttpHost("there", 9090), null); - assertNotNull(proxy); - assertTrue(proxy.getHostName().equals("proxy1")); - - proxy = planner.determineProxy(new HttpHost("10.2.144.23", 4554), null); - assertNotNull(proxy); - assertTrue(proxy.getHostName().equals("proxy1")); - - final InetAddress addr = InetAddress.getByName("localhost"); - proxy = planner.determineProxy(new HttpHost(addr, 4554), null); - assertNull(proxy); - - proxy = planner.determineProxy(new HttpHost("hc.apache.org", 4554), null); - assertNull(proxy); - - - // test with more than one registration of proxyConfiguration - planner = new OSGiHttpRoutePlanner(asList(pc1, pc2)); - proxy = planner.determineProxy(new HttpHost("localhost", 8090), null); - assertNull(proxy); - - proxy = planner.determineProxy(new HttpHost("there", 9090), null); - assertNotNull(proxy); - assertTrue(proxy.getHostName().equals("proxy1")); // the first one - - proxy = planner.determineProxy(new HttpHost(addr, 4554), null); - assertNull(proxy); - - proxy = planner.determineProxy(new HttpHost("hc.apache.org", 4554), null); - assertNull(proxy); - - proxy = planner.determineProxy(new HttpHost("docs.oracle.com", 4554), null); - assertNull(proxy); - } - - @Test - public void testMasking() throws Exception { - final OSGiHttpRoutePlanner planner = new OSGiHttpRoutePlanner(singletonList(pc2)); - - HttpHost proxy = planner.determineProxy(new HttpHost("12.34.34.2", 4554), null); - assertNotNull(proxy); - assertTrue(proxy.getHostName().equals("proxy2")); - - proxy = planner.determineProxy(new HttpHost("12.34.34.8", 4554), null); - assertNotNull(proxy); - } - - private ProxyConfiguration proxy(final String host, final int port, final String... exceptions) { - final OSGiProxyConfiguration proxyConfiguration = new OSGiProxyConfiguration(); - final Hashtable config = new Hashtable<>(); - config.put("proxy.enabled", true); - config.put("proxy.host", host); - config.put("proxy.port", port); - config.put("proxy.user", ""); - config.put("proxy.password", ""); - config.put("proxy.exceptions", exceptions); - proxyConfiguration.update(config); - return proxyConfiguration; - } - -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiTrustedHostsConfiguration.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiTrustedHostsConfiguration.java deleted file mode 100644 index 73d7cbce3..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestOSGiTrustedHostsConfiguration.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.Dictionary; -import java.util.Hashtable; - -import org.apache.hc.client5.http.osgi.services.TrustedHostsConfiguration; -import org.junit.Test; -import org.osgi.service.cm.ConfigurationException; - -public final class TestOSGiTrustedHostsConfiguration { - - @Test - public void testSetValues() throws ConfigurationException { - final TrustedHostsConfiguration configuration = getTrustedHostsConfiguration(); - - assertEquals(true, configuration.isEnabled()); - assertEquals(false, configuration.trustAll()); - assertArrayEquals(new String[]{ "localhost" }, configuration.getTrustedHosts()); - } - - @Test - public void testToString() throws ConfigurationException { - final TrustedHostsConfiguration configuration = getTrustedHostsConfiguration(); - - final String string = configuration.toString(); - assertThat(string, containsString("enabled=true")); - assertThat(string, containsString("trustAll=false")); - assertThat(string, containsString("trustedHosts=[localhost]")); - } - - private TrustedHostsConfiguration getTrustedHostsConfiguration() throws ConfigurationException { - final Dictionary config = new Hashtable<>(); - config.put("trustedhosts.enabled", true); - config.put("trustedhosts.trustAll", false); - config.put("trustedhosts.hosts", new String[]{ "localhost" }); - - final OSGiTrustedHostsConfiguration configuration = new OSGiTrustedHostsConfiguration(); - configuration.updated(config); - return configuration; - } - -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestPropertiesUtils.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestPropertiesUtils.java deleted file mode 100644 index a64218bad..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestPropertiesUtils.java +++ /dev/null @@ -1,132 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.apache.hc.client5.http.osgi.impl.PropertiesUtils.to; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -/** - * @since 4.3 - */ -@SuppressWarnings("boxing") // test code -public final class TestPropertiesUtils { - - @Test - public void toBoolean() { - assertConverted(true, null, boolean.class, true); - assertConverted(true, null, Boolean.class, true); - assertConverted(false, "false", boolean.class, null); - assertConverted(false, "false", Boolean.class, null); - // whatever value is interpreted as `false` by Boolean.valueOf - assertConverted(false, "not a boolean", boolean.class, true); - assertConverted(false, "not a boolean", Boolean.class, true); - } - - @Test - public void toSingleString() { - assertConverted("fallback to default value", null, String.class, "fallback to default value"); - // use an object which represents the string - assertConverted("use the passed value", new StringBuilder("use the passed value"), String.class, null); - // use the "identity" converter - assertConverted("use the passed value", "use the passed value", String.class, null); - // convert another object - assertConverted("456789", 456789, String.class, null); - } - - @Test - public void toStringArray() { - assertConvertedArray(new String[]{"fallback to default value"}, - null, - String[].class, - new String[]{"fallback to default value"}); - // a string is converted to an array with 1 element - assertConvertedArray(new String[]{"a single string"}, - "a single string", - String[].class, - null); - // use an object which represents the string - assertConvertedArray(new String[]{"null objects", "will be ignored"}, - new Object[]{new StringBuilder("null objects"), null, new StringBuilder("will be ignored")}, - String[].class, - null); - // use the "identity" converter - assertConvertedArray(new String[]{"null objects", "will be ignored"}, - new Object[]{"null objects", null, "will be ignored"}, - String[].class, - null); - assertConvertedArray(new String[]{"fallback to default value"}, - 456789, - String[].class, - new String[]{"fallback to default value"}); - } - - @Test - public void toInt() { - assertConverted(123, null, int.class, 123); - assertConverted(123, null, Integer.class, 123); - assertConverted(456, "456", int.class, null); - assertConverted(456, "456", Integer.class, null); - assertConverted(789, "not an integer", int.class, 789); - assertConverted(789, "not an integer", Integer.class, 789); - } - - @Test - public void toLong() { - assertConverted(123l, null, long.class, 123l); - assertConverted(123l, null, Long.class, 123l); - assertConverted(456l, "456", long.class, null); - assertConverted(456l, "456", Long.class, null); - assertConverted(789l, "not a long", long.class, 789l); - assertConverted(789l, "not a long", Long.class, 789l); - } - - @Test - public void toDouble() { - assertConverted(123d, null, double.class, 123d); - assertConverted(123d, null, Double.class, 123d); - assertConverted(456d, "456", double.class, null); - assertConverted(456d, "456", Double.class, null); - assertConverted(789d, "not a double", double.class, 789d); - assertConverted(789d, "not a double", Double.class, 789d); - } - - private static void assertConverted( - final T expected, final Object propValue, final Class targetType, final T defaultValue) { - final T actual = to(propValue, targetType, defaultValue); - assertEquals(expected, actual); - } - - private static void assertConvertedArray( - final T[] expected, final Object propValue, final Class targetType, final T[] defaultValue) { - final T[] actual = to(propValue, targetType, defaultValue); - assertArrayEquals(expected, actual); - } - -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestRelaxedLayeredConnectionSocketFactory.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestRelaxedLayeredConnectionSocketFactory.java deleted file mode 100644 index 94980ff09..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/TestRelaxedLayeredConnectionSocketFactory.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.junit.Assert.assertSame; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.util.Dictionary; -import java.util.Hashtable; - -import org.apache.hc.client5.http.socket.LayeredConnectionSocketFactory; -import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.protocol.BasicHttpContext; -import org.apache.hc.core5.http.protocol.HttpContext; -import org.apache.hc.core5.util.TimeValue; -import org.junit.Test; -import org.mockito.Mock; -import org.osgi.service.cm.ConfigurationException; - -public class TestRelaxedLayeredConnectionSocketFactory { - - @Mock - Socket insecureSocket; - - @Mock - Socket secureSocket; - - private final HttpContext context = new BasicHttpContext(); - - @Test - public void testTrustedAllConnections() throws Exception { - final LayeredConnectionSocketFactory socketFactory = getLayeredConnectionSocketFactory(true, true); - final Socket socket = socketFactory.createSocket(context); - final Socket secureSocket = socketFactory.createLayeredSocket(socket, "localhost", 9999, context); - assertSame(this.secureSocket, secureSocket); - } - - @Test - public void testTrustedConnections() throws Exception { - final LayeredConnectionSocketFactory socketFactory = getLayeredConnectionSocketFactory(true, false, "localhost"); - final Socket socket = socketFactory.createSocket(context); - final Socket localSecureSocket = socketFactory.createLayeredSocket(socket, "localhost", 9999, context); - assertSame(this.insecureSocket, localSecureSocket); - - final Socket apacheSecureSocket = socketFactory.createLayeredSocket(socket, "www.apache.org", 9999, context); - assertSame(this.secureSocket, apacheSecureSocket); - } - - @Test - public void testNotEabledConfiguration() throws Exception { - final LayeredConnectionSocketFactory socketFactory = getLayeredConnectionSocketFactory(false, true); - final Socket socket = socketFactory.createSocket(context); - final Socket secureSocket = socketFactory.createLayeredSocket(socket, "localhost", 9999, context); - assertSame(this.secureSocket, secureSocket); - } - - private LayeredConnectionSocketFactory getLayeredConnectionSocketFactory( - final boolean enabled, final boolean trustAll, final String... trustedHosts) throws ConfigurationException { - final OSGiTrustedHostsConfiguration configuration = new OSGiTrustedHostsConfiguration(); - configuration.updated(createConfig(enabled, trustAll, trustedHosts)); - - final LayeredConnectionSocketFactory defaultSocketFactory = new LayeredConnectionSocketFactory() { - - @Override - public Socket createSocket(final HttpContext context) throws IOException { - return insecureSocket; - } - - @Override - public Socket connectSocket(final TimeValue connectTimeout, - final Socket sock, - final HttpHost host, - final InetSocketAddress remoteAddress, - final InetSocketAddress localAddress, - final HttpContext context ) throws IOException { - // not needed in this version - return insecureSocket; - } - - @Override - public Socket createLayeredSocket(final Socket socket, - final String target, - final int port, - final HttpContext context) throws IOException { - return secureSocket; - } - - }; - - return new RelaxedLayeredConnectionSocketFactory(configuration, defaultSocketFactory); - } - - private Dictionary createConfig(final boolean enabled, final boolean trustAll, final String... trustedHosts) { - final Dictionary config = new Hashtable<>(); - config.put("trustedhosts.enabled", enabled); - config.put("trustedhosts.trustAll", trustAll); - config.put("trustedhosts.hosts", trustedHosts); - return config; - } - -} diff --git a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java b/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java deleted file mode 100644 index ff0f9c7fc..000000000 --- a/httpclient5-osgi/src/test/java/org/apache/hc/client5/http/osgi/impl/WeakListTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * ==================================================================== - * 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 - * . - * - */ -package org.apache.hc.client5.http.osgi.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.junit.Test; - -public class WeakListTest { - - @Test - public void testWeakList() { - final WeakList list = new WeakList<>(); - list.add("hello"); - list.add(null); - - // null objects are seen as GC'd, so we only expect a size of 1 - assertEquals(1, list.size()); - - final Iterator it = list.iterator(); - assertTrue(it.hasNext()); - assertEquals("hello", it.next()); - assertFalse(it.hasNext()); - boolean thrown = false; - try { - it.next(); - } catch (final NoSuchElementException e) { - thrown = true; - } - assertTrue(thrown); - } - - @Test - public void clearSupported() { - final WeakList list = new WeakList<>(); - - list.add("hello"); - assertEquals(1, list.size()); - - list.clear(); - assertEquals(0, list.size()); - } - -} \ No newline at end of file diff --git a/httpclient5-osgi/src/test/resources/log4j2.xml b/httpclient5-osgi/src/test/resources/log4j2.xml deleted file mode 100644 index 0c9bfe241..000000000 --- a/httpclient5-osgi/src/test/resources/log4j2.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index e0a47d133..5e439a613 100644 --- a/pom.xml +++ b/pom.xml @@ -176,7 +176,6 @@ httpclient5-cache httpclient5-win httpclient5-testing - httpclient5-osgi