mirror of
https://github.com/apache/httpcomponents-client.git
synced 2025-03-01 14:19:18 +00:00
Upgraded to Java 1.7
git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1681461 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b29c819645
commit
3b5990e363
@ -54,7 +54,7 @@ public static void main(String[] args)throws Exception {
|
||||
};
|
||||
|
||||
|
||||
Queue<Future<Content>> queue = new LinkedList<Future<Content>>();
|
||||
Queue<Future<Content>> queue = new LinkedList<>();
|
||||
// Execute requests asynchronously
|
||||
for (final Request request: requests) {
|
||||
Future<Content> future = async.execute(request, new FutureCallback<Content>() {
|
||||
|
@ -89,8 +89,8 @@ public void run() {
|
||||
|
||||
public <T> Future<T> execute(
|
||||
final Request request, final ResponseHandler<T> handler, final FutureCallback<T> callback) {
|
||||
final BasicFuture<T> future = new BasicFuture<T>(callback);
|
||||
final ExecRunnable<T> runnable = new ExecRunnable<T>(
|
||||
final BasicFuture<T> future = new BasicFuture<>(callback);
|
||||
final ExecRunnable<T> runnable = new ExecRunnable<>(
|
||||
future,
|
||||
request,
|
||||
this.executor != null ? this.executor : Executor.newInstance(),
|
||||
|
@ -82,9 +82,7 @@ public class Executor {
|
||||
sslcontext = SSLContext.getInstance(SSLConnectionSocketFactory.TLS);
|
||||
sslcontext.init(null, null, null);
|
||||
ssl = new SSLConnectionSocketFactory(sslcontext);
|
||||
} catch (final SecurityException ignore) {
|
||||
} catch (final KeyManagementException ignore) {
|
||||
} catch (final NoSuchAlgorithmException ignore) {
|
||||
} catch (final SecurityException | NoSuchAlgorithmException | KeyManagementException ignore) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public static Form form() {
|
||||
|
||||
Form() {
|
||||
super();
|
||||
this.params = new ArrayList<NameValuePair>();
|
||||
this.params = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Form add(final String name, final String value) {
|
||||
@ -51,7 +51,7 @@ public Form add(final String name, final String value) {
|
||||
}
|
||||
|
||||
public List<NameValuePair> build() {
|
||||
return new ArrayList<NameValuePair>(this.params);
|
||||
return new ArrayList<>(this.params);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -67,16 +67,13 @@ public InputStream getContent() throws IOException {
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = new FileInputStream(this.file);
|
||||
try {
|
||||
try (InputStream instream = new FileInputStream(this.file)) {
|
||||
final byte[] tmp = new byte[4096];
|
||||
int l;
|
||||
while ((l = instream.read(tmp)) != -1) {
|
||||
outstream.write(tmp, 0, l);
|
||||
}
|
||||
outstream.flush();
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ class InternalHttpRequest extends AbstractHttpMessage
|
||||
this.method = method;
|
||||
this.uri = requestURI;
|
||||
this.aborted = new AtomicBoolean(false);
|
||||
this.cancellableRef = new AtomicReference<Cancellable>(null);
|
||||
this.cancellableRef = new AtomicReference<>(null);
|
||||
}
|
||||
|
||||
public void setProtocolVersion(final ProtocolVersion version) {
|
||||
|
@ -67,8 +67,7 @@ public InputStream getContent() throws IOException {
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = this.content;
|
||||
try {
|
||||
try (InputStream instream = this.content) {
|
||||
final byte[] buffer = new byte[4096];
|
||||
int l;
|
||||
if (this.length < 0) {
|
||||
@ -80,7 +79,7 @@ public void writeTo(final OutputStream outstream) throws IOException {
|
||||
// consume no more than length
|
||||
long remaining = this.length;
|
||||
while (remaining > 0) {
|
||||
l = instream.read(buffer, 0, (int)Math.min(4096, remaining));
|
||||
l = instream.read(buffer, 0, (int) Math.min(4096, remaining));
|
||||
if (l == -1) {
|
||||
break;
|
||||
}
|
||||
@ -88,8 +87,6 @@ public void writeTo(final OutputStream outstream) throws IOException {
|
||||
remaining -= l;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -309,7 +309,7 @@ public Request body(final HttpEntity entity) {
|
||||
}
|
||||
|
||||
public Request bodyForm(final Iterable <? extends NameValuePair> formParams, final Charset charset) {
|
||||
final List<NameValuePair> paramList = new ArrayList<NameValuePair>();
|
||||
final List<NameValuePair> paramList = new ArrayList<>();
|
||||
for (NameValuePair param : formParams) {
|
||||
paramList.add(param);
|
||||
}
|
||||
|
@ -121,15 +121,14 @@ public void saveContent(final File file) throws IOException {
|
||||
throw new HttpResponseException(statusLine.getStatusCode(),
|
||||
statusLine.getReasonPhrase());
|
||||
}
|
||||
final FileOutputStream out = new FileOutputStream(file);
|
||||
try {
|
||||
try (FileOutputStream out = new FileOutputStream(file)) {
|
||||
final HttpEntity entity = this.response.getEntity();
|
||||
if (entity != null) {
|
||||
entity.writeTo(out);
|
||||
}
|
||||
} finally {
|
||||
this.consumed = true;
|
||||
out.close();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ public HttpCacheEntry(
|
||||
this.responseHeaders.setHeaders(responseHeaders);
|
||||
this.resource = resource;
|
||||
this.variantMap = variantMap != null
|
||||
? new HashMap<String,String>(variantMap)
|
||||
? new HashMap<>(variantMap)
|
||||
: null;
|
||||
this.date = parseDate();
|
||||
}
|
||||
|
@ -110,12 +110,9 @@ public void run() {
|
||||
*/
|
||||
private boolean revalidateCacheEntry() {
|
||||
try {
|
||||
final CloseableHttpResponse httpResponse = cachingExec.revalidateCacheEntry(route, request, context, execAware, cacheEntry);
|
||||
try {
|
||||
try (CloseableHttpResponse httpResponse = cachingExec.revalidateCacheEntry(route, request, context, execAware, cacheEntry)) {
|
||||
final int statusCode = httpResponse.getStatusLine().getStatusCode();
|
||||
return isNotServerError(statusCode) && isNotStale(httpResponse);
|
||||
} finally {
|
||||
httpResponse.close();
|
||||
}
|
||||
} catch (final IOException ioe) {
|
||||
log.debug("Asynchronous revalidation failed due to I/O error", ioe);
|
||||
|
@ -76,7 +76,7 @@ public AsynchronousValidator(final CacheConfig config) {
|
||||
*/
|
||||
AsynchronousValidator(final SchedulingStrategy schedulingStrategy) {
|
||||
this.schedulingStrategy = schedulingStrategy;
|
||||
this.queued = new HashSet<String>();
|
||||
this.queued = new HashSet<>();
|
||||
this.cacheKeyGenerator = new CacheKeyGenerator();
|
||||
this.failureCache = new DefaultFailureCache();
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
import org.apache.http.protocol.HTTP;
|
||||
|
||||
class BasicHttpCache implements HttpCache {
|
||||
private static final Set<String> safeRequestMethods = new HashSet<String>(
|
||||
private static final Set<String> safeRequestMethods = new HashSet<>(
|
||||
Arrays.asList(HeaderConstants.HEAD_METHOD,
|
||||
HeaderConstants.GET_METHOD, HeaderConstants.OPTIONS_METHOD,
|
||||
HeaderConstants.TRACE_METHOD));
|
||||
@ -245,7 +245,7 @@ HttpCacheEntry doGetUpdatedParentEntry(
|
||||
if (src.getResource() != null) {
|
||||
resource = resourceFactory.copy(requestId, src.getResource());
|
||||
}
|
||||
final Map<String,String> variantMap = new HashMap<String,String>(src.getVariantMap());
|
||||
final Map<String,String> variantMap = new HashMap<>(src.getVariantMap());
|
||||
variantMap.put(variantKey, variantCacheKey);
|
||||
return new HttpCacheEntry(
|
||||
src.getRequestDate(),
|
||||
@ -364,7 +364,7 @@ public void flushInvalidatedCacheEntriesFor(final HttpHost host,
|
||||
@Override
|
||||
public Map<String, Variant> getVariantCacheEntriesWithEtags(final HttpHost host, final HttpRequest request)
|
||||
throws IOException {
|
||||
final Map<String,Variant> variants = new HashMap<String,Variant>();
|
||||
final Map<String,Variant> variants = new HashMap<>();
|
||||
final HttpCacheEntry root = storage.getEntry(uriExtractor.getURI(host, request));
|
||||
if (root == null || !root.hasVariants()) {
|
||||
return variants;
|
||||
|
@ -83,11 +83,8 @@ public InputStream getContent() throws IOException {
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = this.cacheEntry.getResource().getInputStream();
|
||||
try {
|
||||
try (InputStream instream = this.cacheEntry.getResource().getInputStream()) {
|
||||
IOUtils.copy(instream, outstream);
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -108,7 +108,7 @@ && entryDateHeaderNewerThenResponse(entry, response)) {
|
||||
return entry.getAllHeaders();
|
||||
}
|
||||
|
||||
final List<Header> cacheEntryHeaderList = new ArrayList<Header>(Arrays.asList(entry
|
||||
final List<Header> cacheEntryHeaderList = new ArrayList<>(Arrays.asList(entry
|
||||
.getAllHeaders()));
|
||||
removeCacheHeadersThatMatchResponse(cacheEntryHeaderList, response);
|
||||
removeCacheEntry1xxWarnings(cacheEntryHeaderList, entry);
|
||||
|
@ -146,7 +146,7 @@ public String getVariantURI(final HttpHost host, final HttpRequest req, final Ht
|
||||
* @return a {@code String} variant key
|
||||
*/
|
||||
public String getVariantKey(final HttpRequest req, final HttpCacheEntry entry) {
|
||||
final List<String> variantHeaderNames = new ArrayList<String>();
|
||||
final List<String> variantHeaderNames = new ArrayList<>();
|
||||
for (final Header varyHdr : entry.getHeaders(HeaderConstants.VARY)) {
|
||||
for (final HeaderElement elt : varyHdr.getElements()) {
|
||||
variantHeaderNames.add(elt.getName());
|
||||
|
@ -108,7 +108,7 @@ public class CachingExec implements ClientExecChain {
|
||||
private final AtomicLong cacheMisses = new AtomicLong();
|
||||
private final AtomicLong cacheUpdates = new AtomicLong();
|
||||
|
||||
private final Map<ProtocolVersion, String> viaHeaders = new HashMap<ProtocolVersion, String>(4);
|
||||
private final Map<ProtocolVersion, String> viaHeaders = new HashMap<>(4);
|
||||
|
||||
private final CacheConfig cacheConfig;
|
||||
private final ClientExecChain backend;
|
||||
@ -594,10 +594,7 @@ CloseableHttpResponse callBackend(
|
||||
backendResponse.addHeader("Via", generateViaHeader(backendResponse));
|
||||
return handleBackendResponse(request, context, requestDate, getCurrentDate(),
|
||||
backendResponse);
|
||||
} catch (final IOException ex) {
|
||||
backendResponse.close();
|
||||
throw ex;
|
||||
} catch (final RuntimeException ex) {
|
||||
} catch (final IOException | RuntimeException ex) {
|
||||
backendResponse.close();
|
||||
throw ex;
|
||||
}
|
||||
@ -685,10 +682,7 @@ CloseableHttpResponse negotiateResponseFromVariants(
|
||||
return responseGenerator.generateNotModifiedResponse(responseEntry);
|
||||
}
|
||||
return resp;
|
||||
} catch (final IOException ex) {
|
||||
backendResponse.close();
|
||||
throw ex;
|
||||
} catch (final RuntimeException ex) {
|
||||
} catch (final IOException | RuntimeException ex) {
|
||||
backendResponse.close();
|
||||
throw ex;
|
||||
}
|
||||
|
@ -73,15 +73,12 @@ public InputStream getContent() throws IOException, IllegalStateException {
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = getContent();
|
||||
try {
|
||||
try (InputStream instream = getContent()) {
|
||||
int l;
|
||||
final byte[] tmp = new byte[2048];
|
||||
while ((l = instream.read(tmp)) != -1) {
|
||||
outstream.write(tmp, 0, l);
|
||||
}
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ public DefaultFailureCache() {
|
||||
*/
|
||||
public DefaultFailureCache(final int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
this.storage = new ConcurrentHashMap<String, FailureCacheValue>();
|
||||
this.storage = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,23 +50,17 @@ public class DefaultHttpCacheEntrySerializer implements HttpCacheEntrySerializer
|
||||
|
||||
@Override
|
||||
public void writeTo(final HttpCacheEntry cacheEntry, final OutputStream os) throws IOException {
|
||||
final ObjectOutputStream oos = new ObjectOutputStream(os);
|
||||
try {
|
||||
try (ObjectOutputStream oos = new ObjectOutputStream(os)) {
|
||||
oos.writeObject(cacheEntry);
|
||||
} finally {
|
||||
oos.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpCacheEntry readFrom(final InputStream is) throws IOException {
|
||||
final ObjectInputStream ois = new ObjectInputStream(is);
|
||||
try {
|
||||
try (ObjectInputStream ois = new ObjectInputStream(is)) {
|
||||
return (HttpCacheEntry) ois.readObject();
|
||||
} catch (final ClassNotFoundException ex) {
|
||||
throw new HttpCacheEntrySerializationException("Class not found: " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
ois.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,8 +75,7 @@ public Resource generate(
|
||||
final InputStream instream,
|
||||
final InputLimit limit) throws IOException {
|
||||
final File file = generateUniqueCacheFile(requestId);
|
||||
final FileOutputStream outstream = new FileOutputStream(file);
|
||||
try {
|
||||
try (FileOutputStream outstream = new FileOutputStream(file)) {
|
||||
final byte[] buf = new byte[2048];
|
||||
long total = 0;
|
||||
int l;
|
||||
@ -88,8 +87,6 @@ public Resource generate(
|
||||
break;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
outstream.close();
|
||||
}
|
||||
return new FileResource(file);
|
||||
}
|
||||
|
@ -81,8 +81,8 @@ public class ManagedHttpCacheStorage implements HttpCacheStorage, Closeable {
|
||||
public ManagedHttpCacheStorage(final CacheConfig config) {
|
||||
super();
|
||||
this.entries = new CacheMap(config.getMaxCacheEntries());
|
||||
this.morque = new ReferenceQueue<HttpCacheEntry>();
|
||||
this.resources = new HashSet<ResourceReference>();
|
||||
this.morque = new ReferenceQueue<>();
|
||||
this.resources = new HashSet<>();
|
||||
this.active = new AtomicBoolean(true);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ public RequestProtocolCompliance(final boolean weakETagOnPutDeleteAllowed) {
|
||||
* @return list of {@link RequestProtocolError}
|
||||
*/
|
||||
public List<RequestProtocolError> requestIsFatallyNonCompliant(final HttpRequest request) {
|
||||
final List<RequestProtocolError> theErrors = new ArrayList<RequestProtocolError>();
|
||||
final List<RequestProtocolError> theErrors = new ArrayList<>();
|
||||
|
||||
RequestProtocolError anError = requestHasWeakETagAndRange(request);
|
||||
if (anError != null) {
|
||||
@ -125,7 +125,7 @@ public void makeRequestCompliant(final HttpRequestWrapper request)
|
||||
}
|
||||
|
||||
private void stripOtherFreshnessDirectivesWithNoCache(final HttpRequest request) {
|
||||
final List<HeaderElement> outElts = new ArrayList<HeaderElement>();
|
||||
final List<HeaderElement> outElts = new ArrayList<>();
|
||||
boolean shouldStrip = false;
|
||||
for(final Header h : request.getHeaders(HeaderConstants.CACHE_CONTROL)) {
|
||||
for(final HeaderElement elt : h.getElements()) {
|
||||
@ -216,7 +216,7 @@ private void remove100ContinueHeaderIfExists(final HttpRequest request) {
|
||||
boolean hasHeader = false;
|
||||
|
||||
final Header[] expectHeaders = request.getHeaders(HTTP.EXPECT_DIRECTIVE);
|
||||
List<HeaderElement> expectElementsThatAreNot100Continue = new ArrayList<HeaderElement>();
|
||||
List<HeaderElement> expectElementsThatAreNot100Continue = new ArrayList<>();
|
||||
|
||||
for (final Header h : expectHeaders) {
|
||||
for (final HeaderElement elt : h.getElements()) {
|
||||
@ -235,7 +235,7 @@ private void remove100ContinueHeaderIfExists(final HttpRequest request) {
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
expectElementsThatAreNot100Continue = new ArrayList<HeaderElement>();
|
||||
expectElementsThatAreNot100Continue = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ private void warningsWithNonMatchingWarnDatesAreRemoved(
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Header> newWarningHeaders = new ArrayList<Header>();
|
||||
final List<Header> newWarningHeaders = new ArrayList<>();
|
||||
boolean modified = false;
|
||||
for(final Header h : warningHeaders) {
|
||||
for(final WarningValue wv : WarningValue.getWarningValues(h)) {
|
||||
@ -135,7 +135,7 @@ private void identityIsNotUsedInContentEncoding(final HttpResponse response) {
|
||||
if (hdrs == null || hdrs.length == 0) {
|
||||
return;
|
||||
}
|
||||
final List<Header> newHeaders = new ArrayList<Header>();
|
||||
final List<Header> newHeaders = new ArrayList<>();
|
||||
boolean modified = false;
|
||||
for (final Header h : hdrs) {
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
|
@ -69,7 +69,7 @@ class WarningValue {
|
||||
* @return array of {@code WarnValue} objects
|
||||
*/
|
||||
public static WarningValue[] getWarningValues(final Header h) {
|
||||
final List<WarningValue> out = new ArrayList<WarningValue>();
|
||||
final List<WarningValue> out = new ArrayList<>();
|
||||
final String src = h.getValue();
|
||||
int offs = 0;
|
||||
while(offs < src.length()) {
|
||||
|
@ -101,10 +101,8 @@ synchronized public void set(final byte[] bytes) {
|
||||
entry = (HttpCacheEntry)ois.readObject();
|
||||
ois.close();
|
||||
bis.close();
|
||||
} catch (final IOException ioe) {
|
||||
} catch (final IOException | ClassNotFoundException ioe) {
|
||||
throw new MemcachedSerializationException(ioe);
|
||||
} catch (final ClassNotFoundException cnfe) {
|
||||
throw new MemcachedSerializationException(cnfe);
|
||||
}
|
||||
this.key = s;
|
||||
this.httpCacheEntry = entry;
|
||||
|
@ -271,7 +271,7 @@ public void canProvideVariantMap() {
|
||||
|
||||
@Test
|
||||
public void canRetrieveOriginalVariantMap() {
|
||||
final Map<String,String> variantMap = new HashMap<String,String>();
|
||||
final Map<String,String> variantMap = new HashMap<>();
|
||||
variantMap.put("A","B");
|
||||
variantMap.put("C","D");
|
||||
entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
|
||||
@ -285,7 +285,7 @@ public void canRetrieveOriginalVariantMap() {
|
||||
|
||||
@Test
|
||||
public void retrievedVariantMapIsNotModifiable() {
|
||||
final Map<String,String> variantMap = new HashMap<String,String>();
|
||||
final Map<String,String> variantMap = new HashMap<>();
|
||||
variantMap.put("A","B");
|
||||
variantMap.put("C","D");
|
||||
entry = new HttpCacheEntry(new Date(), new Date(), statusLine,
|
||||
|
@ -400,7 +400,7 @@ public static HttpResponse make500Response() {
|
||||
}
|
||||
|
||||
public static Map<String, String> makeDefaultVariantMap(final String key, final String value) {
|
||||
final Map<String, String> variants = new HashMap<String, String>();
|
||||
final Map<String, String> variants = new HashMap<>();
|
||||
variants.put(key, value);
|
||||
|
||||
return variants;
|
||||
|
@ -39,7 +39,7 @@ class SimpleHttpCacheStorage implements HttpCacheStorage {
|
||||
public final Map<String,HttpCacheEntry> map;
|
||||
|
||||
public SimpleHttpCacheStorage() {
|
||||
map = new HashMap<String,HttpCacheEntry>();
|
||||
map = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -318,7 +318,7 @@ public void testCacheUpdateAddsVariantURIToParentEntry() throws Exception {
|
||||
final String existingVariantKey = "existingVariantKey";
|
||||
final String newVariantCacheKey = "newVariantCacheKey";
|
||||
final String newVariantKey = "newVariantKey";
|
||||
final Map<String,String> existingVariants = new HashMap<String,String>();
|
||||
final Map<String,String> existingVariants = new HashMap<>();
|
||||
existingVariants.put(existingVariantKey, variantCacheKey);
|
||||
final HttpCacheEntry parent = HttpTestUtils.makeCacheEntry(existingVariants);
|
||||
final HttpCacheEntry variant = HttpTestUtils.makeCacheEntry();
|
||||
|
@ -89,7 +89,7 @@ public void setUp() {
|
||||
public void testInvalidatesRequestsThatArentGETorHEAD() throws Exception {
|
||||
request = new BasicHttpRequest("POST","/path", HTTP_1_1);
|
||||
final String theUri = "http://foo.example.com:80/path";
|
||||
final Map<String,String> variantMap = new HashMap<String,String>();
|
||||
final Map<String,String> variantMap = new HashMap<>();
|
||||
cacheEntryHasVariantMap(variantMap);
|
||||
|
||||
cacheReturnsEntryForUri(theUri);
|
||||
|
@ -301,7 +301,7 @@ public void testNewerCacheableResponsesReplaceExistingCacheEntry() throws Except
|
||||
}
|
||||
|
||||
protected void requestIsFatallyNonCompliant(final RequestProtocolError error) {
|
||||
final List<RequestProtocolError> errors = new ArrayList<RequestProtocolError>();
|
||||
final List<RequestProtocolError> errors = new ArrayList<>();
|
||||
if (error != null) {
|
||||
errors.add(error);
|
||||
}
|
||||
@ -420,7 +420,7 @@ public void testRecordsClientProtocolInViaHeaderIfRequestNotServableFromCache()
|
||||
req.setHeader("Cache-Control", "no-cache");
|
||||
final HttpResponse resp = new BasicHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpStatus.SC_NO_CONTENT, "No Content");
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
|
||||
backendCaptureRequestAndReturn(cap, resp);
|
||||
|
||||
|
@ -315,7 +315,7 @@ public void testBuildConditionalRequestFromVariants() throws Exception {
|
||||
final String etag2 = "\"456\"";
|
||||
final String etag3 = "\"789\"";
|
||||
|
||||
final Map<String,Variant> variantEntries = new HashMap<String,Variant>();
|
||||
final Map<String,Variant> variantEntries = new HashMap<>();
|
||||
variantEntries.put(etag1, new Variant("A","B",HttpTestUtils.makeCacheEntry(new Header[] { new BasicHeader("ETag", etag1) })));
|
||||
variantEntries.put(etag2, new Variant("C","D",HttpTestUtils.makeCacheEntry(new Header[] { new BasicHeader("ETag", etag2) })));
|
||||
variantEntries.put(etag3, new Variant("E","F",HttpTestUtils.makeCacheEntry(new Header[] { new BasicHeader("ETag", etag3) })));
|
||||
|
@ -89,7 +89,7 @@ private HttpCacheEntry makeCacheEntryWithVariantMap() {
|
||||
|
||||
final ProtocolVersion pvObj = new ProtocolVersion("HTTP", 1, 1);
|
||||
final StatusLine slObj = new BasicStatusLine(pvObj, 200, "ok");
|
||||
final Map<String,String> variantMap = new HashMap<String,String>();
|
||||
final Map<String,String> variantMap = new HashMap<>();
|
||||
variantMap.put("test variant 1","true");
|
||||
variantMap.put("test variant 2","true");
|
||||
final HttpCacheEntry cacheEntry = new HttpCacheEntry(new Date(), new Date(),
|
||||
|
@ -226,7 +226,7 @@ public void testHTTP1_1RequestsWithUnknownBodyLengthAreRejectedOrHaveContentLeng
|
||||
org.easymock.EasyMock.expect(mockBody.getContentLength()).andReturn(-1L).anyTimes();
|
||||
post.setEntity(mockBody);
|
||||
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -268,7 +268,7 @@ public void testOPTIONSRequestsWithBodiesAndNoContentTypeHaveOneSupplied() throw
|
||||
options.setEntity(body);
|
||||
options.setHeader("Content-Length", "1");
|
||||
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
|
@ -245,7 +245,7 @@ private void cacheGenerated304ForStrongValidatorShouldNotContainContentRange(
|
||||
|
||||
// cache module does not currently deal with byte ranges, but we want
|
||||
// this test to work even if it does some day
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -647,7 +647,7 @@ private void testDoesNotModifyHeaderOnResponses(final String headerName)
|
||||
private void testDoesNotModifyHeaderOnRequests(final String headerName)
|
||||
throws Exception {
|
||||
final String headerValue = HttpTestUtils.getCanonicalHeaderValue(request, headerName);
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -931,7 +931,7 @@ public void testUsesLastModifiedDateForCacheConditionalRequests()
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
@ -980,7 +980,7 @@ public void testUsesBothLastModifiedAndETagForConditionalRequestsIfAvailable()
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp1);
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpRequestWrapper req2 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
@ -1095,7 +1095,7 @@ public void testRetriesValidationThatResultsInAnOlderDated304Response()
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpResponse resp3 = HttpTestUtils.make200Response();
|
||||
resp3.setHeader("ETag","\"etag2\"");
|
||||
resp3.setHeader("Date", DateUtils.formatDate(now));
|
||||
@ -1171,7 +1171,7 @@ public void testSendsAllVariantEtagsInConditionalRequest()
|
||||
|
||||
backendExpectsAnyRequestAndReturn(resp2);
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
final HttpRequestWrapper req3 = HttpRequestWrapper.wrap(
|
||||
new BasicHttpRequest("GET","/",HttpVersion.HTTP_1_1));
|
||||
req3.setHeader("User-Agent","agent3");
|
||||
@ -1349,7 +1349,7 @@ public void variantNegotiationsDoNotIncludeEtagsForPartialResponses()
|
||||
resp1.setHeader("Vary", "User-Agent");
|
||||
resp1.setHeader("ETag", "\"etag3\"");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -1669,7 +1669,7 @@ public void otherFreshnessRequestDirectivesNotAllowedWithNoCache()
|
||||
req1.addHeader("Cache-Control", "max-stale=0, max-age=0");
|
||||
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
|
@ -301,7 +301,7 @@ public void testTransferCodingsAreNotSentToAnHTTP_1_0Client() throws Exception {
|
||||
*/
|
||||
private void testOrderOfMultipleHeadersIsPreservedOnRequests(final String h, final HttpRequestWrapper request)
|
||||
throws Exception {
|
||||
final Capture<HttpRequestWrapper> reqCapture = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCapture = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -557,7 +557,7 @@ public void testUnknownResponseStatusCodesAreNotCached() throws Exception {
|
||||
@Test
|
||||
public void testUnknownHeadersOnRequestsAreForwarded() throws Exception {
|
||||
request.addHeader("X-Unknown-Header", "blahblah");
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.isA(HttpRoute.class),
|
||||
@ -611,7 +611,7 @@ public void testRequestsExpecting100ContinueBehaviorShouldSetExpectHeader() thro
|
||||
post.setHeader("Content-Length", "128");
|
||||
post.setEntity(new BasicHttpEntity());
|
||||
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -654,7 +654,7 @@ public void testRequestsNotExpecting100ContinueBehaviorShouldNotSetExpectContinu
|
||||
post.setHeader("Content-Length", "128");
|
||||
post.setEntity(new BasicHttpEntity());
|
||||
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -692,7 +692,7 @@ public void testRequestsNotExpecting100ContinueBehaviorShouldNotSetExpectContinu
|
||||
@Test
|
||||
public void testExpect100ContinueIsNotSentIfThereIsNoRequestBody() throws Exception {
|
||||
request.addHeader("Expect", "100-continue");
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -862,7 +862,7 @@ public void testDecrementsMaxForwardsWhenForwardingOPTIONSRequest() throws Excep
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS", "*", HttpVersion.HTTP_1_1));
|
||||
request.setHeader("Max-Forwards", "7");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -888,7 +888,7 @@ public void testDecrementsMaxForwardsWhenForwardingOPTIONSRequest() throws Excep
|
||||
@Test
|
||||
public void testDoesNotAddAMaxForwardsHeaderToForwardedOPTIONSRequests() throws Exception {
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("OPTIONS", "/", HttpVersion.HTTP_1_1));
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -1119,7 +1119,7 @@ public void testForwardedTRACERequestsDoNotIncludeAnEntity() throws Exception {
|
||||
trace.setEntity(HttpTestUtils.makeBody(entityLength));
|
||||
trace.setHeader("Content-Length", Integer.toString(entityLength));
|
||||
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> reqCap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -2241,8 +2241,8 @@ public void testCacheEntryIsUpdatedWithNewFieldValuesIn304Response() throws Exce
|
||||
unconditionalResponse.setHeader("Date", DateUtils.formatDate(inFiveSeconds));
|
||||
unconditionalResponse.setHeader("ETag", "\"etag\"");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap1 = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap2 = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap1 = new Capture<>();
|
||||
final Capture<HttpRequestWrapper> cap2 = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -2879,7 +2879,7 @@ public void testHeuristicCacheOlderThan24HoursHasWarningAttached() throws Except
|
||||
|
||||
final CloseableHttpResponse reconstructed = Proxies.enhanceResponse(HttpTestUtils.make200Response());
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
|
||||
mockCache.flushInvalidatedCacheEntriesFor(EasyMock.eq(host), eqRequest(request));
|
||||
mockCache.flushInvalidatedCacheEntriesFor(
|
||||
@ -2995,7 +2995,7 @@ public void testKeepsMostRecentDateHeaderForFreshResponse() throws Exception {
|
||||
*/
|
||||
private HttpResponse testRequestWithWeakETagValidatorIsNotAllowed(final String header)
|
||||
throws Exception {
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -3137,7 +3137,7 @@ public void testValidationMustUseETagIfProvidedByOriginServer() throws Exception
|
||||
new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1));
|
||||
req2.setHeader("Cache-Control", "max-age=0,max-stale=0");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.isA(HttpRoute.class),
|
||||
@ -3497,7 +3497,7 @@ private void testDoesNotModifyHeaderOnRequest(final String header, final String
|
||||
req.setHeader("Content-Length","128");
|
||||
req.setHeader(header,value);
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -3544,7 +3544,7 @@ private void testDoesNotAddHeaderToRequestIfNotPresent(final String header) thro
|
||||
req.setHeader("Content-Length","128");
|
||||
req.removeHeaders(header);
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -4577,8 +4577,8 @@ public void testNonmatchingVariantCannotBeServedFromCacheUnlessConditionallyVali
|
||||
resp304.setHeader("ETag","\"etag1\"");
|
||||
resp304.setHeader("Vary","User-Agent");
|
||||
|
||||
final Capture<HttpRequestWrapper> condCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> uncondCap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> condCap = new Capture<>();
|
||||
final Capture<HttpRequestWrapper> uncondCap = new Capture<>();
|
||||
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -5131,7 +5131,7 @@ protected void testSharedCacheMustUseNewRequestHeadersWhenRevalidatingAuthorized
|
||||
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -5209,7 +5209,7 @@ public void testWarning110IsAddedToStaleResponses()
|
||||
req2.setHeader("Cache-Control","max-stale=60");
|
||||
final HttpResponse resp2 = HttpTestUtils.make200Response();
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -5247,7 +5247,7 @@ public void testWarning110IsAddedToStaleResponses()
|
||||
public void testDoesNotTransmitNoCacheDirectivesWithFieldsDownstream()
|
||||
throws Exception {
|
||||
request.setHeader("Cache-Control","no-cache=\"X-Field\"");
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
EasyMock.capture(cap),
|
||||
@ -5293,7 +5293,7 @@ protected void testCacheIsNotUsedWhenRespondingToRequest(final HttpRequestWrappe
|
||||
resp2.setHeader("Etag","\"etag2\"");
|
||||
resp2.setHeader("Cache-Control","max-age=1200");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
EasyMock.capture(cap),
|
||||
@ -5352,7 +5352,7 @@ protected void testStaleCacheResponseMustBeRevalidatedWithOrigin(
|
||||
resp2.setHeader("ETag","\"etag2\"");
|
||||
resp2.setHeader("Cache-Control","max-age=5, must-revalidate");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
// this request MUST happen
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -5607,7 +5607,7 @@ public void testNoCacheOnFieldIsNotReturnedWithoutRevalidation()
|
||||
resp2.setHeader("X-Stuff","things");
|
||||
resp2.setHeader("Cache-Control","no-cache=\"X-Stuff\",max-age=3600");
|
||||
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.eq(route),
|
||||
@ -5995,7 +5995,7 @@ public void testVaryStarIsNotGeneratedByProxy()
|
||||
*/
|
||||
@Test
|
||||
public void testProperlyFormattedViaHeaderIsAddedToRequests() throws Exception {
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
request.removeHeaders("Via");
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
@ -6097,7 +6097,7 @@ public void testViaHeaderOnRequestProperlyRecordsClientProtocol()
|
||||
throws Exception {
|
||||
request = HttpRequestWrapper.wrap(new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_0));
|
||||
request.removeHeaders("Via");
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<HttpRequestWrapper>();
|
||||
final Capture<HttpRequestWrapper> cap = new Capture<>();
|
||||
EasyMock.expect(
|
||||
mockBackend.execute(
|
||||
EasyMock.isA(HttpRoute.class),
|
||||
|
@ -158,8 +158,7 @@ public void close() throws IOException {
|
||||
|
||||
impl.readResponse();
|
||||
final boolean tooLarge = impl.isLimitReached();
|
||||
final CloseableHttpResponse result = impl.getReconstructedResponse();
|
||||
try {
|
||||
try (CloseableHttpResponse result = impl.getReconstructedResponse()) {
|
||||
final HttpEntity reconstructedEntity = result.getEntity();
|
||||
Assert.assertEquals(entity.getContentEncoding(), reconstructedEntity.getContentEncoding());
|
||||
Assert.assertEquals(entity.getContentType(), reconstructedEntity.getContentType());
|
||||
@ -169,8 +168,6 @@ public void close() throws IOException {
|
||||
|
||||
Assert.assertTrue(tooLarge);
|
||||
Assert.assertEquals("large entity content", content);
|
||||
} finally {
|
||||
result.close();
|
||||
}
|
||||
Assert.assertTrue(closed.get());
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ public final class HttpProxyConfigurationActivator implements BundleActivator, M
|
||||
|
||||
private BundleContext context;
|
||||
|
||||
private final Map<String, ServiceRegistration> registeredConfigurations = new LinkedHashMap<String, ServiceRegistration>();
|
||||
private final Map<String, ServiceRegistration> registeredConfigurations = new LinkedHashMap<>();
|
||||
|
||||
private final List<CloseableHttpClient> trackedHttpClients = new LinkedList<CloseableHttpClient>();
|
||||
private final List<CloseableHttpClient> trackedHttpClients = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
@ -72,7 +72,7 @@ public void start(final BundleContext context) throws Exception {
|
||||
this.context = context;
|
||||
|
||||
// ensure we receive configurations for the proxy selector
|
||||
final Hashtable<String, Object> props = new Hashtable<String, Object>();
|
||||
final Hashtable<String, Object> props = new Hashtable<>();
|
||||
props.put(Constants.SERVICE_PID, getName());
|
||||
props.put(Constants.SERVICE_VENDOR, context.getBundle().getHeaders(Constants.BUNDLE_VENDOR));
|
||||
props.put(Constants.SERVICE_DESCRIPTION, SERVICE_FACTORY_NAME);
|
||||
|
@ -38,7 +38,7 @@
|
||||
final class PropertiesUtils {
|
||||
|
||||
private static final Map<Class<?>, PropertyConverter<?>> CONVERTERS_REGISTRY =
|
||||
new HashMap<Class<?>, PropertiesUtils.PropertyConverter<?>>();
|
||||
new HashMap<>();
|
||||
|
||||
static {
|
||||
register(new BooleanPropertyConverter(), boolean.class, Boolean.class);
|
||||
@ -147,7 +147,7 @@ public String[] to(final Object propValue) {
|
||||
if (propValue.getClass().isArray()) {
|
||||
// other array
|
||||
final Object[] valueArray = (Object[]) propValue;
|
||||
final List<String> values = new ArrayList<String>(valueArray.length);
|
||||
final List<String> values = new ArrayList<>(valueArray.length);
|
||||
for (final Object value : valueArray) {
|
||||
if (value != null) {
|
||||
values.add(value.toString());
|
||||
@ -160,7 +160,7 @@ public String[] to(final Object propValue) {
|
||||
if (propValue instanceof Collection<?>) {
|
||||
// collection
|
||||
final Collection<?> valueCollection = (Collection<?>) propValue;
|
||||
final List<String> valueList = new ArrayList<String>(valueCollection.size());
|
||||
final List<String> valueList = new ArrayList<>(valueCollection.size());
|
||||
for (final Object value : valueCollection) {
|
||||
if (value != null) {
|
||||
valueList.add(value.toString());
|
||||
|
@ -112,11 +112,8 @@ public AuthScheme create(final HttpContext context) {
|
||||
|
||||
final HttpHost target = start();
|
||||
final HttpGet httpGet = new HttpGet("/");
|
||||
final CloseableHttpResponse response = customClient.execute(target, httpGet);
|
||||
try {
|
||||
try (CloseableHttpResponse response = customClient.execute(target, httpGet)) {
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,23 +38,17 @@
|
||||
public class ClientAbortMethod {
|
||||
|
||||
public final static void main(String[] args) throws Exception {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
HttpGet httpget = new HttpGet("http://www.apache.org/");
|
||||
|
||||
System.out.println("Executing request " + httpget.getURI());
|
||||
CloseableHttpResponse response = httpclient.execute(httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
// Do not feel like reading the response body
|
||||
// Call abort on the request object
|
||||
httpget.abort();
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,23 +47,17 @@ public static void main(String[] args) throws Exception {
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope("localhost", 443),
|
||||
new UsernamePasswordCredentials("username", "password"));
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
HttpGet httpget = new HttpGet("http://localhost/");
|
||||
|
||||
System.out.println("Executing request " + httpget.getRequestLine());
|
||||
CloseableHttpResponse response = httpclient.execute(httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,8 +47,7 @@ public static void main(String[] args) throws Exception {
|
||||
System.out.println("File path not given");
|
||||
System.exit(1);
|
||||
}
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
HttpPost httppost = new HttpPost("http://localhost/");
|
||||
|
||||
File file = new File(args[0]);
|
||||
@ -65,16 +64,11 @@ public static void main(String[] args) throws Exception {
|
||||
httppost.setEntity(reqEntity);
|
||||
|
||||
System.out.println("Executing request: " + httppost.getRequestLine());
|
||||
CloseableHttpResponse response = httpclient.execute(httppost);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httppost)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -212,24 +212,23 @@ public InetAddress[] resolve(final String host) throws UnknownHostException {
|
||||
.build();
|
||||
|
||||
// Create an HttpClient with the given custom dependencies and configuration.
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setConnectionManager(connManager)
|
||||
.setDefaultCookieStore(cookieStore)
|
||||
.setDefaultCredentialsProvider(credentialsProvider)
|
||||
.setProxy(new HttpHost("myproxy", 8080))
|
||||
.setDefaultRequestConfig(defaultRequestConfig)
|
||||
.build();
|
||||
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setConnectionManager(connManager)
|
||||
.setDefaultCookieStore(cookieStore)
|
||||
.setDefaultCredentialsProvider(credentialsProvider)
|
||||
.setProxy(new HttpHost("myproxy", 8080))
|
||||
.setDefaultRequestConfig(defaultRequestConfig)
|
||||
.build()) {
|
||||
HttpGet httpget = new HttpGet("http://www.apache.org/");
|
||||
// Request configuration can be overridden at the request level.
|
||||
// They will take precedence over the one set at the client level.
|
||||
RequestConfig requestConfig = RequestConfig.copy(defaultRequestConfig)
|
||||
.setSocketTimeout(5000)
|
||||
.setConnectTimeout(5000)
|
||||
.setConnectionRequestTimeout(5000)
|
||||
.setProxy(new HttpHost("myotherproxy", 8080))
|
||||
.build();
|
||||
.setSocketTimeout(5000)
|
||||
.setConnectTimeout(5000)
|
||||
.setConnectionRequestTimeout(5000)
|
||||
.setProxy(new HttpHost("myotherproxy", 8080))
|
||||
.build();
|
||||
httpget.setConfig(requestConfig);
|
||||
|
||||
// Execution context can be customized locally.
|
||||
@ -240,8 +239,7 @@ public InetAddress[] resolve(final String host) throws UnknownHostException {
|
||||
context.setCredentialsProvider(credentialsProvider);
|
||||
|
||||
System.out.println("executing request " + httpget.getURI());
|
||||
CloseableHttpResponse response = httpclient.execute(httpget, context);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget, context)) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
System.out.println("----------------------------------------");
|
||||
@ -270,11 +268,7 @@ public InetAddress[] resolve(final String host) throws UnknownHostException {
|
||||
// User security token
|
||||
context.getUserToken();
|
||||
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,13 +43,11 @@
|
||||
public class ClientConnectionRelease {
|
||||
|
||||
public final static void main(String[] args) throws Exception {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
HttpGet httpget = new HttpGet("http://localhost/");
|
||||
|
||||
System.out.println("Executing request " + httpget.getRequestLine());
|
||||
CloseableHttpResponse response = httpclient.execute(httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
|
||||
@ -59,24 +57,16 @@ public final static void main(String[] args) throws Exception {
|
||||
// If the response does not enclose an entity, there is no need
|
||||
// to bother about connection release
|
||||
if (entity != null) {
|
||||
InputStream instream = entity.getContent();
|
||||
try {
|
||||
try (InputStream instream = entity.getContent()) {
|
||||
instream.read();
|
||||
// do something useful with the response
|
||||
} catch (IOException ex) {
|
||||
// In case of an IOException the connection will be released
|
||||
// back to the connection manager automatically
|
||||
throw ex;
|
||||
} finally {
|
||||
// Closing the input stream will trigger connection release
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,7 @@
|
||||
public class ClientCustomContext {
|
||||
|
||||
public final static void main(String[] args) throws Exception {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
// Create a local instance of cookie store
|
||||
CookieStore cookieStore = new BasicCookieStore();
|
||||
|
||||
@ -60,8 +59,7 @@ public final static void main(String[] args) throws Exception {
|
||||
System.out.println("Executing request " + httpget.getRequestLine());
|
||||
|
||||
// Pass local context as a parameter
|
||||
CloseableHttpResponse response = httpclient.execute(httpget, localContext);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget, localContext)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
List<Cookie> cookies = cookieStore.getCookies();
|
||||
@ -69,11 +67,7 @@ public final static void main(String[] args) throws Exception {
|
||||
System.out.println("Local cookie: " + cookies.get(i));
|
||||
}
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,28 +67,22 @@ public final static void main(String[] args) throws Exception {
|
||||
.register(CookieSpecs.STANDARD_STRICT, cookieSpecProvider)
|
||||
.build();
|
||||
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setSSLHostnameVerifier(hostnameVerifier)
|
||||
.setDefaultCookieSpecRegistry(cookieSpecRegistry)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
|
||||
HttpGet httpget = new HttpGet("https://remotehost/");
|
||||
|
||||
System.out.println("executing request " + httpget.getRequestLine());
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(entity);
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,27 +58,21 @@ public final static void main(String[] args) throws Exception {
|
||||
new String[] { "TLSv1" },
|
||||
null,
|
||||
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setSSLSocketFactory(sslsf)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
|
||||
HttpGet httpget = new HttpGet("https://localhost/");
|
||||
|
||||
System.out.println("executing request " + httpget.getRequestLine());
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(entity);
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,17 +45,16 @@ public class ClientEvictExpiredConnections {
|
||||
public static void main(String[] args) throws Exception {
|
||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||
cm.setMaxTotal(100);
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setConnectionManager(cm)
|
||||
.evictExpiredConnections()
|
||||
.evictIdleConnections(5L, TimeUnit.SECONDS)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
// create an array of URIs to perform GETs on
|
||||
String[] urisToGet = {
|
||||
"http://hc.apache.org/",
|
||||
"http://hc.apache.org/httpcomponents-core-ga/",
|
||||
"http://hc.apache.org/httpcomponents-client-ga/",
|
||||
"http://hc.apache.org/",
|
||||
"http://hc.apache.org/httpcomponents-core-ga/",
|
||||
"http://hc.apache.org/httpcomponents-client-ga/",
|
||||
};
|
||||
|
||||
for (int i = 0; i < urisToGet.length; i++) {
|
||||
@ -64,13 +63,10 @@ public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("Executing request " + requestURI);
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(request);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(request)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,8 +79,6 @@ public static void main(String[] args) throws Exception {
|
||||
PoolStats stats2 = cm.getTotalStats();
|
||||
System.out.println("Connections kept alive: " + stats2.getAvailable());
|
||||
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,8 +43,7 @@
|
||||
public class ClientExecuteProxy {
|
||||
|
||||
public static void main(String[] args)throws Exception {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
HttpHost target = new HttpHost("localhost", 443, "https");
|
||||
HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");
|
||||
|
||||
@ -56,16 +55,11 @@ public static void main(String[] args)throws Exception {
|
||||
|
||||
System.out.println("Executing request " + request.getRequestLine() + " to " + target + " via " + proxy);
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(target, request);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(target, request)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,10 +59,9 @@ public static void main(String[] args)throws Exception {
|
||||
.register("http", new MyConnectionSocketFactory())
|
||||
.build();
|
||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(reg);
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setConnectionManager(cm)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
InetSocketAddress socksaddr = new InetSocketAddress("mysockshost", 1234);
|
||||
HttpClientContext context = HttpClientContext.create();
|
||||
context.setAttribute("socks.address", socksaddr);
|
||||
@ -71,16 +70,11 @@ public static void main(String[] args)throws Exception {
|
||||
HttpGet request = new HttpGet("/");
|
||||
|
||||
System.out.println("Executing request " + request + " to " + target + " via SOCKS proxy " + socksaddr);
|
||||
CloseableHttpResponse response = httpclient.execute(target, request, context);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(target, request, context)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -48,13 +48,11 @@ public class ClientFormLogin {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
BasicCookieStore cookieStore = new BasicCookieStore();
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCookieStore(cookieStore)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
HttpGet httpget = new HttpGet("https://someportal/");
|
||||
CloseableHttpResponse response1 = httpclient.execute(httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response1 = httpclient.execute(httpget)) {
|
||||
HttpEntity entity = response1.getEntity();
|
||||
|
||||
System.out.println("Login form get: " + response1.getStatusLine());
|
||||
@ -69,8 +67,6 @@ public static void main(String[] args) throws Exception {
|
||||
System.out.println("- " + cookies.get(i).toString());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
response1.close();
|
||||
}
|
||||
|
||||
HttpUriRequest login = RequestBuilder.post()
|
||||
@ -78,8 +74,7 @@ public static void main(String[] args) throws Exception {
|
||||
.addParameter("IDToken1", "username")
|
||||
.addParameter("IDToken2", "password")
|
||||
.build();
|
||||
CloseableHttpResponse response2 = httpclient.execute(login);
|
||||
try {
|
||||
try (CloseableHttpResponse response2 = httpclient.execute(login)) {
|
||||
HttpEntity entity = response2.getEntity();
|
||||
|
||||
System.out.println("Login form get: " + response2.getStatusLine());
|
||||
@ -94,11 +89,7 @@ public static void main(String[] args) throws Exception {
|
||||
System.out.println("- " + cookies.get(i).toString());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
response2.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,15 +49,14 @@ public static void main(String[] args) throws Exception {
|
||||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
|
||||
cm.setMaxTotal(100);
|
||||
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setConnectionManager(cm)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
// create an array of URIs to perform GETs on
|
||||
String[] urisToGet = {
|
||||
"http://hc.apache.org/",
|
||||
"http://hc.apache.org/httpcomponents-core-ga/",
|
||||
"http://hc.apache.org/httpcomponents-client-ga/",
|
||||
"http://hc.apache.org/",
|
||||
"http://hc.apache.org/httpcomponents-core-ga/",
|
||||
"http://hc.apache.org/httpcomponents-client-ga/",
|
||||
};
|
||||
|
||||
// create a thread for each URI
|
||||
@ -77,8 +76,6 @@ public static void main(String[] args) throws Exception {
|
||||
threads[j].join();
|
||||
}
|
||||
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,8 +103,7 @@ public GetThread(CloseableHttpClient httpClient, HttpGet httpget, int id) {
|
||||
public void run() {
|
||||
try {
|
||||
System.out.println(id + " - about to get something from " + httpget.getURI());
|
||||
CloseableHttpResponse response = httpClient.execute(httpget, context);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpget, context)) {
|
||||
System.out.println(id + " - get executed");
|
||||
// get the response body as an array of bytes
|
||||
HttpEntity entity = response.getEntity();
|
||||
@ -115,8 +111,6 @@ public void run() {
|
||||
byte[] bytes = EntityUtils.toByteArray(entity);
|
||||
System.out.println(id + " - " + bytes.length + " bytes read");
|
||||
}
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(id + " - error: " + e);
|
||||
|
@ -57,9 +57,8 @@ public static void main(String[] args) throws Exception {
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope(target.getHostName(), target.getPort()),
|
||||
new UsernamePasswordCredentials("username", "password"));
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider).build();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider).build()) {
|
||||
|
||||
// Create AuthCache instance
|
||||
AuthCache authCache = new BasicAuthCache();
|
||||
@ -76,17 +75,12 @@ public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("Executing request " + httpget.getRequestLine() + " to target " + target);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
CloseableHttpResponse response = httpclient.execute(target, httpget, localContext);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,10 +58,9 @@ public static void main(String[] args) throws Exception {
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope(target.getHostName(), target.getPort()),
|
||||
new UsernamePasswordCredentials("username", "password"));
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider)
|
||||
.build();
|
||||
try {
|
||||
.build()) {
|
||||
|
||||
// Create AuthCache instance
|
||||
AuthCache authCache = new BasicAuthCache();
|
||||
@ -82,17 +81,12 @@ public static void main(String[] args) throws Exception {
|
||||
|
||||
System.out.println("Executing request " + httpget.getRequestLine() + " to target " + target);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
CloseableHttpResponse response = httpclient.execute(target, httpget, localContext);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(target, httpget, localContext)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,30 +49,24 @@ public static void main(String[] args) throws Exception {
|
||||
credsProvider.setCredentials(
|
||||
new AuthScope("localhost", 8080),
|
||||
new UsernamePasswordCredentials("username", "password"));
|
||||
CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider).build();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.custom()
|
||||
.setDefaultCredentialsProvider(credsProvider).build()) {
|
||||
HttpHost target = new HttpHost("www.verisign.com", 443, "https");
|
||||
HttpHost proxy = new HttpHost("localhost", 8080);
|
||||
|
||||
RequestConfig config = RequestConfig.custom()
|
||||
.setProxy(proxy)
|
||||
.build();
|
||||
.setProxy(proxy)
|
||||
.build();
|
||||
HttpGet httpget = new HttpGet("/");
|
||||
httpget.setConfig(config);
|
||||
|
||||
System.out.println("Executing request " + httpget.getRequestLine() + " to " + target + " via " + proxy);
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(target, httpget);
|
||||
try {
|
||||
try (CloseableHttpResponse response = httpclient.execute(target, httpget)) {
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(response.getStatusLine());
|
||||
EntityUtils.consume(response.getEntity());
|
||||
} finally {
|
||||
response.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,9 +51,8 @@ public static void main(String[] args) throws Exception {
|
||||
.setMaxConnPerRoute(5)
|
||||
.setMaxConnTotal(5).build();
|
||||
ExecutorService execService = Executors.newFixedThreadPool(5);
|
||||
FutureRequestExecutionService requestExecService = new FutureRequestExecutionService(
|
||||
httpclient, execService);
|
||||
try {
|
||||
try (FutureRequestExecutionService requestExecService = new FutureRequestExecutionService(
|
||||
httpclient, execService)) {
|
||||
// Because things are asynchronous, you must provide a ResponseHandler
|
||||
ResponseHandler<Boolean> handler = new ResponseHandler<Boolean>() {
|
||||
@Override
|
||||
@ -68,7 +67,7 @@ public Boolean handleResponse(HttpResponse response) throws ClientProtocolExcept
|
||||
HttpRequestFutureTask<Boolean> futureTask1 = requestExecService.execute(request1,
|
||||
HttpClientContext.create(), handler);
|
||||
Boolean wasItOk1 = futureTask1.get();
|
||||
System.out.println("It was ok? " + wasItOk1);
|
||||
System.out.println("It was ok? " + wasItOk1);
|
||||
|
||||
// Cancel a request
|
||||
try {
|
||||
@ -87,7 +86,7 @@ public Boolean handleResponse(HttpResponse response) throws ClientProtocolExcept
|
||||
HttpRequestFutureTask<Boolean> futureTask3 = requestExecService.execute(request3,
|
||||
HttpClientContext.create(), handler);
|
||||
Boolean wasItOk3 = futureTask3.get(10, TimeUnit.SECONDS);
|
||||
System.out.println("It was ok? " + wasItOk3);
|
||||
System.out.println("It was ok? " + wasItOk3);
|
||||
|
||||
FutureCallback<Boolean> callback = new FutureCallback<Boolean>() {
|
||||
@Override
|
||||
@ -113,9 +112,7 @@ public void cancelled() {
|
||||
HttpRequestFutureTask<Boolean> futureTask4 = requestExecService.execute(request4,
|
||||
HttpClientContext.create(), handler, callback);
|
||||
Boolean wasItOk4 = futureTask4.get(10, TimeUnit.SECONDS);
|
||||
System.out.println("It was ok? " + wasItOk4);
|
||||
} finally {
|
||||
requestExecService.close();
|
||||
System.out.println("It was ok? " + wasItOk4);
|
||||
}
|
||||
}
|
||||
}
|
@ -45,8 +45,7 @@
|
||||
public class ClientWithResponseHandler {
|
||||
|
||||
public final static void main(String[] args) throws Exception {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
HttpGet httpget = new HttpGet("http://localhost/");
|
||||
|
||||
System.out.println("Executing request " + httpget.getRequestLine());
|
||||
@ -70,8 +69,6 @@ public String handleResponse(
|
||||
String responseBody = httpclient.execute(httpget, responseHandler);
|
||||
System.out.println("----------------------------------------");
|
||||
System.out.println(responseBody);
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,7 @@ public final static void main(String[] args) throws Exception {
|
||||
HttpHost target = new HttpHost("www.yahoo.com", 80);
|
||||
HttpHost proxy = new HttpHost("localhost", 8888);
|
||||
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd");
|
||||
Socket socket = proxyClient.tunnel(proxy, target, credentials);
|
||||
try {
|
||||
try (Socket socket = proxyClient.tunnel(proxy, target, credentials)) {
|
||||
Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET);
|
||||
out.write("GET / HTTP/1.1\r\n");
|
||||
out.write("Host: " + target.toHostString() + "\r\n");
|
||||
@ -64,8 +63,6 @@ public final static void main(String[] args) throws Exception {
|
||||
while ((line = in.readLine()) != null) {
|
||||
System.out.println(line);
|
||||
}
|
||||
} finally {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,10 +43,8 @@
|
||||
public class QuickStart {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
CloseableHttpClient httpclient = HttpClients.createDefault();
|
||||
try {
|
||||
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
|
||||
HttpGet httpGet = new HttpGet("http://targethost/homepage");
|
||||
CloseableHttpResponse response1 = httpclient.execute(httpGet);
|
||||
// The underlying HTTP connection is still held by the response object
|
||||
// to allow the response content to be streamed directly from the network socket.
|
||||
// In order to ensure correct deallocation of system resources
|
||||
@ -54,34 +52,27 @@ public static void main(String[] args) throws Exception {
|
||||
// Please note that if response content is not fully consumed the underlying
|
||||
// connection cannot be safely re-used and will be shut down and discarded
|
||||
// by the connection manager.
|
||||
try {
|
||||
try (CloseableHttpResponse response1 = httpclient.execute(httpGet)) {
|
||||
System.out.println(response1.getStatusLine());
|
||||
HttpEntity entity1 = response1.getEntity();
|
||||
// do something useful with the response body
|
||||
// and ensure it is fully consumed
|
||||
EntityUtils.consume(entity1);
|
||||
} finally {
|
||||
response1.close();
|
||||
}
|
||||
|
||||
HttpPost httpPost = new HttpPost("http://targethost/login");
|
||||
List <NameValuePair> nvps = new ArrayList <NameValuePair>();
|
||||
List<NameValuePair> nvps = new ArrayList<>();
|
||||
nvps.add(new BasicNameValuePair("username", "vip"));
|
||||
nvps.add(new BasicNameValuePair("password", "secret"));
|
||||
httpPost.setEntity(new UrlEncodedFormEntity(nvps));
|
||||
CloseableHttpResponse response2 = httpclient.execute(httpPost);
|
||||
|
||||
try {
|
||||
try (CloseableHttpResponse response2 = httpclient.execute(httpPost)) {
|
||||
System.out.println(response2.getStatusLine());
|
||||
HttpEntity entity2 = response2.getEntity();
|
||||
// do something useful with the response body
|
||||
// and ensure it is fully consumed
|
||||
EntityUtils.consume(entity2);
|
||||
} finally {
|
||||
response2.close();
|
||||
}
|
||||
} finally {
|
||||
httpclient.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,15 +87,12 @@ public InputStream getContent() throws IOException {
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = getContent();
|
||||
try {
|
||||
try (InputStream instream = getContent()) {
|
||||
final byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int l;
|
||||
while ((l = instream.read(buffer)) != -1) {
|
||||
outstream.write(buffer, 0, l);
|
||||
}
|
||||
} finally {
|
||||
instream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ public abstract class AbstractExecutionAwareRequest extends AbstractHttpMessage
|
||||
protected AbstractExecutionAwareRequest() {
|
||||
super();
|
||||
this.aborted = new AtomicBoolean(false);
|
||||
this.cancellableRef = new AtomicReference<Cancellable>(null);
|
||||
this.cancellableRef = new AtomicReference<>(null);
|
||||
}
|
||||
|
||||
public void abort() {
|
||||
|
@ -86,7 +86,7 @@ public Set<String> getAllowedMethods(final HttpResponse response) {
|
||||
Args.notNull(response, "HTTP response");
|
||||
|
||||
final HeaderIterator it = response.headerIterator("Allow");
|
||||
final Set<String> methods = new HashSet<String>();
|
||||
final Set<String> methods = new HashSet<>();
|
||||
while (it.hasNext()) {
|
||||
final Header header = it.nextHeader();
|
||||
final HeaderElement[] elements = header.getElements();
|
||||
|
@ -440,14 +440,14 @@ public RequestBuilder setEntity(final HttpEntity entity) {
|
||||
}
|
||||
|
||||
public List<NameValuePair> getParameters() {
|
||||
return parameters != null ? new ArrayList<NameValuePair>(parameters) :
|
||||
return parameters != null ? new ArrayList<>(parameters) :
|
||||
new ArrayList<NameValuePair>();
|
||||
}
|
||||
|
||||
public RequestBuilder addParameter(final NameValuePair nvp) {
|
||||
Args.notNull(nvp, "Name value pair");
|
||||
if (parameters == null) {
|
||||
parameters = new LinkedList<NameValuePair>();
|
||||
parameters = new LinkedList<>();
|
||||
}
|
||||
parameters.add(nvp);
|
||||
return this;
|
||||
|
@ -157,7 +157,7 @@ public void process(final HttpRequest request, final HttpContext context)
|
||||
// Get all cookies available in the HTTP state
|
||||
final List<Cookie> cookies = cookieStore.getCookies();
|
||||
// Find cookies matching the given origin
|
||||
final List<Cookie> matchedCookies = new ArrayList<Cookie>();
|
||||
final List<Cookie> matchedCookies = new ArrayList<>();
|
||||
final Date now = new Date();
|
||||
boolean expired = false;
|
||||
for (final Cookie cookie : cookies) {
|
||||
|
@ -226,9 +226,9 @@ public static SimpleDateFormat formatFor(final String pattern) {
|
||||
final SoftReference<Map<String, SimpleDateFormat>> ref = THREADLOCAL_FORMATS.get();
|
||||
Map<String, SimpleDateFormat> formats = ref.get();
|
||||
if (formats == null) {
|
||||
formats = new HashMap<String, SimpleDateFormat>();
|
||||
formats = new HashMap<>();
|
||||
THREADLOCAL_FORMATS.set(
|
||||
new SoftReference<Map<String, SimpleDateFormat>>(formats));
|
||||
new SoftReference<>(formats));
|
||||
}
|
||||
|
||||
SimpleDateFormat format = formats.get(pattern);
|
||||
|
@ -280,7 +280,7 @@ public URIBuilder removeQuery() {
|
||||
*/
|
||||
public URIBuilder setParameters(final List <NameValuePair> nvps) {
|
||||
if (this.queryParams == null) {
|
||||
this.queryParams = new ArrayList<NameValuePair>();
|
||||
this.queryParams = new ArrayList<>();
|
||||
} else {
|
||||
this.queryParams.clear();
|
||||
}
|
||||
@ -303,7 +303,7 @@ public URIBuilder setParameters(final List <NameValuePair> nvps) {
|
||||
*/
|
||||
public URIBuilder addParameters(final List <NameValuePair> nvps) {
|
||||
if (this.queryParams == null) {
|
||||
this.queryParams = new ArrayList<NameValuePair>();
|
||||
this.queryParams = new ArrayList<>();
|
||||
}
|
||||
this.queryParams.addAll(nvps);
|
||||
this.encodedQuery = null;
|
||||
@ -324,7 +324,7 @@ public URIBuilder addParameters(final List <NameValuePair> nvps) {
|
||||
*/
|
||||
public URIBuilder setParameters(final NameValuePair... nvps) {
|
||||
if (this.queryParams == null) {
|
||||
this.queryParams = new ArrayList<NameValuePair>();
|
||||
this.queryParams = new ArrayList<>();
|
||||
} else {
|
||||
this.queryParams.clear();
|
||||
}
|
||||
@ -347,7 +347,7 @@ public URIBuilder setParameters(final NameValuePair... nvps) {
|
||||
*/
|
||||
public URIBuilder addParameter(final String param, final String value) {
|
||||
if (this.queryParams == null) {
|
||||
this.queryParams = new ArrayList<NameValuePair>();
|
||||
this.queryParams = new ArrayList<>();
|
||||
}
|
||||
this.queryParams.add(new BasicNameValuePair(param, value));
|
||||
this.encodedQuery = null;
|
||||
@ -366,7 +366,7 @@ public URIBuilder addParameter(final String param, final String value) {
|
||||
*/
|
||||
public URIBuilder setParameter(final String param, final String value) {
|
||||
if (this.queryParams == null) {
|
||||
this.queryParams = new ArrayList<NameValuePair>();
|
||||
this.queryParams = new ArrayList<>();
|
||||
}
|
||||
if (!this.queryParams.isEmpty()) {
|
||||
for (final Iterator<NameValuePair> it = this.queryParams.iterator(); it.hasNext(); ) {
|
||||
@ -459,9 +459,9 @@ public String getPath() {
|
||||
|
||||
public List<NameValuePair> getQueryParams() {
|
||||
if (this.queryParams != null) {
|
||||
return new ArrayList<NameValuePair>(this.queryParams);
|
||||
return new ArrayList<>(this.queryParams);
|
||||
} else {
|
||||
return new ArrayList<NameValuePair>();
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ static URI normalizeSyntax(final URI uri) throws URISyntaxException {
|
||||
final String path = builder.getPath();
|
||||
if (path != null && !path.equals("/")) {
|
||||
final String[] inputSegments = path.split("/");
|
||||
final Stack<String> outputSegments = new Stack<String>();
|
||||
final Stack<String> outputSegments = new Stack<>();
|
||||
for (final String inputSegment : inputSegments) {
|
||||
if ((inputSegment.isEmpty()) || (".".equals(inputSegment))) {
|
||||
// Do nothing
|
||||
|
@ -218,7 +218,7 @@ public static List<NameValuePair> parse(
|
||||
delimSet.set(separator);
|
||||
}
|
||||
final ParserCursor cursor = new ParserCursor(0, buf.length());
|
||||
final List<NameValuePair> list = new ArrayList<NameValuePair>();
|
||||
final List<NameValuePair> list = new ArrayList<>();
|
||||
while (!cursor.atEnd()) {
|
||||
delimSet.set('=');
|
||||
final String name = tokenParser.parseToken(buf, cursor, delimSet);
|
||||
|
@ -74,7 +74,7 @@ private HttpRoute(final HttpHost target, final InetAddress local, final List<Htt
|
||||
this.targetHost = normalize(target);
|
||||
this.localAddress = local;
|
||||
if (proxies != null && !proxies.isEmpty()) {
|
||||
this.proxyChain = new ArrayList<HttpHost>(proxies);
|
||||
this.proxyChain = new ArrayList<>(proxies);
|
||||
} else {
|
||||
this.proxyChain = null;
|
||||
}
|
||||
|
@ -247,8 +247,7 @@ static String extractCN(final String subjectPrincipal) throws SSLException {
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
} catch (NoSuchElementException ignore) {
|
||||
} catch (NamingException ignore) {
|
||||
} catch (NoSuchElementException | NamingException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -272,7 +271,7 @@ static List<String> extractSubjectAlts(final X509Certificate cert, final int sub
|
||||
if (type == subjectType) {
|
||||
final String s = (String) list.get(1);
|
||||
if (subjectAltList == null) {
|
||||
subjectAltList = new ArrayList<String>();
|
||||
subjectAltList = new ArrayList<>();
|
||||
}
|
||||
subjectAltList.add(s);
|
||||
}
|
||||
|
@ -308,7 +308,7 @@ public Socket createLayeredSocket(
|
||||
} else {
|
||||
// If supported protocols are not explicitly set, remove all SSL protocol versions
|
||||
final String[] allProtocols = sslsock.getEnabledProtocols();
|
||||
final List<String> enabledProtocols = new ArrayList<String>(allProtocols.length);
|
||||
final List<String> enabledProtocols = new ArrayList<>(allProtocols.length);
|
||||
for (String protocol: allProtocols) {
|
||||
if (!protocol.startsWith("SSL")) {
|
||||
enabledProtocols.add(protocol);
|
||||
@ -371,7 +371,7 @@ private void verifyHostname(final SSLSocket sslsock, final String hostname) thro
|
||||
this.log.debug(" peer principal: " + peer.toString());
|
||||
final Collection<List<?>> altNames1 = x509.getSubjectAlternativeNames();
|
||||
if (altNames1 != null) {
|
||||
final List<String> altNames = new ArrayList<String>();
|
||||
final List<String> altNames = new ArrayList<>();
|
||||
for (final List<?> aC : altNames1) {
|
||||
if (!aC.isEmpty()) {
|
||||
altNames.add((String) aC.get(1));
|
||||
@ -384,7 +384,7 @@ private void verifyHostname(final SSLSocket sslsock, final String hostname) thro
|
||||
this.log.debug(" issuer principal: " + issuer.toString());
|
||||
final Collection<List<?>> altNames2 = x509.getIssuerAlternativeNames();
|
||||
if (altNames2 != null) {
|
||||
final List<String> altNames = new ArrayList<String>();
|
||||
final List<String> altNames = new ArrayList<>();
|
||||
for (final List<?> aC : altNames2) {
|
||||
if (!aC.isEmpty()) {
|
||||
altNames.add((String) aC.get(1));
|
||||
|
@ -56,8 +56,8 @@ public PublicSuffixListParser() {
|
||||
* @throws java.io.IOException on error while reading from list
|
||||
*/
|
||||
public PublicSuffixList parse(final Reader reader) throws IOException {
|
||||
final List<String> rules = new ArrayList<String>();
|
||||
final List<String> exceptions = new ArrayList<String>();
|
||||
final List<String> rules = new ArrayList<>();
|
||||
final List<String> exceptions = new ArrayList<>();
|
||||
final BufferedReader r = new BufferedReader(reader);
|
||||
|
||||
String line;
|
||||
@ -98,7 +98,7 @@ public PublicSuffixList parse(final Reader reader) throws IOException {
|
||||
* @since 4.5
|
||||
*/
|
||||
public List<PublicSuffixList> parseByType(final Reader reader) throws IOException {
|
||||
final List<PublicSuffixList> result = new ArrayList<PublicSuffixList>(2);
|
||||
final List<PublicSuffixList> result = new ArrayList<>(2);
|
||||
|
||||
final BufferedReader r = new BufferedReader(reader);
|
||||
final StringBuilder sb = new StringBuilder(256);
|
||||
@ -147,12 +147,12 @@ public List<PublicSuffixList> parseByType(final Reader reader) throws IOExceptio
|
||||
|
||||
if (isException) {
|
||||
if (exceptions == null) {
|
||||
exceptions = new ArrayList<String>();
|
||||
exceptions = new ArrayList<>();
|
||||
}
|
||||
exceptions.add(line);
|
||||
} else {
|
||||
if (rules == null) {
|
||||
rules = new ArrayList<String>();
|
||||
rules = new ArrayList<>();
|
||||
}
|
||||
rules.add(line);
|
||||
}
|
||||
|
@ -63,11 +63,11 @@ public PublicSuffixMatcher(
|
||||
final DomainType domainType, final Collection<String> rules, final Collection<String> exceptions) {
|
||||
Args.notNull(domainType, "Domain type");
|
||||
Args.notNull(rules, "Domain suffix rules");
|
||||
this.rules = new ConcurrentHashMap<String, DomainType>(rules.size());
|
||||
this.rules = new ConcurrentHashMap<>(rules.size());
|
||||
for (String rule: rules) {
|
||||
this.rules.put(rule, domainType);
|
||||
}
|
||||
this.exceptions = new ConcurrentHashMap<String, DomainType>();
|
||||
this.exceptions = new ConcurrentHashMap<>();
|
||||
if (exceptions != null) {
|
||||
for (String exception: exceptions) {
|
||||
this.exceptions.put(exception, domainType);
|
||||
@ -80,8 +80,8 @@ public PublicSuffixMatcher(
|
||||
*/
|
||||
public PublicSuffixMatcher(final Collection<PublicSuffixList> lists) {
|
||||
Args.notNull(lists, "Domain suffix lists");
|
||||
this.rules = new ConcurrentHashMap<String, DomainType>();
|
||||
this.exceptions = new ConcurrentHashMap<String, DomainType>();
|
||||
this.rules = new ConcurrentHashMap<>();
|
||||
this.exceptions = new ConcurrentHashMap<>();
|
||||
for (PublicSuffixList list: lists) {
|
||||
final DomainType domainType = list.getType();
|
||||
final List<String> rules = list.getRules();
|
||||
|
@ -57,21 +57,15 @@ private static PublicSuffixMatcher load(final InputStream in) throws IOException
|
||||
|
||||
public static PublicSuffixMatcher load(final URL url) throws IOException {
|
||||
Args.notNull(url, "URL");
|
||||
final InputStream in = url.openStream();
|
||||
try {
|
||||
try (InputStream in = url.openStream()) {
|
||||
return load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static PublicSuffixMatcher load(final File file) throws IOException {
|
||||
Args.notNull(file, "File");
|
||||
final InputStream in = new FileInputStream(file);
|
||||
try {
|
||||
try (InputStream in = new FileInputStream(file)) {
|
||||
return load(in);
|
||||
} finally {
|
||||
in.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,7 +240,7 @@ private Header createDigestHeader(
|
||||
algorithm = "MD5";
|
||||
}
|
||||
|
||||
final Set<String> qopset = new HashSet<String>(8);
|
||||
final Set<String> qopset = new HashSet<>(8);
|
||||
int qop = QOP_UNKNOWN;
|
||||
final String qoplist = getParameter("qop");
|
||||
if (qoplist != null) {
|
||||
@ -384,7 +384,7 @@ private Header createDigestHeader(
|
||||
}
|
||||
buffer.append(": Digest ");
|
||||
|
||||
final List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(20);
|
||||
final List<BasicNameValuePair> params = new ArrayList<>(20);
|
||||
params.add(new BasicNameValuePair("username", uname));
|
||||
params.add(new BasicNameValuePair("realm", realm));
|
||||
params.add(new BasicNameValuePair("nonce", nonce));
|
||||
|
@ -68,7 +68,7 @@ public abstract class RFC2617Scheme extends AuthSchemeBase implements Serializab
|
||||
*/
|
||||
public RFC2617Scheme(final Charset credentialsCharset) {
|
||||
super();
|
||||
this.params = new HashMap<String, String>();
|
||||
this.params = new HashMap<>();
|
||||
this.credentialsCharset = credentialsCharset != null ? credentialsCharset : Consts.ASCII;
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ public AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute) {
|
||||
AIMDBackoffManager(final ConnPoolControl<HttpRoute> connPerRoute, final Clock clock) {
|
||||
this.clock = clock;
|
||||
this.connPerRoute = connPerRoute;
|
||||
this.lastRouteProbes = new HashMap<HttpRoute,Long>();
|
||||
this.lastRouteBackoffs = new HashMap<HttpRoute,Long>();
|
||||
this.lastRouteProbes = new HashMap<>();
|
||||
this.lastRouteBackoffs = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,7 +110,7 @@ public Map<String, Header> getChallenges(
|
||||
final HttpContext context) throws MalformedChallengeException {
|
||||
Args.notNull(response, "HTTP response");
|
||||
final Header[] headers = response.getHeaders(this.headerName);
|
||||
final Map<String, Header> map = new HashMap<String, Header>(headers.length);
|
||||
final Map<String, Header> map = new HashMap<>(headers.length);
|
||||
for (final Header header : headers) {
|
||||
final CharArrayBuffer buffer;
|
||||
int pos;
|
||||
@ -154,7 +154,7 @@ public Queue<AuthOption> select(
|
||||
Args.notNull(context, "HTTP context");
|
||||
final HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
|
||||
final Queue<AuthOption> options = new LinkedList<AuthOption>();
|
||||
final Queue<AuthOption> options = new LinkedList<>();
|
||||
final Lookup<AuthSchemeProvider> registry = clientContext.getAuthSchemeRegistry();
|
||||
if (registry == null) {
|
||||
this.log.debug("Auth scheme registry not set in the context");
|
||||
|
@ -71,7 +71,7 @@ public class BasicAuthCache implements AuthCache {
|
||||
*/
|
||||
public BasicAuthCache(final SchemePortResolver schemePortResolver) {
|
||||
super();
|
||||
this.map = new ConcurrentHashMap<HttpHost, byte[]>();
|
||||
this.map = new ConcurrentHashMap<>();
|
||||
this.schemePortResolver = schemePortResolver != null ? schemePortResolver :
|
||||
DefaultSchemePortResolver.INSTANCE;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ public class BasicCookieStore implements CookieStore, Serializable {
|
||||
|
||||
public BasicCookieStore() {
|
||||
super();
|
||||
this.cookies = new TreeSet<Cookie>(new CookieIdentityComparator());
|
||||
this.cookies = new TreeSet<>(new CookieIdentityComparator());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -106,7 +106,7 @@ public synchronized void addCookies(final Cookie[] cookies) {
|
||||
@Override
|
||||
public synchronized List<Cookie> getCookies() {
|
||||
//create defensive copy so it won't be concurrently modified
|
||||
return new ArrayList<Cookie>(cookies);
|
||||
return new ArrayList<>(cookies);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ public class BasicCredentialsProvider implements CredentialsProvider {
|
||||
*/
|
||||
public BasicCredentialsProvider() {
|
||||
super();
|
||||
this.credMap = new ConcurrentHashMap<AuthScope, Credentials>();
|
||||
this.credMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -80,7 +80,7 @@ protected DefaultHttpRequestRetryHandler(
|
||||
super();
|
||||
this.retryCount = retryCount;
|
||||
this.requestSentRetryEnabled = requestSentRetryEnabled;
|
||||
this.nonRetriableClasses = new HashSet<Class<? extends IOException>>();
|
||||
this.nonRetriableClasses = new HashSet<>();
|
||||
for (final Class<? extends IOException> clazz: clazzes) {
|
||||
this.nonRetriableClasses.add(clazz);
|
||||
}
|
||||
|
@ -113,10 +113,10 @@ public <T> HttpRequestFutureTask<T> execute(
|
||||
throw new IllegalStateException("Close has been called on this httpclient instance.");
|
||||
}
|
||||
metrics.getScheduledConnections().incrementAndGet();
|
||||
final HttpRequestTaskCallable<T> callable = new HttpRequestTaskCallable<T>(
|
||||
httpclient, request, context, responseHandler, callback, metrics);
|
||||
final HttpRequestFutureTask<T> httpRequestFutureTask = new HttpRequestFutureTask<T>(
|
||||
request, callable);
|
||||
final HttpRequestTaskCallable<T> callable = new HttpRequestTaskCallable<>(
|
||||
httpclient, request, context, responseHandler, callback, metrics);
|
||||
final HttpRequestFutureTask<T> httpRequestFutureTask = new HttpRequestFutureTask<>(
|
||||
request, callable);
|
||||
executorService.execute(httpRequestFutureTask);
|
||||
|
||||
return httpRequestFutureTask;
|
||||
|
@ -480,7 +480,7 @@ public final HttpClientBuilder addInterceptorFirst(final HttpResponseInterceptor
|
||||
return this;
|
||||
}
|
||||
if (responseFirst == null) {
|
||||
responseFirst = new LinkedList<HttpResponseInterceptor>();
|
||||
responseFirst = new LinkedList<>();
|
||||
}
|
||||
responseFirst.addFirst(itcp);
|
||||
return this;
|
||||
@ -498,7 +498,7 @@ public final HttpClientBuilder addInterceptorLast(final HttpResponseInterceptor
|
||||
return this;
|
||||
}
|
||||
if (responseLast == null) {
|
||||
responseLast = new LinkedList<HttpResponseInterceptor>();
|
||||
responseLast = new LinkedList<>();
|
||||
}
|
||||
responseLast.addLast(itcp);
|
||||
return this;
|
||||
@ -515,7 +515,7 @@ public final HttpClientBuilder addInterceptorFirst(final HttpRequestInterceptor
|
||||
return this;
|
||||
}
|
||||
if (requestFirst == null) {
|
||||
requestFirst = new LinkedList<HttpRequestInterceptor>();
|
||||
requestFirst = new LinkedList<>();
|
||||
}
|
||||
requestFirst.addFirst(itcp);
|
||||
return this;
|
||||
@ -532,7 +532,7 @@ public final HttpClientBuilder addInterceptorLast(final HttpRequestInterceptor i
|
||||
return this;
|
||||
}
|
||||
if (requestLast == null) {
|
||||
requestLast = new LinkedList<HttpRequestInterceptor>();
|
||||
requestLast = new LinkedList<>();
|
||||
}
|
||||
requestLast.addLast(itcp);
|
||||
return this;
|
||||
@ -845,7 +845,7 @@ protected void addCloseable(final Closeable closeable) {
|
||||
return;
|
||||
}
|
||||
if (closeables == null) {
|
||||
closeables = new ArrayList<Closeable>();
|
||||
closeables = new ArrayList<>();
|
||||
}
|
||||
closeables.add(closeable);
|
||||
}
|
||||
@ -1013,7 +1013,7 @@ public CloseableHttpClient build() {
|
||||
}
|
||||
if (!contentCompressionDisabled) {
|
||||
if (contentDecoderMap != null) {
|
||||
final List<String> encodings = new ArrayList<String>(contentDecoderMap.keySet());
|
||||
final List<String> encodings = new ArrayList<>(contentDecoderMap.keySet());
|
||||
Collections.sort(encodings);
|
||||
b.add(new RequestAcceptEncoding(encodings));
|
||||
} else {
|
||||
@ -1125,10 +1125,10 @@ public CloseableHttpClient build() {
|
||||
}
|
||||
}
|
||||
|
||||
List<Closeable> closeablesCopy = closeables != null ? new ArrayList<Closeable>(closeables) : null;
|
||||
List<Closeable> closeablesCopy = closeables != null ? new ArrayList<>(closeables) : null;
|
||||
if (!this.connManagerShared) {
|
||||
if (closeablesCopy == null) {
|
||||
closeablesCopy = new ArrayList<Closeable>(1);
|
||||
closeablesCopy = new ArrayList<>(1);
|
||||
}
|
||||
final HttpClientConnectionManager cm = connManagerCopy;
|
||||
|
||||
|
@ -51,8 +51,8 @@ public class RedirectLocations extends AbstractList<Object> {
|
||||
|
||||
public RedirectLocations() {
|
||||
super();
|
||||
this.unique = new HashSet<URI>();
|
||||
this.all = new ArrayList<URI>();
|
||||
this.unique = new HashSet<>();
|
||||
this.all = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +95,7 @@ public boolean remove(final URI uri) {
|
||||
* @since 4.1
|
||||
*/
|
||||
public List<URI> getAll() {
|
||||
return new ArrayList<URI>(this.all);
|
||||
return new ArrayList<>(this.all);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -55,7 +55,7 @@ public class StandardHttpRequestRetryHandler extends DefaultHttpRequestRetryHand
|
||||
*/
|
||||
public StandardHttpRequestRetryHandler(final int retryCount, final boolean requestSentRetryEnabled) {
|
||||
super(retryCount, requestSentRetryEnabled);
|
||||
this.idempotentMethods = new ConcurrentHashMap<String, Boolean>();
|
||||
this.idempotentMethods = new ConcurrentHashMap<>();
|
||||
this.idempotentMethods.put("GET", Boolean.TRUE);
|
||||
this.idempotentMethods.put("HEAD", Boolean.TRUE);
|
||||
this.idempotentMethods.put("PUT", Boolean.TRUE);
|
||||
|
@ -54,7 +54,7 @@ public class SystemDefaultCredentialsProvider implements CredentialsProvider {
|
||||
private static final Map<String, String> SCHEME_MAP;
|
||||
|
||||
static {
|
||||
SCHEME_MAP = new ConcurrentHashMap<String, String>();
|
||||
SCHEME_MAP = new ConcurrentHashMap<>();
|
||||
SCHEME_MAP.put(AuthSchemes.BASIC.toUpperCase(Locale.ROOT), "Basic");
|
||||
SCHEME_MAP.put(AuthSchemes.DIGEST.toUpperCase(Locale.ROOT), "Digest");
|
||||
SCHEME_MAP.put(AuthSchemes.NTLM.toUpperCase(Locale.ROOT), "NTLM");
|
||||
|
@ -77,7 +77,7 @@ public DefaultManagedHttpClientConnection(
|
||||
constraints, incomingContentStrategy, outgoingContentStrategy,
|
||||
requestWriterFactory, responseParserFactory);
|
||||
this.id = id;
|
||||
this.attributes = new ConcurrentHashMap<String, Object>();
|
||||
this.attributes = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public DefaultManagedHttpClientConnection(
|
||||
|
@ -58,7 +58,7 @@ public class InMemoryDnsResolver implements DnsResolver {
|
||||
* collection held in-memory.
|
||||
*/
|
||||
public InMemoryDnsResolver() {
|
||||
dnsMap = new ConcurrentHashMap<String, InetAddress[]>();
|
||||
dnsMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -521,8 +521,8 @@ static class ConfigData {
|
||||
|
||||
ConfigData() {
|
||||
super();
|
||||
this.socketConfigMap = new ConcurrentHashMap<HttpHost, SocketConfig>();
|
||||
this.connectionConfigMap = new ConcurrentHashMap<HttpHost, ConnectionConfig>();
|
||||
this.socketConfigMap = new ConcurrentHashMap<>();
|
||||
this.connectionConfigMap = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
public SocketConfig getDefaultSocketConfig() {
|
||||
|
@ -59,7 +59,7 @@ public abstract class AbstractCookieSpec implements CookieSpec {
|
||||
* */
|
||||
public AbstractCookieSpec() {
|
||||
super();
|
||||
this.attribHandlerMap = new ConcurrentHashMap<String, CookieAttributeHandler>(10);
|
||||
this.attribHandlerMap = new ConcurrentHashMap<>(10);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +68,7 @@ public AbstractCookieSpec() {
|
||||
protected AbstractCookieSpec(final HashMap<String, CookieAttributeHandler> map) {
|
||||
super();
|
||||
Asserts.notNull(map, "Attribute handler map");
|
||||
this.attribHandlerMap = new ConcurrentHashMap<String, CookieAttributeHandler>(map);
|
||||
this.attribHandlerMap = new ConcurrentHashMap<>(map);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ protected AbstractCookieSpec(final HashMap<String, CookieAttributeHandler> map)
|
||||
*/
|
||||
protected AbstractCookieSpec(final CommonCookieAttributeHandler... handlers) {
|
||||
super();
|
||||
this.attribHandlerMap = new ConcurrentHashMap<String, CookieAttributeHandler>(handlers.length);
|
||||
this.attribHandlerMap = new ConcurrentHashMap<>(handlers.length);
|
||||
for (CommonCookieAttributeHandler handler: handlers) {
|
||||
this.attribHandlerMap.put(handler.getAttributeName(), handler);
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ public BasicClientCookie(final String name, final String value) {
|
||||
super();
|
||||
Args.notNull(name, "Name");
|
||||
this.name = name;
|
||||
this.attribs = new HashMap<String, String>();
|
||||
this.attribs = new HashMap<>();
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@ -342,7 +342,7 @@ public boolean removeAttribute(final String name) {
|
||||
@Override
|
||||
public Object clone() throws CloneNotSupportedException {
|
||||
final BasicClientCookie clone = (BasicClientCookie) super.clone();
|
||||
clone.attribs = new HashMap<String, String>(this.attribs);
|
||||
clone.attribs = new HashMap<>(this.attribs);
|
||||
return clone;
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ protected static String getDefaultDomain(final CookieOrigin origin) {
|
||||
|
||||
protected List<Cookie> parse(final HeaderElement[] elems, final CookieOrigin origin)
|
||||
throws MalformedCookieException {
|
||||
final List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
|
||||
final List<Cookie> cookies = new ArrayList<>(elems.length);
|
||||
for (final HeaderElement headerelement : elems) {
|
||||
final String name = headerelement.getName();
|
||||
final String value = headerelement.getValue();
|
||||
|
@ -72,7 +72,7 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
|
||||
}
|
||||
private static final Map<String, Integer> MONTHS;
|
||||
static {
|
||||
final ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<String, Integer>(12);
|
||||
final ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>(12);
|
||||
map.put("jan", Calendar.JANUARY);
|
||||
map.put("feb", Calendar.FEBRUARY);
|
||||
map.put("mar", Calendar.MARCH);
|
||||
|
@ -71,7 +71,7 @@ public HeaderElement parseHeader(
|
||||
Args.notNull(buffer, "Char array buffer");
|
||||
Args.notNull(cursor, "Parser cursor");
|
||||
final NameValuePair nvp = parseNameValuePair(buffer, cursor);
|
||||
final List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||
final List<NameValuePair> params = new ArrayList<>();
|
||||
while (!cursor.atEnd()) {
|
||||
final NameValuePair param = parseNameValuePair(buffer, cursor);
|
||||
params.add(param);
|
||||
|
@ -151,7 +151,7 @@ public List<Header> formatCookies(final List<Cookie> cookies) {
|
||||
buffer.append(s);
|
||||
}
|
||||
}
|
||||
final List<Header> headers = new ArrayList<Header>(1);
|
||||
final List<Header> headers = new ArrayList<>(1);
|
||||
headers.add(new BufferedHeader(buffer));
|
||||
return headers;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ public List<Header> formatCookies(final List<Cookie> cookies) {
|
||||
List<Cookie> cookieList;
|
||||
if (cookies.size() > 1) {
|
||||
// Create a mutable copy and sort the copy.
|
||||
cookieList = new ArrayList<Cookie>(cookies);
|
||||
cookieList = new ArrayList<>(cookies);
|
||||
Collections.sort(cookieList, CookiePathComparator.INSTANCE);
|
||||
} else {
|
||||
cookieList = cookies;
|
||||
@ -155,13 +155,13 @@ private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
|
||||
final Cookie cookie = cooky;
|
||||
formatCookieAsVer(buffer, cookie, version);
|
||||
}
|
||||
final List<Header> headers = new ArrayList<Header>(1);
|
||||
final List<Header> headers = new ArrayList<>(1);
|
||||
headers.add(new BufferedHeader(buffer));
|
||||
return headers;
|
||||
}
|
||||
|
||||
private List<Header> doFormatManyHeaders(final List<Cookie> cookies) {
|
||||
final List<Header> headers = new ArrayList<Header>(cookies.size());
|
||||
final List<Header> headers = new ArrayList<>(cookies.size());
|
||||
for (final Cookie cookie : cookies) {
|
||||
final int version = cookie.getVersion();
|
||||
final CharArrayBuffer buffer = new CharArrayBuffer(40);
|
||||
|
@ -112,7 +112,7 @@ protected List<Cookie> parse(
|
||||
private List<Cookie> createCookies(
|
||||
final HeaderElement[] elems,
|
||||
final CookieOrigin origin) throws MalformedCookieException {
|
||||
final List<Cookie> cookies = new ArrayList<Cookie>(elems.length);
|
||||
final List<Cookie> cookies = new ArrayList<>(elems.length);
|
||||
for (final HeaderElement headerelement : elems) {
|
||||
final String name = headerelement.getName();
|
||||
final String value = headerelement.getValue();
|
||||
@ -130,7 +130,7 @@ private List<Cookie> createCookies(
|
||||
// Eliminate duplicate attributes. The first occurrence takes precedence
|
||||
// See RFC2965: 3.2 Origin Server Role
|
||||
final Map<String, NameValuePair> attribmap =
|
||||
new HashMap<String, NameValuePair>(attribs.length);
|
||||
new HashMap<>(attribs.length);
|
||||
for (int j = attribs.length - 1; j >= 0; j--) {
|
||||
final NameValuePair param = attribs[j];
|
||||
attribmap.put(param.getName().toLowerCase(Locale.ROOT), param);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user