mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
use ahc for internal http operations
This commit is contained in:
@@ -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;
|
||||
@@ -158,7 +158,7 @@ public class HgConfigResource
|
||||
if (pkg != null)
|
||||
{
|
||||
if (HgInstallerFactory.createInstaller().installPackage(client, handler,
|
||||
SCMContext.getContext().getBaseDirectory(), pkg))
|
||||
SCMContext.getContext().getBaseDirectory(), pkg))
|
||||
{
|
||||
response = Response.noContent().build();
|
||||
}
|
||||
@@ -262,7 +262,7 @@ public class HgConfigResource
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
|
||||
public Response setConfig(@Context UriInfo uriInfo, HgConfig config)
|
||||
throws IOException
|
||||
throws IOException
|
||||
{
|
||||
handler.setConfig(config);
|
||||
handler.storeConfig();
|
||||
@@ -338,7 +338,7 @@ public class HgConfigResource
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private HttpClient client;
|
||||
private AdvancedHttpClient client;
|
||||
|
||||
/** Field description */
|
||||
private HgRepositoryHandler handler;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ----------------------------------------------------------
|
||||
@@ -167,7 +161,7 @@ public class HgPackageReader
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("reject package {}, because of wrong platform {}",
|
||||
pkg.getId(), pkg.getPlatform());
|
||||
pkg.getId(), pkg.getPlatform());
|
||||
}
|
||||
|
||||
add = false;
|
||||
@@ -181,7 +175,7 @@ public class HgPackageReader
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("reject package {}, because of wrong arch {}",
|
||||
pkg.getId(), pkg.getArch());
|
||||
pkg.getId(), pkg.getArch());
|
||||
}
|
||||
|
||||
add = false;
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
logger.trace("check hook url {}", url);
|
||||
//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;
|
||||
|
||||
Reference in New Issue
Block a user