Dedicated branch for testing maven-notice-plugin

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/notice-plugin-test@1026503 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2010-10-22 21:47:45 +00:00
parent e4d6204517
commit c76574f947
37 changed files with 505 additions and 387 deletions

View File

@ -40,14 +40,6 @@
<url>http://hc.apache.org/httpcomponents-client</url>
<packaging>jar</packaging>
<licenses>
<license>
<name>Apache License</name>
<url>../LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>

View File

@ -40,13 +40,6 @@
<url>http://hc.apache.org/httpcomponents-client</url>
<packaging>jar</packaging>
<licenses>
<license>
<name>Apache License</name>
<url>../LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<repositories>
<repository>
<id>spy</id>
@ -122,13 +115,6 @@
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>META-INF/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
@ -136,21 +122,6 @@
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE.txt</include>
</includes>
</resource>
<resource>
<directory>../src/main/resources</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>NOTICE.txt</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>

View File

@ -47,10 +47,25 @@ public class CacheConfig {
*/
public final static int DEFAULT_MAX_UPDATE_RETRIES = 1;
/** Default setting for heuristic caching
*/
public final static boolean DEFAULT_HEURISTIC_CACHING_ENABLED = false;
/** Default coefficient used to heuristically determine freshness lifetime from
* cache entry.
*/
public final static float DEFAULT_HEURISTIC_COEFFICIENT = 0.1f;
/** Default lifetime to be assumed when we cannot calculate freshness heuristically
*/
public final static long DEFAULT_HEURISTIC_LIFETIME = 0;
private int maxObjectSizeBytes = DEFAULT_MAX_OBJECT_SIZE_BYTES;
private int maxCacheEntries = DEFAULT_MAX_CACHE_ENTRIES;
private int maxUpdateRetries = DEFAULT_MAX_UPDATE_RETRIES;
private boolean heuristicCachingEnabled = false;
private float heuristicCoefficient = DEFAULT_HEURISTIC_COEFFICIENT;
private long heuristicDefaultLifetime = DEFAULT_HEURISTIC_LIFETIME;
private boolean isSharedCache = true;
/**
@ -118,4 +133,55 @@ public class CacheConfig {
public void setMaxUpdateRetries(int maxUpdateRetries){
this.maxUpdateRetries = maxUpdateRetries;
}
/**
* Returns if heuristic freshness caching is in enabled
* @return
*/
public boolean isHeuristicCachingEnabled() {
return heuristicCachingEnabled;
}
/**
* Set if heuristic freshness caching is enabled
* @param heursiticCachingEnabled
*/
public void setHeuristicCachingEnabled(boolean heuristicCachingEnabled) {
this.heuristicCachingEnabled = heuristicCachingEnabled;
}
/**
* Returns coefficient used in heuristic freshness caching
* @return
*/
public float getHeuristicCoefficient() {
return heuristicCoefficient;
}
/**
* Set coefficient to be used in heuristic freshness caching
* @param heuristicCoefficient
*/
public void setHeuristicCoefficient(float heuristicCoefficient) {
this.heuristicCoefficient = heuristicCoefficient;
}
/**
* Get the default lifetime to be used if heuristic freshness calculation is
* not possible
* @return
*/
public long getHeuristicDefaultLifetime() {
return heuristicDefaultLifetime;
}
/**
* Set default lifetime to be used if heuristic freshness calculation is not possible
* @param heuristicDefaultLifetime
*/
public void setHeuristicDefaultLifetime(long heuristicDefaultLifetime) {
this.heuristicDefaultLifetime = heuristicDefaultLifetime;
}
}

View File

@ -73,6 +73,39 @@ class CacheValidityPolicy {
return (getCurrentAgeSecs(entry, now) < getFreshnessLifetimeSecs(entry));
}
/**
* Decides if this response is fresh enough based Last-Modified and Date, if available.
* This entry is meant to be used when isResponseFresh returns false. The algorithm is as follows:
*
* if last-modified and date are defined, freshness lifetime is coefficient*(date-lastModified),
* else freshness lifetime is defaultLifetime
*
* @param entry
* @param now
* @param coefficient
* @param defaultLifetime
* @return
*/
public boolean isResponseHeuristicallyFresh(final HttpCacheEntry entry,
Date now, float coefficient, long defaultLifetime) {
return (getCurrentAgeSecs(entry, now) < getHeuristicFreshnessLifetimeSecs(entry, coefficient, defaultLifetime));
}
public long getHeuristicFreshnessLifetimeSecs(HttpCacheEntry entry,
float coefficient, long defaultLifetime) {
Date dateValue = getDateValue(entry);
Date lastModifiedValue = getLastModifiedValue(entry);
if (dateValue != null && lastModifiedValue != null) {
long diff = dateValue.getTime() - lastModifiedValue.getTime();
if (diff < 0)
return 0;
return (long)(coefficient * (diff / 1000));
}
return defaultLifetime;
}
public boolean isRevalidatable(final HttpCacheEntry entry) {
return entry.getFirstHeader(HeaderConstants.ETAG) != null
|| entry.getFirstHeader(HeaderConstants.LAST_MODIFIED) != null;
@ -98,6 +131,18 @@ class CacheValidityPolicy {
return null;
}
protected Date getLastModifiedValue(final HttpCacheEntry entry) {
Header dateHdr = entry.getFirstHeader(HeaderConstants.LAST_MODIFIED);
if (dateHdr == null)
return null;
try {
return DateUtils.parseDate(dateHdr.getValue());
} catch (DateParseException dpe) {
// ignore malformed date
}
return null;
}
protected long getContentLengthValue(final HttpCacheEntry entry) {
Header cl = entry.getFirstHeader(HTTP.CONTENT_LEN);
if (cl == null)

View File

@ -52,6 +52,9 @@ class CachedResponseSuitabilityChecker {
private final Log log = LogFactory.getLog(getClass());
private final boolean sharedCache;
private final boolean useHeuristicCaching;
private final float heuristicCoefficient;
private final long heuristicDefaultLifetime;
private final CacheValidityPolicy validityStrategy;
CachedResponseSuitabilityChecker(final CacheValidityPolicy validityStrategy,
@ -59,6 +62,9 @@ class CachedResponseSuitabilityChecker {
super();
this.validityStrategy = validityStrategy;
this.sharedCache = config.isSharedCache();
this.useHeuristicCaching = config.isHeuristicCachingEnabled();
this.heuristicCoefficient = config.getHeuristicCoefficient();
this.heuristicDefaultLifetime = config.getHeuristicDefaultLifetime();
}
CachedResponseSuitabilityChecker(CacheConfig config) {
@ -67,6 +73,9 @@ class CachedResponseSuitabilityChecker {
private boolean isFreshEnough(HttpCacheEntry entry, HttpRequest request, Date now) {
if (validityStrategy.isResponseFresh(entry, now)) return true;
if (useHeuristicCaching &&
validityStrategy.isResponseHeuristicallyFresh(entry, now, heuristicCoefficient, heuristicDefaultLifetime))
return true;
if (originInsistsOnFreshness(entry)) return false;
long maxstale = getMaxStale(request);
if (maxstale == -1) return false;

View File

@ -407,6 +407,11 @@ public class CachingHttpClient implements HttpClient {
log.debug("Cache miss [host: " + target + "; uri: " + rl.getUri() + "]");
}
if (!mayCallBackend(request)) {
return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT,
"Gateway Timeout");
}
Set<HttpCacheEntry> variantEntries = null;
try {
responseCache.getVariantCacheEntries(target, request);
@ -447,6 +452,11 @@ public class CachingHttpClient implements HttpClient {
return cachedResponse;
}
if (!mayCallBackend(request)) {
return new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_GATEWAY_TIMEOUT,
"Gateway Timeout");
}
if (validityPolicy.isRevalidatable(entry)) {
log.debug("Revalidating the cache entry");
@ -472,6 +482,17 @@ public class CachingHttpClient implements HttpClient {
return callBackend(target, request, context);
}
private boolean mayCallBackend(HttpRequest request) {
for (Header h: request.getHeaders("Cache-Control")) {
for (HeaderElement elt : h.getElements()) {
if ("only-if-cached".equals(elt.getName())) {
return false;
}
}
}
return true;
}
private boolean explicitFreshnessRequest(HttpRequest request, HttpCacheEntry entry, Date now) {
for(Header h : request.getHeaders("Cache-Control")) {
for(HeaderElement elt : h.getElements()) {

View File

@ -250,6 +250,48 @@ public class TestCacheValidityPolicy {
Assert.assertEquals(4, impl.getFreshnessLifetimeSecs(entry));
}
@Test
public void testHeuristicFreshnessLifetime() {
Date now = new Date();
Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(oneSecondAgo)),
new BasicHeader("Last-Modified", DateUtils.formatDate(elevenSecondsAgo))
};
HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
CacheValidityPolicy impl = new CacheValidityPolicy();
Assert.assertEquals(1, impl.getHeuristicFreshnessLifetimeSecs(entry, 0.1f, 0));
}
@Test
public void testHeuristicFreshnessLifetimeDefaultsProperly() {
long defaultFreshness = 10;
HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();
CacheValidityPolicy impl = new CacheValidityPolicy();
Assert.assertEquals(defaultFreshness, impl.getHeuristicFreshnessLifetimeSecs(entry, 0.1f, defaultFreshness));
}
@Test
public void testHeuristicFreshnessLifetimeIsNonNegative() {
Date now = new Date();
Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
Date elevenSecondsAgo = new Date(now.getTime() - 1 * 1000L);
Header[] headers = new Header[] {
new BasicHeader("Date", DateUtils.formatDate(elevenSecondsAgo)),
new BasicHeader("Last-Modified", DateUtils.formatDate(oneSecondAgo))
};
HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
CacheValidityPolicy impl = new CacheValidityPolicy();
Assert.assertTrue(impl.getHeuristicFreshnessLifetimeSecs(entry, 0.1f, 10) >= 0);
}
@Test
public void testResponseIsFreshIfFreshnessLifetimeExceedsCurrentAge() {
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry();

View File

@ -223,4 +223,41 @@ public class TestCachedResponseSuitabilityChecker {
Assert.assertFalse(impl.canCachedResponseBeUsed(host, request, entry, now));
}
@Test
public void testSuitableIfCacheEntryIsHeuristicallyFreshEnough() {
Date oneSecondAgo = new Date(now.getTime() - 1 * 1000L);
Date twentyOneSecondsAgo = new Date(now.getTime() - 21 * 1000L);
Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(oneSecondAgo)),
new BasicHeader("Last-Modified", DateUtils.formatDate(twentyOneSecondsAgo)),
new BasicHeader("Content-Length", "128")
};
entry = HttpTestUtils.makeCacheEntry(oneSecondAgo, oneSecondAgo, headers);
CacheConfig config = new CacheConfig();
config.setHeuristicCachingEnabled(true);
config.setHeuristicCoefficient(0.1f);
impl = new CachedResponseSuitabilityChecker(config);
Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
}
@Test
public void testSuitableIfCacheEntryIsHeuristicallyFreshEnoughByDefault() {
Header[] headers = {
new BasicHeader("Date", DateUtils.formatDate(tenSecondsAgo)),
new BasicHeader("Content-Length", "128")
};
entry = getEntry(headers);
CacheConfig config = new CacheConfig();
config.setHeuristicCachingEnabled(true);
config.setHeuristicDefaultLifetime(20);
impl = new CachedResponseSuitabilityChecker(config);
Assert.assertTrue(impl.canCachedResponseBeUsed(host, request, entry, now));
}
}

View File

@ -1931,6 +1931,59 @@ public class TestCachingHttpClient {
Assert.assertSame(resp, result);
}
@Test
public void testIfOnlyIfCachedAndNoCacheEntryBackendNotCalled() throws IOException {
impl = new CachingHttpClient(mockBackend);
request.addHeader("Cache-Control", "only-if-cached");
HttpResponse resp = impl.execute(host, request);
Assert.assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT, resp.getStatusLine().getStatusCode());
}
@Test
public void testIfOnlyIfCachedAndEntryNotSuitableBackendNotCalled() throws Exception {
request.setHeader("Cache-Control", "only-if-cached");
entry = HttpTestUtils.makeCacheEntry(new Header[]{new BasicHeader("Cache-Control", "must-revalidate")});
requestIsFatallyNonCompliant(null);
requestProtocolValidationIsCalled();
cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
getCacheEntryReturns(entry);
cacheEntrySuitable(false);
replayMocks();
HttpResponse resp = impl.execute(host, request);
verifyMocks();
Assert.assertEquals(HttpStatus.SC_GATEWAY_TIMEOUT, resp.getStatusLine().getStatusCode());
}
@Test
public void testIfOnlyIfCachedAndEntryExistsAndIsSuitableReturnsEntry() throws Exception {
request.setHeader("Cache-Control", "only-if-cached");
requestIsFatallyNonCompliant(null);
requestProtocolValidationIsCalled();
cacheInvalidatorWasCalled();
requestPolicyAllowsCaching(true);
getCacheEntryReturns(entry);
cacheEntrySuitable(true);
responseIsGeneratedFromCache();
entryHasStaleness(0);
replayMocks();
HttpResponse resp = impl.execute(host, request);
verifyMocks();
Assert.assertSame(mockCachedResponse, resp);
}
private void getCacheEntryReturns(HttpCacheEntry result) throws IOException {
EasyMock.expect(mockCache.getCacheEntry(host, request)).andReturn(result);
}

View File

@ -40,14 +40,6 @@
<url>http://hc.apache.org/httpcomponents-client</url>
<packaging>jar</packaging>
<licenses>
<license>
<name>Apache License</name>
<url>../LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>

View File

@ -79,13 +79,6 @@
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>META-INF/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
@ -93,21 +86,6 @@
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE.txt</include>
</includes>
</resource>
<resource>
<directory>../src/main/resources</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>NOTICE.txt</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>

View File

@ -40,14 +40,6 @@
<url>http://hc.apache.org/httpcomponents-client</url>
<packaging>jar</packaging>
<licenses>
<license>
<name>Apache License</name>
<url>../LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@ -98,13 +90,6 @@
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>META-INF/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
@ -112,46 +97,7 @@
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE.txt</include>
</includes>
</resource>
<resource>
<directory>../src/main/resources</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>NOTICE.txt</include>
</includes>
</resource>
</resources>
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>false</filtering>
<includes>
<include>*</include>
</includes>
</testResource>
<testResource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE.txt</include>
</includes>
</testResource>
<testResource>
<directory>../src/main/resources</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>NOTICE.txt</include>
</includes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -31,6 +31,7 @@ import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
/**
* A simple example that uses HttpClient to execute an HTTP request against
@ -56,9 +57,7 @@ public class ClientAuthentication {
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure

View File

@ -35,6 +35,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
/**
* Example how to use unbuffered chunk-encoded POST request.
@ -75,9 +76,7 @@ public class ClientChunkEncodedPost {
System.out.println("Response content length: " + resEntity.getContentLength());
System.out.println("Chunked?: " + resEntity.isChunked());
}
if (resEntity != null) {
resEntity.consumeContent();
}
EntityUtils.consume(resEntity);
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure

View File

@ -40,6 +40,7 @@ import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
/**
@ -79,9 +80,7 @@ public class ClientCustomContext {
}
// Consume response content
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
System.out.println("----------------------------------------");

View File

@ -36,6 +36,7 @@ import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
/**
* This example demonstrates how to create secure connections with a custom SSL
@ -70,9 +71,7 @@ public class ClientCustomSSL {
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure

View File

@ -38,6 +38,7 @@ import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.util.EntityUtils;
/**
* Example demonstrating how to evict expired and idle connections
@ -52,7 +53,7 @@ public class ClientEvictExpiredConnections {
new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
cm.setMaxTotalConnections(100);
cm.setMaxTotal(100);
HttpClient httpclient = new DefaultHttpClient(cm);
@ -83,9 +84,7 @@ public class ClientEvictExpiredConnections {
}
System.out.println("----------------------------------------");
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
}
// Sleep 10 sec and let the connection evictor do its job

View File

@ -38,6 +38,7 @@ import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
/**
* A example that demonstrates how HttpClient APIs can be used to perform
@ -55,9 +56,8 @@ public class ClientFormLogin {
HttpEntity entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
System.out.println("Initial set of cookies:");
List<Cookie> cookies = httpclient.getCookieStore().getCookies();
if (cookies.isEmpty()) {
@ -83,9 +83,7 @@ public class ClientFormLogin {
entity = response.getEntity();
System.out.println("Login form get: " + response.getStatusLine());
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
System.out.println("Post logon cookies:");
cookies = httpclient.getCookieStore().getCookies();

View File

@ -40,6 +40,7 @@ import org.apache.http.client.protocol.ClientContext;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
/**
* A simple example that uses HttpClient to execute an HTTP request against
@ -65,9 +66,7 @@ public class ClientInteractiveAuthentication {
// Consume response content
HttpEntity entity = response.getEntity();
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
int sc = response.getStatusLine().getStatusCode();

View File

@ -162,9 +162,7 @@ public class ClientKerberosAuthentication {
System.out.println("----------------------------------------");
// This ensures the connection gets released back to the manager
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure

View File

@ -55,7 +55,7 @@ public class ClientMultiThreadedExecution {
// This connection manager must be used if more than one thread will
// be using the HttpClient.
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
cm.setMaxTotalConnections(100);
cm.setMaxTotal(100);
HttpClient httpClient = new DefaultHttpClient(cm);

View File

@ -37,6 +37,7 @@ import org.apache.http.impl.auth.BasicScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
/**
* An example of HttpClient can be customized to authenticate
@ -82,8 +83,8 @@ public class ClientPreemptiveBasicAuthentication {
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
entity.consumeContent();
}
EntityUtils.consume(entity);
}
// When HttpClient instance is no longer needed,

View File

@ -37,6 +37,7 @@ import org.apache.http.impl.auth.DigestScheme;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.util.EntityUtils;
/**
* An example of HttpClient can be customized to authenticate
@ -86,8 +87,8 @@ public class ClientPreemptiveDigestAuthentication {
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
entity.consumeContent();
}
EntityUtils.consume(entity);
}
// When HttpClient instance is no longer needed,

View File

@ -33,6 +33,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
/**
* A simple example that uses HttpClient to execute an HTTP request
@ -67,9 +68,7 @@ public class ClientProxyAuthentication {
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
if (entity != null) {
entity.consumeContent();
}
EntityUtils.consume(entity);
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure

View File

@ -40,14 +40,6 @@
<url>http://hc.apache.org/httpcomponents-client</url>
<packaging>jar</packaging>
<licenses>
<license>
<name>Apache License</name>
<url>../LICENSE.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@ -80,13 +72,6 @@
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>META-INF/*</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
@ -94,21 +79,6 @@
<include>**/*.properties</include>
</includes>
</resource>
<resource>
<directory>..</directory>
<targetPath>META-INF</targetPath>
<includes>
<include>LICENSE.txt</include>
</includes>
</resource>
<resource>
<directory>../src/main/resources</directory>
<targetPath>META-INF</targetPath>
<filtering>true</filtering>
<includes>
<include>NOTICE.txt</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>

13
pom.xml
View File

@ -86,6 +86,19 @@
<build>
<plugins>
<plugin>
<artifactId>maven-notice-plugin</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>attach-notice-license</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<executions>

View File

@ -1,8 +0,0 @@
Apache HttpComponents Client - ${project.name}
Copyright 1999-2010 The Apache Software Foundation
This product includes software developed by
The Apache Software Foundation (http://www.apache.org/).
This project contains annotations derived from JCIP-ANNOTATIONS
Copyright (c) 2005 Brian Goetz and Tim Peierls. See http://www.jcip.net