use ahc for internal http operations

This commit is contained in:
Sebastian Sdorra
2015-05-17 14:04:58 +02:00
parent a7d33529fd
commit 656085c698
8 changed files with 52 additions and 100 deletions

View File

@@ -43,7 +43,7 @@ import sonia.scm.installer.HgInstallerFactory;
import sonia.scm.installer.HgPackage;
import sonia.scm.installer.HgPackageReader;
import sonia.scm.installer.HgPackages;
import sonia.scm.net.HttpClient;
import sonia.scm.net.ahc.AdvancedHttpClient;
import sonia.scm.repository.HgConfig;
import sonia.scm.repository.HgRepositoryHandler;
@@ -89,8 +89,8 @@ public class HgConfigResource
* @param pkgReader
*/
@Inject
public HgConfigResource(HttpClient client, HgRepositoryHandler handler,
HgPackageReader pkgReader)
public HgConfigResource(AdvancedHttpClient client,
HgRepositoryHandler handler, HgPackageReader pkgReader)
{
this.client = client;
this.handler = handler;
@@ -338,7 +338,7 @@ public class HgConfigResource
//~--- fields ---------------------------------------------------------------
/** Field description */
private HttpClient client;
private AdvancedHttpClient client;
/** Field description */
private HgRepositoryHandler handler;

View File

@@ -35,7 +35,6 @@ package sonia.scm.installer;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.net.HttpClient;
import sonia.scm.repository.HgConfig;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.util.IOUtil;
@@ -44,6 +43,7 @@ import sonia.scm.util.IOUtil;
import java.io.File;
import java.io.IOException;
import sonia.scm.net.ahc.AdvancedHttpClient;
/**
*
@@ -93,7 +93,7 @@ public abstract class AbstractHgInstaller implements HgInstaller
* @return
*/
@Override
public boolean installPackage(HttpClient client, HgRepositoryHandler handler,
public boolean installPackage(AdvancedHttpClient client, HgRepositoryHandler handler,
File baseDirectory, HgPackage pkg)
{
return new HgPackageInstaller(client, handler, baseDirectory,

View File

@@ -35,7 +35,7 @@ package sonia.scm.installer;
//~--- non-JDK imports --------------------------------------------------------
import sonia.scm.net.HttpClient;
import sonia.scm.net.ahc.AdvancedHttpClient;
import sonia.scm.repository.HgConfig;
import sonia.scm.repository.HgRepositoryHandler;
@@ -78,8 +78,8 @@ public interface HgInstaller
*
* @return
*/
public boolean installPackage(HttpClient client, HgRepositoryHandler handler,
File baseDirectory, HgPackage pkg);
public boolean installPackage(AdvancedHttpClient client,
HgRepositoryHandler handler, File baseDirectory, HgPackage pkg);
/**
* Method description

View File

@@ -40,10 +40,10 @@ import org.slf4j.LoggerFactory;
import sonia.scm.SCMContext;
import sonia.scm.io.ZipUnArchiver;
import sonia.scm.net.HttpClient;
import sonia.scm.repository.HgWindowsPackageFix;
import sonia.scm.net.ahc.AdvancedHttpClient;
import sonia.scm.repository.HgConfig;
import sonia.scm.repository.HgRepositoryHandler;
import sonia.scm.repository.HgWindowsPackageFix;
import sonia.scm.util.IOUtil;
//~--- JDK imports ------------------------------------------------------------
@@ -80,8 +80,8 @@ public class HgPackageInstaller implements Runnable
* @param baseDirectory
* @param pkg
*/
public HgPackageInstaller(HttpClient client, HgRepositoryHandler handler,
File baseDirectory, HgPackage pkg)
public HgPackageInstaller(AdvancedHttpClient client,
HgRepositoryHandler handler, File baseDirectory, HgPackage pkg)
{
this.client = client;
this.handler = handler;
@@ -155,7 +155,7 @@ public class HgPackageInstaller implements Runnable
}
// TODO error handling
input = client.get(pkg.getUrl()).getContent();
input = client.get(pkg.getUrl()).request().contentAsStream();
output = new FileOutputStream(file);
IOUtil.copy(input, output);
}
@@ -265,7 +265,7 @@ public class HgPackageInstaller implements Runnable
private File baseDirectory;
/** Field description */
private HttpClient client;
private AdvancedHttpClient client;
/** Field description */
private HgRepositoryHandler handler;

View File

@@ -36,7 +36,6 @@ package sonia.scm.installer;
//~--- non-JDK imports --------------------------------------------------------
import com.google.inject.Inject;
import com.google.inject.Provider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,22 +43,17 @@ import org.slf4j.LoggerFactory;
import sonia.scm.PlatformType;
import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager;
import sonia.scm.net.HttpClient;
import sonia.scm.net.HttpResponse;
import sonia.scm.util.IOUtil;
import sonia.scm.net.ahc.AdvancedHttpClient;
import sonia.scm.util.SystemUtil;
import sonia.scm.util.Util;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.JAXB;
/**
*
* @author Sebastian Sdorra
@@ -85,14 +79,14 @@ public class HgPackageReader
*
*
* @param cacheManager
* @param httpClientProvider
* @param httpClient
*/
@Inject
public HgPackageReader(CacheManager cacheManager,
Provider<HttpClient> httpClientProvider)
AdvancedHttpClient httpClient)
{
cache = cacheManager.getCache(String.class, HgPackages.class, CACHENAME);
this.httpClientProvider = httpClientProvider;
this.httpClient = httpClient;
}
//~--- get methods ----------------------------------------------------------
@@ -218,23 +212,19 @@ public class HgPackageReader
}
HgPackages packages = null;
InputStream input = null;
try
{
HttpResponse response = httpClientProvider.get().get(PACKAGEURL);
input = response.getContent();
packages = JAXB.unmarshal(input, HgPackages.class);
//J-
packages = httpClient.get(PACKAGEURL)
.request()
.contentFromXml(HgPackages.class);
//J+
}
catch (IOException ex)
{
logger.error("could not read HgPackages from ".concat(PACKAGEURL), ex);
}
finally
{
IOUtil.close(input);
}
if (packages == null)
{
@@ -251,5 +241,5 @@ public class HgPackageReader
private Cache<String, HgPackages> cache;
/** Field description */
private Provider<HttpClient> httpClientProvider;
private AdvancedHttpClient httpClient;
}

View File

@@ -47,9 +47,6 @@ import org.slf4j.LoggerFactory;
import sonia.scm.ConfigChangedListener;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.net.HttpClient;
import sonia.scm.net.HttpRequest;
import sonia.scm.net.HttpResponse;
import sonia.scm.util.HttpUtil;
import sonia.scm.util.Util;
@@ -60,6 +57,7 @@ import java.io.IOException;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import sonia.scm.net.ahc.AdvancedHttpClient;
/**
*
@@ -86,17 +84,17 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
*
* @param configuration
* @param httpServletRequestProvider
* @param httpClientProvider
* @param httpClient
*/
@Inject
public HgHookManager(ScmConfiguration configuration,
Provider<HttpServletRequest> httpServletRequestProvider,
Provider<HttpClient> httpClientProvider)
AdvancedHttpClient httpClient)
{
this.configuration = configuration;
this.configuration.addListener(this);
this.httpServletRequestProvider = httpServletRequestProvider;
this.httpClientProvider = httpClientProvider;
this.httpClient = httpClient;
}
//~--- methods --------------------------------------------------------------
@@ -359,20 +357,16 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
{
url = url.concat("?ping=true");
if (logger.isTraceEnabled())
{
logger.trace("check hook url {}", url);
}
HttpRequest request = new HttpRequest(url);
request.setDisableCertificateValidation(true);
request.setDisableHostnameValidation(true);
request.setIgnoreProxySettings(true);
HttpResponse response = httpClientProvider.get().get(request);
result = response.getStatusCode() == 204;
//J-
int sc = httpClient.get(url)
.disableHostnameValidation(true)
.disableCertificateValidation(true)
.ignoreProxySettings(true)
.request()
.getStatus();
//J+
result = sc == 204;
}
catch (IOException ex)
{
@@ -397,7 +391,7 @@ public class HgHookManager implements ConfigChangedListener<ScmConfiguration>
private volatile String hookUrl;
/** Field description */
private Provider<HttpClient> httpClientProvider;
private AdvancedHttpClient httpClient;
/** Field description */
private Provider<HttpServletRequest> httpServletRequestProvider;

View File

@@ -74,7 +74,9 @@ import sonia.scm.util.HttpUtil;
/**
*
* @author Sebastian Sdorra
* @deprecated use {@link sonia.scm.net.ahc.AdvancedHttpClient}
*/
@Deprecated
public class URLHttpClient implements HttpClient
{

View File

@@ -40,21 +40,18 @@ import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Sets;
import com.google.common.io.Files;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import sonia.scm.ConfigChangedListener;
import sonia.scm.ConfigurationException;
import sonia.scm.SCMContext;
import sonia.scm.SCMContextProvider;
import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager;
import sonia.scm.config.ScmConfiguration;
import sonia.scm.io.ZipUnArchiver;
import sonia.scm.net.HttpClient;
import sonia.scm.util.AssertUtil;
import sonia.scm.util.IOUtil;
import sonia.scm.util.SecurityUtil;
@@ -79,9 +76,7 @@ import java.util.Map;
import java.util.Set;
import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import sonia.scm.net.ahc.AdvancedHttpClient;
/**
*
@@ -122,18 +117,18 @@ public class DefaultPluginManager
* @param configuration
* @param pluginLoader
* @param cacheManager
* @param clientProvider
* @param httpClient
*/
@Inject
public DefaultPluginManager(SCMContextProvider context,
ScmConfiguration configuration, PluginLoader pluginLoader,
CacheManager cacheManager, Provider<HttpClient> clientProvider)
CacheManager cacheManager, AdvancedHttpClient httpClient)
{
this.context = context;
this.configuration = configuration;
this.cache = cacheManager.getCache(String.class, PluginCenter.class,
CACHE_NAME);
this.clientProvider = clientProvider;
this.httpClient = httpClient;
installedPlugins = new HashMap<String, Plugin>();
for (Plugin plugin : pluginLoader.getInstalledPlugins())
@@ -146,16 +141,6 @@ public class DefaultPluginManager
}
}
try
{
unmarshaller =
JAXBContext.newInstance(PluginCenter.class).createUnmarshaller();
}
catch (JAXBException ex)
{
throw new ConfigurationException(ex);
}
File file = findAdvancedConfiguration();
if (file.exists())
@@ -654,21 +639,9 @@ public class DefaultPluginManager
if (Util.isNotEmpty(pluginUrl))
{
InputStream input = null;
try
{
input = clientProvider.get().get(pluginUrl).getContent();
/*
* TODO: add gzip support
*
* if (gzip)
* {
* input = new GZIPInputStream(input);
* }
*/
center = (PluginCenter) unmarshaller.unmarshal(input);
center = httpClient.get(pluginUrl).request().contentFromXml(PluginCenter.class);
preparePlugins(center);
cache.put(PluginCenter.class.getName(), center);
@@ -690,10 +663,6 @@ public class DefaultPluginManager
{
logger.error("could not load plugins from plugin center", ex);
}
finally
{
IOUtil.close(input);
}
}
if (center == null)
@@ -794,7 +763,7 @@ public class DefaultPluginManager
private Cache<String, PluginCenter> cache;
/** Field description */
private Provider<HttpClient> clientProvider;
private AdvancedHttpClient httpClient;
/** Field description */
private ScmConfiguration configuration;
@@ -807,7 +776,4 @@ public class DefaultPluginManager
/** Field description */
private AetherPluginHandler pluginHandler;
/** Field description */
private Unmarshaller unmarshaller;
}