Rename or inline local variables to avoid variable hiding
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1571371 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
56e6a6c853
commit
fe360e7b3d
|
@ -116,12 +116,12 @@ public class TestCacheInvalidator {
|
|||
|
||||
@Test
|
||||
public void testInvalidatesUrisInContentLocationHeadersOnPUTs() throws Exception {
|
||||
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
request.setEntity(HttpTestUtils.makeBody(128));
|
||||
request.setHeader("Content-Length","128");
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
final String contentLocation = "http://foo.example.com/content";
|
||||
request.setHeader("Content-Location", contentLocation);
|
||||
putRequest.setHeader("Content-Location", contentLocation);
|
||||
|
||||
final String theUri = "http://foo.example.com:80/";
|
||||
cacheEntryHasVariantMap(new HashMap<String,String>());
|
||||
|
@ -132,19 +132,19 @@ public class TestCacheInvalidator {
|
|||
|
||||
replayMocks();
|
||||
|
||||
impl.flushInvalidatedCacheEntries(host, request);
|
||||
impl.flushInvalidatedCacheEntries(host, putRequest);
|
||||
|
||||
verifyMocks();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidatesUrisInLocationHeadersOnPUTs() throws Exception {
|
||||
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
request.setEntity(HttpTestUtils.makeBody(128));
|
||||
request.setHeader("Content-Length","128");
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
final String contentLocation = "http://foo.example.com/content";
|
||||
request.setHeader("Location",contentLocation);
|
||||
putRequest.setHeader("Location",contentLocation);
|
||||
|
||||
final String theUri = "http://foo.example.com:80/";
|
||||
cacheEntryHasVariantMap(new HashMap<String,String>());
|
||||
|
@ -155,19 +155,19 @@ public class TestCacheInvalidator {
|
|||
|
||||
replayMocks();
|
||||
|
||||
impl.flushInvalidatedCacheEntries(host, request);
|
||||
impl.flushInvalidatedCacheEntries(host, putRequest);
|
||||
|
||||
verifyMocks();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidatesRelativeUrisInContentLocationHeadersOnPUTs() throws Exception {
|
||||
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
request.setEntity(HttpTestUtils.makeBody(128));
|
||||
request.setHeader("Content-Length","128");
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
final String relativePath = "/content";
|
||||
request.setHeader("Content-Location",relativePath);
|
||||
putRequest.setHeader("Content-Location",relativePath);
|
||||
|
||||
final String theUri = "http://foo.example.com:80/";
|
||||
cacheEntryHasVariantMap(new HashMap<String,String>());
|
||||
|
@ -178,19 +178,19 @@ public class TestCacheInvalidator {
|
|||
|
||||
replayMocks();
|
||||
|
||||
impl.flushInvalidatedCacheEntries(host, request);
|
||||
impl.flushInvalidatedCacheEntries(host, putRequest);
|
||||
|
||||
verifyMocks();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoesNotInvalidateUrisInContentLocationHeadersOnPUTsToDifferentHosts() throws Exception {
|
||||
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
request.setEntity(HttpTestUtils.makeBody(128));
|
||||
request.setHeader("Content-Length","128");
|
||||
final HttpEntityEnclosingRequest putRequest = new BasicHttpEntityEnclosingRequest("PUT","/",HTTP_1_1);
|
||||
putRequest.setEntity(HttpTestUtils.makeBody(128));
|
||||
putRequest.setHeader("Content-Length","128");
|
||||
|
||||
final String contentLocation = "http://bar.example.com/content";
|
||||
request.setHeader("Content-Location",contentLocation);
|
||||
putRequest.setHeader("Content-Location",contentLocation);
|
||||
|
||||
final String theUri = "http://foo.example.com:80/";
|
||||
cacheEntryHasVariantMap(new HashMap<String,String>());
|
||||
|
@ -200,7 +200,7 @@ public class TestCacheInvalidator {
|
|||
|
||||
replayMocks();
|
||||
|
||||
impl.flushInvalidatedCacheEntries(host, request);
|
||||
impl.flushInvalidatedCacheEntries(host, putRequest);
|
||||
|
||||
verifyMocks();
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@SuppressWarnings("boxing") // this is test code
|
||||
public class TestCacheKeyGenerator {
|
||||
|
||||
private static final BasicHttpRequest REQUEST_FULL_EPISODES = new BasicHttpRequest("GET",
|
||||
|
@ -46,13 +47,13 @@ public class TestCacheKeyGenerator {
|
|||
private static final BasicHttpRequest REQUEST_ROOT = new BasicHttpRequest("GET", "/");
|
||||
|
||||
CacheKeyGenerator extractor;
|
||||
private HttpHost host;
|
||||
private HttpHost defaultHost;
|
||||
private HttpCacheEntry mockEntry;
|
||||
private HttpRequest mockRequest;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
host = new HttpHost("foo.example.com");
|
||||
defaultHost = new HttpHost("foo.example.com");
|
||||
mockEntry = EasyMock.createNiceMock(HttpCacheEntry.class);
|
||||
mockRequest = EasyMock.createNiceMock(HttpRequest.class);
|
||||
extractor = new CacheKeyGenerator();
|
||||
|
@ -127,14 +128,14 @@ public class TestCacheKeyGenerator {
|
|||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(final HttpHost h, final HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
Assert.assertSame(defaultHost, h);
|
||||
Assert.assertSame(mockRequest, req);
|
||||
return theURI;
|
||||
}
|
||||
};
|
||||
|
||||
replayMocks();
|
||||
final String result = extractor.getVariantURI(host, mockRequest, mockEntry);
|
||||
final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
|
||||
verifyMocks();
|
||||
Assert.assertSame(theURI, result);
|
||||
}
|
||||
|
@ -148,7 +149,7 @@ public class TestCacheKeyGenerator {
|
|||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(final HttpHost h, final HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
Assert.assertSame(defaultHost, h);
|
||||
Assert.assertSame(mockRequest, req);
|
||||
return theURI;
|
||||
}
|
||||
|
@ -159,7 +160,7 @@ public class TestCacheKeyGenerator {
|
|||
encHeaders);
|
||||
replayMocks();
|
||||
|
||||
final String result = extractor.getVariantURI(host, mockRequest, mockEntry);
|
||||
final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
|
||||
|
||||
verifyMocks();
|
||||
Assert.assertEquals("{Accept-Encoding=gzip}" + theURI, result);
|
||||
|
@ -173,7 +174,7 @@ public class TestCacheKeyGenerator {
|
|||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(final HttpHost h, final HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
Assert.assertSame(defaultHost, h);
|
||||
Assert.assertSame(mockRequest, req);
|
||||
return theURI;
|
||||
}
|
||||
|
@ -184,7 +185,7 @@ public class TestCacheKeyGenerator {
|
|||
.andReturn(noHeaders);
|
||||
replayMocks();
|
||||
|
||||
final String result = extractor.getVariantURI(host, mockRequest, mockEntry);
|
||||
final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
|
||||
|
||||
verifyMocks();
|
||||
Assert.assertEquals("{Accept-Encoding=}" + theURI, result);
|
||||
|
@ -199,7 +200,7 @@ public class TestCacheKeyGenerator {
|
|||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(final HttpHost h, final HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
Assert.assertSame(defaultHost, h);
|
||||
Assert.assertSame(mockRequest, req);
|
||||
return theURI;
|
||||
}
|
||||
|
@ -211,7 +212,7 @@ public class TestCacheKeyGenerator {
|
|||
EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
|
||||
replayMocks();
|
||||
|
||||
final String result = extractor.getVariantURI(host, mockRequest, mockEntry);
|
||||
final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
|
||||
|
||||
verifyMocks();
|
||||
Assert.assertEquals("{Accept-Encoding=gzip&User-Agent=browser}" + theURI, result);
|
||||
|
@ -227,7 +228,7 @@ public class TestCacheKeyGenerator {
|
|||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(final HttpHost h, final HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
Assert.assertSame(defaultHost, h);
|
||||
Assert.assertSame(mockRequest, req);
|
||||
return theURI;
|
||||
}
|
||||
|
@ -238,7 +239,7 @@ public class TestCacheKeyGenerator {
|
|||
EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
|
||||
replayMocks();
|
||||
|
||||
final String result = extractor.getVariantURI(host, mockRequest, mockEntry);
|
||||
final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
|
||||
|
||||
verifyMocks();
|
||||
Assert.assertEquals("{Accept-Encoding=gzip&User-Agent=browser}" + theURI, result);
|
||||
|
@ -254,7 +255,7 @@ public class TestCacheKeyGenerator {
|
|||
extractor = new CacheKeyGenerator() {
|
||||
@Override
|
||||
public String getURI(final HttpHost h, final HttpRequest req) {
|
||||
Assert.assertSame(host, h);
|
||||
Assert.assertSame(defaultHost, h);
|
||||
Assert.assertSame(mockRequest, req);
|
||||
return theURI;
|
||||
}
|
||||
|
@ -265,7 +266,7 @@ public class TestCacheKeyGenerator {
|
|||
EasyMock.expect(mockRequest.getHeaders("User-Agent")).andReturn(uaHeaders);
|
||||
replayMocks();
|
||||
|
||||
final String result = extractor.getVariantURI(host, mockRequest, mockEntry);
|
||||
final String result = extractor.getVariantURI(defaultHost, mockRequest, mockEntry);
|
||||
|
||||
verifyMocks();
|
||||
Assert
|
||||
|
|
|
@ -68,9 +68,9 @@ public class TestCachedHttpResponseGenerator {
|
|||
@Test
|
||||
public void testResponseHasContentLength() {
|
||||
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
|
||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(buf);
|
||||
final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(buf);
|
||||
|
||||
final HttpResponse response = impl.generateResponse(entry);
|
||||
final HttpResponse response = impl.generateResponse(entry1);
|
||||
|
||||
final Header length = response.getFirstHeader("Content-Length");
|
||||
Assert.assertNotNull("Content-Length Header is missing", length);
|
||||
|
@ -84,9 +84,9 @@ public class TestCachedHttpResponseGenerator {
|
|||
|
||||
final Header[] hdrs = new Header[] { new BasicHeader("Transfer-Encoding", "chunked") };
|
||||
final byte[] buf = new byte[] { 1, 2, 3, 4, 5 };
|
||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(hdrs, buf);
|
||||
final HttpCacheEntry entry1 = HttpTestUtils.makeCacheEntry(hdrs, buf);
|
||||
|
||||
final HttpResponse response = impl.generateResponse(entry);
|
||||
final HttpResponse response = impl.generateResponse(entry1);
|
||||
|
||||
final Header length = response.getFirstHeader("Content-Length");
|
||||
|
||||
|
|
|
@ -327,9 +327,9 @@ public abstract class TestCachingExecChain {
|
|||
|
||||
@Test
|
||||
public void testNonCacheableResponseIsNotCachedAndIsReturnedAsIs() throws Exception {
|
||||
final CacheConfig config = CacheConfig.DEFAULT;
|
||||
final CacheConfig configDefault = CacheConfig.DEFAULT;
|
||||
impl = createCachingExecChain(mockBackend, new BasicHttpCache(new HeapResourceFactory(),
|
||||
mockStorage, config), config);
|
||||
mockStorage, configDefault), configDefault);
|
||||
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpResponse resp1 = HttpTestUtils.make200Response();
|
||||
|
|
|
@ -65,9 +65,9 @@ public class TestConditionalRequestBuilder {
|
|||
final String theUri = "/theuri";
|
||||
final String lastModified = "this is my last modified date";
|
||||
|
||||
final HttpRequest request = new BasicHttpRequest(theMethod, theUri);
|
||||
request.addHeader("Accept-Encoding", "gzip");
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
|
||||
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
|
||||
basicRequest.addHeader("Accept-Encoding", "gzip");
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
|
||||
final Header[] headers = new Header[] {
|
||||
new BasicHeader("Date", DateUtils.formatDate(new Date())),
|
||||
|
@ -76,11 +76,11 @@ public class TestConditionalRequestBuilder {
|
|||
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
|
||||
final HttpRequestWrapper newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
|
||||
|
||||
Assert.assertNotSame(request, newRequest);
|
||||
Assert.assertNotSame(basicRequest, newRequest);
|
||||
|
||||
Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod());
|
||||
Assert.assertEquals(theUri, newRequest.getRequestLine().getUri());
|
||||
Assert.assertEquals(request.getRequestLine().getProtocolVersion(), newRequest
|
||||
Assert.assertEquals(basicRequest.getRequestLine().getProtocolVersion(), newRequest
|
||||
.getRequestLine().getProtocolVersion());
|
||||
Assert.assertEquals(2, newRequest.getAllHeaders().length);
|
||||
|
||||
|
@ -104,10 +104,10 @@ public class TestConditionalRequestBuilder {
|
|||
new BasicHeader("Last-Modified", lmDate),
|
||||
new BasicHeader("ETag", etag)
|
||||
};
|
||||
final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
|
||||
final HttpCacheEntry entry = HttpTestUtils.makeCacheEntry(headers);
|
||||
final HttpRequest result = impl.buildConditionalRequest(requestWrapper, entry);
|
||||
final HttpRequest basicRequest = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final HttpCacheEntry cacheEntry = HttpTestUtils.makeCacheEntry(headers);
|
||||
final HttpRequest result = impl.buildConditionalRequest(requestWrapper, cacheEntry);
|
||||
Assert.assertEquals(lmDate,
|
||||
result.getFirstHeader("If-Modified-Since").getValue());
|
||||
Assert.assertEquals(etag,
|
||||
|
@ -120,9 +120,9 @@ public class TestConditionalRequestBuilder {
|
|||
final String theUri = "/theuri";
|
||||
final String theETag = "this is my eTag";
|
||||
|
||||
final HttpRequest request = new BasicHttpRequest(theMethod, theUri);
|
||||
request.addHeader("Accept-Encoding", "gzip");
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
|
||||
final HttpRequest basicRequest = new BasicHttpRequest(theMethod, theUri);
|
||||
basicRequest.addHeader("Accept-Encoding", "gzip");
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
|
||||
final Header[] headers = new Header[] {
|
||||
new BasicHeader("Date", DateUtils.formatDate(new Date())),
|
||||
|
@ -133,11 +133,11 @@ public class TestConditionalRequestBuilder {
|
|||
|
||||
final HttpRequest newRequest = impl.buildConditionalRequest(requestWrapper, cacheEntry);
|
||||
|
||||
Assert.assertNotSame(request, newRequest);
|
||||
Assert.assertNotSame(basicRequest, newRequest);
|
||||
|
||||
Assert.assertEquals(theMethod, newRequest.getRequestLine().getMethod());
|
||||
Assert.assertEquals(theUri, newRequest.getRequestLine().getUri());
|
||||
Assert.assertEquals(request.getRequestLine().getProtocolVersion(), newRequest
|
||||
Assert.assertEquals(basicRequest.getRequestLine().getProtocolVersion(), newRequest
|
||||
.getRequestLine().getProtocolVersion());
|
||||
|
||||
Assert.assertEquals(3, newRequest.getAllHeaders().length);
|
||||
|
@ -151,8 +151,8 @@ public class TestConditionalRequestBuilder {
|
|||
|
||||
@Test
|
||||
public void testCacheEntryWithMustRevalidateDoesEndToEndRevalidation() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
|
||||
final HttpRequest basicRequest = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final Date now = new Date();
|
||||
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
@ -180,8 +180,8 @@ public class TestConditionalRequestBuilder {
|
|||
|
||||
@Test
|
||||
public void testCacheEntryWithProxyRevalidateDoesEndToEndRevalidation() throws Exception {
|
||||
final HttpRequest request = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(request);
|
||||
final HttpRequest basicRequest = new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1);
|
||||
final HttpRequestWrapper requestWrapper = HttpRequestWrapper.wrap(basicRequest);
|
||||
final Date now = new Date();
|
||||
final Date elevenSecondsAgo = new Date(now.getTime() - 11 * 1000L);
|
||||
final Date tenSecondsAgo = new Date(now.getTime() - 10 * 1000L);
|
||||
|
|
|
@ -4842,12 +4842,12 @@ public class TestProtocolRequirements extends AbstractProtocolTest {
|
|||
}
|
||||
|
||||
protected HttpRequestWrapper makeRequestWithBody(final String method, final String requestUri) {
|
||||
final HttpEntityEnclosingRequest request =
|
||||
final HttpEntityEnclosingRequest req =
|
||||
new BasicHttpEntityEnclosingRequest(method, requestUri, HttpVersion.HTTP_1_1);
|
||||
final int nbytes = 128;
|
||||
request.setEntity(HttpTestUtils.makeBody(nbytes));
|
||||
request.setHeader("Content-Length",""+nbytes);
|
||||
return HttpRequestWrapper.wrap(request);
|
||||
req.setEntity(HttpTestUtils.makeBody(nbytes));
|
||||
req.setHeader("Content-Length",""+nbytes);
|
||||
return HttpRequestWrapper.wrap(req);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -101,8 +101,8 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
final HttpResponse resp2 = HttpTestUtils.make500Response();
|
||||
final byte[] body = HttpTestUtils.getRandomBytes(101);
|
||||
final ByteArrayInputStream buf = new ByteArrayInputStream(body);
|
||||
final byte[] body101 = HttpTestUtils.getRandomBytes(101);
|
||||
final ByteArrayInputStream buf = new ByteArrayInputStream(body101);
|
||||
final ConsumableInputStream cis = new ConsumableInputStream(buf);
|
||||
final HttpEntity entity = new InputStreamEntity(cis, 101);
|
||||
resp2.setEntity(entity);
|
||||
|
@ -167,9 +167,9 @@ public class TestRFC5861Compliance extends AbstractProtocolTest {
|
|||
@Test
|
||||
public void testStaleIfErrorInResponseNeedNotYieldToProxyRevalidateForPrivateCache()
|
||||
throws Exception{
|
||||
final CacheConfig config = CacheConfig.custom()
|
||||
final CacheConfig configUnshared = CacheConfig.custom()
|
||||
.setSharedCache(false).build();
|
||||
impl = new CachingExec(mockBackend, new BasicHttpCache(config), config);
|
||||
impl = new CachingExec(mockBackend, new BasicHttpCache(configUnshared), configUnshared);
|
||||
|
||||
final Date tenSecondsAgo = new Date(new Date().getTime() - 10 * 1000L);
|
||||
final HttpRequestWrapper req1 = HttpRequestWrapper.wrap(HttpTestUtils.makeDefaultRequest());
|
||||
|
|
|
@ -91,10 +91,10 @@ public class TestRequestProtocolCompliance {
|
|||
|
||||
@Test
|
||||
public void removesEntityFromTRACERequest() throws Exception {
|
||||
final HttpEntityEnclosingRequest req =
|
||||
final HttpEntityEnclosingRequest reqst =
|
||||
new BasicHttpEntityEnclosingRequest("TRACE", "/", HttpVersion.HTTP_1_1);
|
||||
req.setEntity(HttpTestUtils.makeBody(50));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(req);
|
||||
reqst.setEntity(HttpTestUtils.makeBody(50));
|
||||
final HttpRequestWrapper wrapper = HttpRequestWrapper.wrap(reqst);
|
||||
impl.makeRequestCompliant(wrapper);
|
||||
if (wrapper instanceof HttpEntityEnclosingRequest) {
|
||||
assertNull(((HttpEntityEnclosingRequest) wrapper).getEntity());
|
||||
|
|
|
@ -79,13 +79,13 @@ public class TestMemcachedCacheEntryImpl {
|
|||
@Test
|
||||
public void canBeReconstitutedFromByteArray() throws Exception {
|
||||
final String key = impl.getStorageKey();
|
||||
final HttpCacheEntry entry = impl.getHttpCacheEntry();
|
||||
final HttpCacheEntry entry1 = impl.getHttpCacheEntry();
|
||||
final byte[] bytes = impl.toByteArray();
|
||||
impl = new MemcachedCacheEntryImpl();
|
||||
impl.set(bytes);
|
||||
|
||||
assertEquals(key, impl.getStorageKey());
|
||||
assertEquivalent(entry, impl.getHttpCacheEntry());
|
||||
assertEquivalent(entry1, impl.getHttpCacheEntry());
|
||||
}
|
||||
|
||||
@Test(expected=MemcachedSerializationException.class)
|
||||
|
|
|
@ -286,7 +286,7 @@ public class RequestBuilder {
|
|||
|
||||
public HttpUriRequest build() {
|
||||
final HttpRequestBase result;
|
||||
URI uri = this.uri != null ? this.uri : URI.create("/");
|
||||
URI uriNotNull = this.uri != null ? this.uri : URI.create("/");
|
||||
HttpEntity entity = this.entity;
|
||||
if (parameters != null && !parameters.isEmpty()) {
|
||||
if (entity == null && (HttpPost.METHOD_NAME.equalsIgnoreCase(method)
|
||||
|
@ -294,7 +294,7 @@ public class RequestBuilder {
|
|||
entity = new UrlEncodedFormEntity(parameters, HTTP.DEF_CONTENT_CHARSET);
|
||||
} else {
|
||||
try {
|
||||
uri = new URIBuilder(uri).addParameters(parameters).build();
|
||||
uriNotNull = new URIBuilder(uriNotNull).addParameters(parameters).build();
|
||||
} catch (final URISyntaxException ex) {
|
||||
// should never happen
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ public class RequestBuilder {
|
|||
result = request;
|
||||
}
|
||||
result.setProtocolVersion(this.version);
|
||||
result.setURI(uri);
|
||||
result.setURI(uriNotNull);
|
||||
if (this.headergroup != null) {
|
||||
result.setHeaders(this.headergroup.getAllHeaders());
|
||||
}
|
||||
|
|
|
@ -91,9 +91,9 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
|
|||
|
||||
protected byte[] generateGSSToken(
|
||||
final byte[] input, final Oid oid, final String authServer) throws GSSException {
|
||||
byte[] token = input;
|
||||
if (token == null) {
|
||||
token = new byte[0];
|
||||
byte[] inputBuff = input;
|
||||
if (inputBuff == null) {
|
||||
inputBuff = new byte[0];
|
||||
}
|
||||
final GSSManager manager = getManager();
|
||||
final GSSName serverName = manager.createName("HTTP@" + authServer, GSSName.NT_HOSTBASED_SERVICE);
|
||||
|
@ -101,7 +101,7 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
|
|||
serverName.canonicalize(oid), oid, null, GSSContext.DEFAULT_LIFETIME);
|
||||
gssContext.requestMutualAuth(true);
|
||||
gssContext.requestCredDeleg(true);
|
||||
return gssContext.initSecContext(token, 0, token.length);
|
||||
return gssContext.initSecContext(inputBuff, 0, inputBuff.length);
|
||||
}
|
||||
|
||||
protected abstract byte[] generateToken(
|
||||
|
|
|
@ -129,7 +129,6 @@ public class RequestWrapper extends AbstractHttpMessage implements HttpUriReques
|
|||
|
||||
@Override
|
||||
public RequestLine getRequestLine() {
|
||||
final String method = getMethod();
|
||||
final ProtocolVersion ver = getProtocolVersion();
|
||||
String uritext = null;
|
||||
if (uri != null) {
|
||||
|
@ -138,7 +137,7 @@ public class RequestWrapper extends AbstractHttpMessage implements HttpUriReques
|
|||
if (uritext == null || uritext.isEmpty()) {
|
||||
uritext = "/";
|
||||
}
|
||||
return new BasicRequestLine(method, uritext, ver);
|
||||
return new BasicRequestLine(getMethod(), uritext, ver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -60,6 +60,7 @@ import org.mockito.MockitoAnnotations;
|
|||
/**
|
||||
* {@link PoolingHttpClientConnectionManager} tests.
|
||||
*/
|
||||
@SuppressWarnings({"boxing","static-access","resource"}) // test code
|
||||
public class TestPoolingHttpClientConnectionManager {
|
||||
|
||||
@Mock
|
||||
|
@ -300,7 +301,7 @@ public class TestPoolingHttpClientConnectionManager {
|
|||
|
||||
final ConnectionSocketFactory plainsf = Mockito.mock(ConnectionSocketFactory.class);
|
||||
final LayeredConnectionSocketFactory sslsf = Mockito.mock(LayeredConnectionSocketFactory.class);
|
||||
final Socket socket = Mockito.mock(Socket.class);
|
||||
final Socket mockSock = Mockito.mock(Socket.class);
|
||||
final HttpClientContext context = HttpClientContext.create();
|
||||
final SocketConfig sconfig = SocketConfig.custom().build();
|
||||
final ConnectionConfig cconfig = ConnectionConfig.custom().build();
|
||||
|
@ -313,31 +314,31 @@ public class TestPoolingHttpClientConnectionManager {
|
|||
Mockito.when(schemePortResolver.resolve(target)).thenReturn(8443);
|
||||
Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainsf);
|
||||
Mockito.when(socketFactoryRegistry.lookup("https")).thenReturn(sslsf);
|
||||
Mockito.when(plainsf.createSocket(Mockito.<HttpContext>any())).thenReturn(socket);
|
||||
Mockito.when(plainsf.createSocket(Mockito.<HttpContext>any())).thenReturn(mockSock);
|
||||
Mockito.when(plainsf.connectSocket(
|
||||
Mockito.anyInt(),
|
||||
Mockito.eq(socket),
|
||||
Mockito.eq(mockSock),
|
||||
Mockito.<HttpHost>any(),
|
||||
Mockito.<InetSocketAddress>any(),
|
||||
Mockito.<InetSocketAddress>any(),
|
||||
Mockito.<HttpContext>any())).thenReturn(socket);
|
||||
Mockito.<HttpContext>any())).thenReturn(mockSock);
|
||||
|
||||
mgr.connect(conn1, route, 123, context);
|
||||
|
||||
Mockito.verify(dnsResolver, Mockito.times(1)).resolve("someproxy");
|
||||
Mockito.verify(schemePortResolver, Mockito.times(1)).resolve(proxy);
|
||||
Mockito.verify(plainsf, Mockito.times(1)).createSocket(context);
|
||||
Mockito.verify(plainsf, Mockito.times(1)).connectSocket(123, socket, proxy,
|
||||
Mockito.verify(plainsf, Mockito.times(1)).connectSocket(123, mockSock, proxy,
|
||||
new InetSocketAddress(remote, 8080),
|
||||
new InetSocketAddress(local, 0), context);
|
||||
|
||||
Mockito.when(conn.getSocket()).thenReturn(socket);
|
||||
Mockito.when(conn.getSocket()).thenReturn(mockSock);
|
||||
|
||||
mgr.upgrade(conn1, route, context);
|
||||
|
||||
Mockito.verify(schemePortResolver, Mockito.times(1)).resolve(target);
|
||||
Mockito.verify(sslsf, Mockito.times(1)).createLayeredSocket(
|
||||
socket, "somehost", 8443, context);
|
||||
mockSock, "somehost", 8443, context);
|
||||
|
||||
mgr.routeComplete(conn1, route, context);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
package org.apache.http.impl.execchain;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntityEnclosingRequest;
|
||||
import org.apache.http.HttpHost;
|
||||
|
@ -52,6 +53,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
@SuppressWarnings({"boxing","static-access","resource"}) // test code
|
||||
public class TestRetryExec {
|
||||
|
||||
@Mock
|
||||
|
@ -165,8 +167,8 @@ public class TestRetryExec {
|
|||
@Override
|
||||
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
|
||||
final Object[] args = invocationOnMock.getArguments();
|
||||
final HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) args[1];
|
||||
request.getEntity().writeTo(new ByteArrayOutputStream());
|
||||
final HttpEntityEnclosingRequest req = (HttpEntityEnclosingRequest) args[1];
|
||||
req.getEntity().writeTo(new ByteArrayOutputStream());
|
||||
throw new IOException("Ka-boom");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue