merge with branch issue-109

This commit is contained in:
Sebastian Sdorra
2012-04-10 14:44:32 +02:00
6 changed files with 79 additions and 20 deletions

View File

@@ -169,6 +169,19 @@ public class HttpRequest
return username;
}
/**
* Method description
*
*
* @return
*
* @since 1.14
*/
public boolean isDecodeGZip()
{
return decodeGZip;
}
//~--- set methods ----------------------------------------------------------
/**
@@ -188,6 +201,22 @@ public class HttpRequest
return this;
}
/**
* Method description
*
*
* @param decodeGZip
*
* @return
*
* @since 1.14
*/
public HttpRequest setDecodeGZip(boolean decodeGZip)
{
this.decodeGZip = decodeGZip;
return this;
}
/**
* Method description
*
@@ -247,6 +276,9 @@ public class HttpRequest
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean decodeGZip = false;
/** Field description */
private Map<String, List<String>> headers;

View File

@@ -87,15 +87,15 @@ public class HgConfigResource
*
* @param client
* @param handler
* @param cacheManager
* @param pkgReader
*/
@Inject
public HgConfigResource(HttpClient client, HgRepositoryHandler handler,
CacheManager cacheManager)
HgPackageReader pkgReader)
{
this.client = client;
this.handler = handler;
this.pkgReader = new HgPackageReader(cacheManager);
this.pkgReader = pkgReader;
}
//~--- methods --------------------------------------------------------------

View File

@@ -35,12 +35,18 @@ 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;
import sonia.scm.PlatformType;
import sonia.scm.cache.Cache;
import sonia.scm.cache.CacheManager;
import sonia.scm.net.HttpClient;
import sonia.scm.net.HttpRequest;
import sonia.scm.net.HttpResponse;
import sonia.scm.util.IOUtil;
import sonia.scm.util.SystemUtil;
import sonia.scm.util.Util;
@@ -50,11 +56,8 @@ import sonia.scm.util.Util;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.GZIPInputStream;
import javax.xml.bind.JAXB;
@@ -83,10 +86,14 @@ public class HgPackageReader
*
*
* @param cacheManager
* @param httpClientProvider
*/
public HgPackageReader(CacheManager cacheManager)
@Inject
public HgPackageReader(CacheManager cacheManager,
Provider<HttpClient> httpClientProvider)
{
cache = cacheManager.getCache(String.class, HgPackages.class, CACHENAME);
this.httpClientProvider = httpClientProvider;
}
//~--- get methods ----------------------------------------------------------
@@ -216,17 +223,13 @@ public class HgPackageReader
try
{
URL url = new URL(PACKAGEURL);
HttpRequest request = new HttpRequest(PACKAGEURL);
if (PACKAGEURL.endsWith(".gz"))
{
input = new GZIPInputStream(url.openStream());
}
else
{
input = url.openStream();
}
request.setDecodeGZip(true);
HttpResponse response = httpClientProvider.get().get(request);
input = response.getContent();
packages = JAXB.unmarshal(input, HgPackages.class);
}
catch (IOException ex)
@@ -251,4 +254,7 @@ public class HgPackageReader
/** Field description */
private Cache<String, HgPackages> cache;
/** Field description */
private Provider<HttpClient> httpClientProvider;
}

View File

@@ -37,6 +37,7 @@ package sonia.scm.web;
import com.google.inject.servlet.ServletModule;
import sonia.scm.installer.HgPackageReader;
import sonia.scm.plugin.ext.Extension;
import sonia.scm.repository.HgContext;
import sonia.scm.repository.HgHookManager;
@@ -67,6 +68,9 @@ public class HgServletModule extends ServletModule
{
bind(HgContext.class);
bind(HgHookManager.class);
bind(HgPackageReader.class);
// bind servlets
serve(MAPPING_HOOK).with(HgHookCallbackServlet.class);
// register hg cgi servlet

View File

@@ -251,7 +251,8 @@ public class URLHttpClient implements HttpClient
{
String url = createGetUrl(request.getUrl(), request.getParameters());
return new URLHttpResponse(openConnection(request, url));
return new URLHttpResponse(openConnection(request, url),
request.isDecodeGZip());
}
//~--- methods --------------------------------------------------------------

View File

@@ -70,8 +70,21 @@ public class URLHttpResponse implements HttpResponse
* @param connection
*/
public URLHttpResponse(URLConnection connection)
{
this(connection, false);
}
/**
* Constructs ...
*
*
* @param connection
* @param decodeGZip
*/
public URLHttpResponse(URLConnection connection, boolean decodeGZip)
{
this.connection = connection;
this.decodeGZip = decodeGZip;
}
//~--- methods --------------------------------------------------------------
@@ -114,7 +127,7 @@ public class URLHttpResponse implements HttpResponse
String enc = connection.getContentEncoding();
InputStream input = null;
if (Util.isNotEmpty(enc) && enc.contains(ENCODING_GZIP))
if (decodeGZip || (Util.isNotEmpty(enc) && enc.contains(ENCODING_GZIP)))
{
input = new GZIPInputStream(connection.getInputStream());
}
@@ -215,8 +228,11 @@ public class URLHttpResponse implements HttpResponse
//~--- fields ---------------------------------------------------------------
/** Field description */
private boolean clientClose = false;
private URLConnection connection;
/** Field description */
private URLConnection connection;
private boolean decodeGZip = false;
/** Field description */
private boolean clientClose = false;
}