- Always use blocks
- Add missing serial version ID (default 1L) - Camel-case names. - Don't nest in else clause unnecessarily. - Remove declared exceptions that are not thrown (but don't break BC.) - Remove redundant superinterface - Access static methods directly - Better local var names.
This commit is contained in:
parent
b9a286ed93
commit
e6c226d5f6
|
@ -91,10 +91,10 @@ class InternalByteArrayEntity extends AbstractHttpEntity implements Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
outstream.write(this.b, this.off, this.len);
|
||||
outstream.flush();
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
outStream.write(this.b, this.off, this.len);
|
||||
outStream.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -65,18 +65,18 @@ class InternalFileEntity extends AbstractHttpEntity implements Cloneable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = new FileInputStream(this.file);
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
final InputStream inStream = new FileInputStream(this.file);
|
||||
try {
|
||||
final byte[] tmp = new byte[4096];
|
||||
int l;
|
||||
while ((l = instream.read(tmp)) != -1) {
|
||||
outstream.write(tmp, 0, l);
|
||||
while ((l = inStream.read(tmp)) != -1) {
|
||||
outStream.write(tmp, 0, l);
|
||||
}
|
||||
outstream.flush();
|
||||
outStream.flush();
|
||||
} finally {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,9 @@ class InternalInputStreamEntity extends AbstractHttpEntity {
|
|||
private final InputStream content;
|
||||
private final long length;
|
||||
|
||||
public InternalInputStreamEntity(final InputStream instream, final long length, final ContentType contentType) {
|
||||
public InternalInputStreamEntity(final InputStream inputStream, final long length, final ContentType contentType) {
|
||||
super();
|
||||
this.content = Args.notNull(instream, "Source input stream");
|
||||
this.content = Args.notNull(inputStream, "Source input stream");
|
||||
this.length = length;
|
||||
if (contentType != null) {
|
||||
setContentType(contentType.toString());
|
||||
|
@ -65,31 +65,31 @@ class InternalInputStreamEntity extends AbstractHttpEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = this.content;
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
final InputStream inStream = this.content;
|
||||
try {
|
||||
final byte[] buffer = new byte[4096];
|
||||
int l;
|
||||
int readLen;
|
||||
if (this.length < 0) {
|
||||
// consume until EOF
|
||||
while ((l = instream.read(buffer)) != -1) {
|
||||
outstream.write(buffer, 0, l);
|
||||
while ((readLen = inStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, readLen);
|
||||
}
|
||||
} else {
|
||||
// consume no more than length
|
||||
long remaining = this.length;
|
||||
while (remaining > 0) {
|
||||
l = instream.read(buffer, 0, (int)Math.min(4096, remaining));
|
||||
if (l == -1) {
|
||||
readLen = inStream.read(buffer, 0, (int)Math.min(4096, remaining));
|
||||
if (readLen == -1) {
|
||||
break;
|
||||
}
|
||||
outstream.write(buffer, 0, l);
|
||||
remaining -= l;
|
||||
outStream.write(buffer, 0, readLen);
|
||||
remaining -= readLen;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -401,12 +401,12 @@ public class Request {
|
|||
return body(new InternalByteArrayEntity(b, off, len, contentType));
|
||||
}
|
||||
|
||||
public Request bodyStream(final InputStream instream) {
|
||||
return body(new InternalInputStreamEntity(instream, -1, null));
|
||||
public Request bodyStream(final InputStream inStream) {
|
||||
return body(new InternalInputStreamEntity(inStream, -1, null));
|
||||
}
|
||||
|
||||
public Request bodyStream(final InputStream instream, final ContentType contentType) {
|
||||
return body(new InternalInputStreamEntity(instream, -1, contentType));
|
||||
public Request bodyStream(final InputStream inStream, final ContentType contentType) {
|
||||
return body(new InternalInputStreamEntity(inStream, -1, contentType));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,7 +41,7 @@ public interface ResourceFactory {
|
|||
* Creates a {@link Resource} from a given response body.
|
||||
* @param requestId a unique identifier for this particular
|
||||
* response body
|
||||
* @param instream the original {@link InputStream}
|
||||
* @param inStream the original {@link InputStream}
|
||||
* containing the response body of the origin HTTP response.
|
||||
* @param limit maximum number of bytes to consume of the
|
||||
* response body; if this limit is reached before the
|
||||
|
@ -52,7 +52,7 @@ public interface ResourceFactory {
|
|||
* the response body was successfully read.
|
||||
* @throws IOException
|
||||
*/
|
||||
Resource generate(String requestId, InputStream instream, InputLimit limit) throws IOException;
|
||||
Resource generate(String requestId, InputStream inStream, InputLimit limit) throws IOException;
|
||||
|
||||
/**
|
||||
* Clones an existing {@link Resource}.
|
||||
|
|
|
@ -82,13 +82,13 @@ class CacheEntity implements HttpEntity, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = this.cacheEntry.getResource().getInputStream();
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
final InputStream inStream = this.cacheEntry.getResource().getInputStream();
|
||||
try {
|
||||
IOUtils.copy(instream, outstream);
|
||||
IOUtils.copy(inStream, outStream);
|
||||
} finally {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,11 +41,11 @@ class CombinedEntity extends AbstractHttpEntity {
|
|||
private final Resource resource;
|
||||
private final InputStream combinedStream;
|
||||
|
||||
CombinedEntity(final Resource resource, final InputStream instream) throws IOException {
|
||||
CombinedEntity(final Resource resource, final InputStream inStream) throws IOException {
|
||||
super();
|
||||
this.resource = resource;
|
||||
this.combinedStream = new SequenceInputStream(
|
||||
new ResourceStream(resource.getInputStream()), instream);
|
||||
new ResourceStream(resource.getInputStream()), inStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,17 +69,17 @@ class CombinedEntity extends AbstractHttpEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = getContent();
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
final InputStream inStream = getContent();
|
||||
try {
|
||||
int l;
|
||||
final byte[] tmp = new byte[2048];
|
||||
while ((l = instream.read(tmp)) != -1) {
|
||||
outstream.write(tmp, 0, l);
|
||||
while ((l = inStream.read(tmp)) != -1) {
|
||||
outStream.write(tmp, 0, l);
|
||||
}
|
||||
} finally {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,16 +73,16 @@ public class FileResourceFactory implements ResourceFactory {
|
|||
@Override
|
||||
public Resource generate(
|
||||
final String requestId,
|
||||
final InputStream instream,
|
||||
final InputStream inStream,
|
||||
final InputLimit limit) throws IOException {
|
||||
final File file = generateUniqueCacheFile(requestId);
|
||||
final FileOutputStream outstream = new FileOutputStream(file);
|
||||
final FileOutputStream outStream = new FileOutputStream(file);
|
||||
try {
|
||||
final byte[] buf = new byte[2048];
|
||||
long total = 0;
|
||||
int l;
|
||||
while ((l = instream.read(buf)) != -1) {
|
||||
outstream.write(buf, 0, l);
|
||||
while ((l = inStream.read(buf)) != -1) {
|
||||
outStream.write(buf, 0, l);
|
||||
total += l;
|
||||
if (limit != null && total > limit.getValue()) {
|
||||
limit.reached();
|
||||
|
@ -90,7 +90,7 @@ public class FileResourceFactory implements ResourceFactory {
|
|||
}
|
||||
}
|
||||
} finally {
|
||||
outstream.close();
|
||||
outStream.close();
|
||||
}
|
||||
return new FileResource(file);
|
||||
}
|
||||
|
|
|
@ -47,21 +47,21 @@ public class HeapResourceFactory implements ResourceFactory {
|
|||
@Override
|
||||
public Resource generate(
|
||||
final String requestId,
|
||||
final InputStream instream,
|
||||
final InputStream inStream,
|
||||
final InputLimit limit) throws IOException {
|
||||
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
||||
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
final byte[] buf = new byte[2048];
|
||||
long total = 0;
|
||||
int l;
|
||||
while ((l = instream.read(buf)) != -1) {
|
||||
outstream.write(buf, 0, l);
|
||||
while ((l = inStream.read(buf)) != -1) {
|
||||
outStream.write(buf, 0, l);
|
||||
total += l;
|
||||
if (limit != null && total > limit.getValue()) {
|
||||
limit.reached();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return createResource(outstream.toByteArray());
|
||||
return createResource(outStream.toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,9 +72,9 @@ public class HeapResourceFactory implements ResourceFactory {
|
|||
if (resource instanceof HeapResource) {
|
||||
body = ((HeapResource) resource).getByteArray();
|
||||
} else {
|
||||
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
||||
IOUtils.copyAndClose(resource.getInputStream(), outstream);
|
||||
body = outstream.toByteArray();
|
||||
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
IOUtils.copyAndClose(resource.getInputStream(), outStream);
|
||||
body = outStream.toByteArray();
|
||||
}
|
||||
return createResource(body);
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ class IOUtils {
|
|||
return;
|
||||
}
|
||||
if (entity.isStreaming()) {
|
||||
final InputStream instream = entity.getContent();
|
||||
if (instream != null) {
|
||||
instream.close();
|
||||
final InputStream inStream = entity.getContent();
|
||||
if (inStream != null) {
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ class SizeLimitedResponseReader {
|
|||
private final HttpRequest request;
|
||||
private final CloseableHttpResponse response;
|
||||
|
||||
private InputStream instream;
|
||||
private InputStream inStream;
|
||||
private InputLimit limit;
|
||||
private Resource resource;
|
||||
private boolean consumed;
|
||||
|
@ -99,12 +99,12 @@ class SizeLimitedResponseReader {
|
|||
return;
|
||||
}
|
||||
final String uri = request.getRequestLine().getUri();
|
||||
instream = entity.getContent();
|
||||
inStream = entity.getContent();
|
||||
try {
|
||||
resource = resourceFactory.generate(uri, instream, limit);
|
||||
resource = resourceFactory.generate(uri, inStream, limit);
|
||||
} finally {
|
||||
if (!limit.isReached()) {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ class SizeLimitedResponseReader {
|
|||
final HttpResponse reconstructed = new BasicHttpResponse(response.getStatusLine());
|
||||
reconstructed.setHeaders(response.getAllHeaders());
|
||||
|
||||
final CombinedEntity combinedEntity = new CombinedEntity(resource, instream);
|
||||
final CombinedEntity combinedEntity = new CombinedEntity(resource, inStream);
|
||||
final HttpEntity entity = response.getEntity();
|
||||
if (entity != null) {
|
||||
combinedEntity.setContentType(entity.getContentType());
|
||||
|
|
|
@ -45,8 +45,8 @@ public class TestCombinedEntity {
|
|||
when(resource.getInputStream()).thenReturn(
|
||||
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }));
|
||||
|
||||
final ByteArrayInputStream instream = new ByteArrayInputStream(new byte[] { 6, 7, 8, 9, 10 });
|
||||
final CombinedEntity entity = new CombinedEntity(resource, instream);
|
||||
final ByteArrayInputStream inStream = new ByteArrayInputStream(new byte[] { 6, 7, 8, 9, 10 });
|
||||
final CombinedEntity entity = new CombinedEntity(resource, inStream);
|
||||
Assert.assertEquals(-1, entity.getContentLength());
|
||||
Assert.assertFalse(entity.isRepeatable());
|
||||
Assert.assertTrue(entity.isStreaming());
|
||||
|
|
|
@ -59,9 +59,9 @@ public class ClientConnectionRelease {
|
|||
// If the response does not enclose an entity, there is no need
|
||||
// to bother about connection release
|
||||
if (entity != null) {
|
||||
InputStream instream = entity.getContent();
|
||||
InputStream inStream = entity.getContent();
|
||||
try {
|
||||
instream.read();
|
||||
inStream.read();
|
||||
// do something useful with the response
|
||||
} catch (IOException ex) {
|
||||
// In case of an IOException the connection will be released
|
||||
|
@ -69,7 +69,7 @@ public class ClientConnectionRelease {
|
|||
throw ex;
|
||||
} finally {
|
||||
// Closing the input stream will trigger connection release
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
|
|
@ -113,8 +113,8 @@ public class BasicManagedEntity extends HttpEntityWrapper
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
super.writeTo(outstream);
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
super.writeTo(outStream);
|
||||
ensureConsumed();
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ public class BasicClientConnectionManager implements ClientConnectionManager {
|
|||
|
||||
@Override
|
||||
public ManagedClientConnection getConnection(
|
||||
final long timeout, final TimeUnit tunit) {
|
||||
final long timeout, final TimeUnit timeUnit) {
|
||||
return BasicClientConnectionManager.this.getConnection(
|
||||
route, state);
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public class BasicClientConnectionManager implements ClientConnectionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
|
||||
public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit timeUnit) {
|
||||
Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
|
||||
"connection not obtained from this manager");
|
||||
final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
|
||||
|
@ -214,11 +214,11 @@ public class BasicClientConnectionManager implements ClientConnectionManager {
|
|||
shutdownConnection(managedConn);
|
||||
}
|
||||
if (managedConn.isMarkedReusable()) {
|
||||
this.poolEntry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
|
||||
this.poolEntry.updateExpiry(keepalive, timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS);
|
||||
if (this.log.isDebugEnabled()) {
|
||||
final String s;
|
||||
if (keepalive > 0) {
|
||||
s = "for " + keepalive + " " + tunit;
|
||||
s = "for " + keepalive + " " + timeUnit;
|
||||
} else {
|
||||
s = "indefinitely";
|
||||
}
|
||||
|
@ -249,11 +249,11 @@ public class BasicClientConnectionManager implements ClientConnectionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
Args.notNull(tunit, "Time unit");
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
Args.notNull(timeUnit, "Time unit");
|
||||
synchronized (this) {
|
||||
assertNotShutdown();
|
||||
long time = tunit.toMillis(idletime);
|
||||
long time = timeUnit.toMillis(idletime);
|
||||
if (time < 0) {
|
||||
time = 0;
|
||||
}
|
||||
|
|
|
@ -187,29 +187,29 @@ public class DefaultClientConnection extends SocketHttpClientConnection
|
|||
@Override
|
||||
protected SessionInputBuffer createSessionInputBuffer(
|
||||
final Socket socket,
|
||||
final int buffersize,
|
||||
final int bufferSize,
|
||||
final HttpParams params) throws IOException {
|
||||
SessionInputBuffer inbuffer = super.createSessionInputBuffer(
|
||||
SessionInputBuffer inBuffer = super.createSessionInputBuffer(
|
||||
socket,
|
||||
buffersize > 0 ? buffersize : 8192,
|
||||
bufferSize > 0 ? bufferSize : 8192,
|
||||
params);
|
||||
if (wireLog.isDebugEnabled()) {
|
||||
inbuffer = new LoggingSessionInputBuffer(
|
||||
inbuffer,
|
||||
inBuffer = new LoggingSessionInputBuffer(
|
||||
inBuffer,
|
||||
new Wire(wireLog),
|
||||
HttpProtocolParams.getHttpElementCharset(params));
|
||||
}
|
||||
return inbuffer;
|
||||
return inBuffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SessionOutputBuffer createSessionOutputBuffer(
|
||||
final Socket socket,
|
||||
final int buffersize,
|
||||
final int bufferSize,
|
||||
final HttpParams params) throws IOException {
|
||||
SessionOutputBuffer outbuffer = super.createSessionOutputBuffer(
|
||||
socket,
|
||||
buffersize > 0 ? buffersize : 8192,
|
||||
bufferSize > 0 ? bufferSize : 8192,
|
||||
params);
|
||||
if (wireLog.isDebugEnabled()) {
|
||||
outbuffer = new LoggingSessionOutputBuffer(
|
||||
|
|
|
@ -49,22 +49,22 @@ class HttpConnPool extends AbstractConnPool<HttpRoute, OperatedClientConnection,
|
|||
|
||||
private final Log log;
|
||||
private final long timeToLive;
|
||||
private final TimeUnit tunit;
|
||||
private final TimeUnit timeUnit;
|
||||
|
||||
public HttpConnPool(final Log log,
|
||||
final ClientConnectionOperator connOperator,
|
||||
final int defaultMaxPerRoute, final int maxTotal,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
super(new InternalConnFactory(connOperator), defaultMaxPerRoute, maxTotal);
|
||||
this.log = log;
|
||||
this.timeToLive = timeToLive;
|
||||
this.tunit = tunit;
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpPoolEntry createEntry(final HttpRoute route, final OperatedClientConnection conn) {
|
||||
final String id = Long.toString(COUNTER.getAndIncrement());
|
||||
return new HttpPoolEntry(this.log, id, route, conn, this.timeToLive, this.tunit);
|
||||
return new HttpPoolEntry(this.log, id, route, conn, this.timeToLive, this.timeUnit);
|
||||
}
|
||||
|
||||
static class InternalConnFactory implements ConnFactory<HttpRoute, OperatedClientConnection> {
|
||||
|
|
|
@ -52,8 +52,8 @@ class HttpPoolEntry extends PoolEntry<HttpRoute, OperatedClientConnection> {
|
|||
final String id,
|
||||
final HttpRoute route,
|
||||
final OperatedClientConnection conn,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super(id, route, conn, timeToLive, tunit);
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
super(id, route, conn, timeToLive, timeUnit);
|
||||
this.log = log;
|
||||
this.tracker = new RouteTracker(route);
|
||||
}
|
||||
|
|
|
@ -83,29 +83,29 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer, EofSensor
|
|||
|
||||
@Override
|
||||
public int read(final byte[] b, final int off, final int len) throws IOException {
|
||||
final int l = this.in.read(b, off, len);
|
||||
if (this.wire.enabled() && l > 0) {
|
||||
this.wire.input(b, off, l);
|
||||
final int readLen = this.in.read(b, off, len);
|
||||
if (this.wire.enabled() && readLen > 0) {
|
||||
this.wire.input(b, off, readLen);
|
||||
}
|
||||
return l;
|
||||
return readLen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
final int l = this.in.read();
|
||||
if (this.wire.enabled() && l != -1) {
|
||||
this.wire.input(l);
|
||||
final int b = this.in.read();
|
||||
if (this.wire.enabled() && b != -1) {
|
||||
this.wire.input(b);
|
||||
}
|
||||
return l;
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] b) throws IOException {
|
||||
final int l = this.in.read(b);
|
||||
if (this.wire.enabled() && l > 0) {
|
||||
this.wire.input(b, 0, l);
|
||||
final int readLen = this.in.read(b);
|
||||
if (this.wire.enabled() && readLen > 0) {
|
||||
this.wire.input(b, 0, readLen);
|
||||
}
|
||||
return l;
|
||||
return readLen;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -120,14 +120,14 @@ public class LoggingSessionInputBuffer implements SessionInputBuffer, EofSensor
|
|||
|
||||
@Override
|
||||
public int readLine(final CharArrayBuffer buffer) throws IOException {
|
||||
final int l = this.in.readLine(buffer);
|
||||
if (this.wire.enabled() && l >= 0) {
|
||||
final int pos = buffer.length() - l;
|
||||
final String s = new String(buffer.buffer(), pos, l);
|
||||
final int readLen = this.in.readLine(buffer);
|
||||
if (this.wire.enabled() && readLen >= 0) {
|
||||
final int pos = buffer.length() - readLen;
|
||||
final String s = new String(buffer.buffer(), pos, readLen);
|
||||
final String tmp = s + "\r\n";
|
||||
this.wire.input(tmp.getBytes(this.charset));
|
||||
}
|
||||
return l;
|
||||
return readLen;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -98,12 +98,12 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
|
||||
public PoolingClientConnectionManager(
|
||||
final SchemeRegistry schemeRegistry,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
this(schemeRegistry, timeToLive, tunit, new SystemDefaultDnsResolver());
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
this(schemeRegistry, timeToLive, timeUnit, new SystemDefaultDnsResolver());
|
||||
}
|
||||
|
||||
public PoolingClientConnectionManager(final SchemeRegistry schemeRegistry,
|
||||
final long timeToLive, final TimeUnit tunit,
|
||||
final long timeToLive, final TimeUnit timeUnit,
|
||||
final DnsResolver dnsResolver) {
|
||||
super();
|
||||
Args.notNull(schemeRegistry, "Scheme registry");
|
||||
|
@ -111,7 +111,7 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
this.schemeRegistry = schemeRegistry;
|
||||
this.dnsResolver = dnsResolver;
|
||||
this.operator = createConnectionOperator(schemeRegistry);
|
||||
this.pool = new HttpConnPool(this.log, this.operator, 2, 20, timeToLive, tunit);
|
||||
this.pool = new HttpConnPool(this.log, this.operator, 2, 20, timeToLive, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -196,8 +196,8 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
@Override
|
||||
public ManagedClientConnection getConnection(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
return leaseConnection(future, timeout, tunit);
|
||||
final TimeUnit timeUnit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
return leaseConnection(future, timeout, timeUnit);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -207,10 +207,10 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
ManagedClientConnection leaseConnection(
|
||||
final Future<HttpPoolEntry> future,
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
final TimeUnit timeUnit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
final HttpPoolEntry entry;
|
||||
try {
|
||||
entry = future.get(timeout, tunit);
|
||||
entry = future.get(timeout, timeUnit);
|
||||
if (entry == null || future.isCancelled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
@ -234,7 +234,7 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
|
||||
@Override
|
||||
public void releaseConnection(
|
||||
final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
|
||||
final ManagedClientConnection conn, final long keepalive, final TimeUnit timeUnit) {
|
||||
|
||||
Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
|
||||
"connection not obtained from this manager");
|
||||
|
@ -257,11 +257,11 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
}
|
||||
// Only reusable connections can be kept alive
|
||||
if (managedConn.isMarkedReusable()) {
|
||||
entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
|
||||
entry.updateExpiry(keepalive, timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS);
|
||||
if (this.log.isDebugEnabled()) {
|
||||
final String s;
|
||||
if (keepalive > 0) {
|
||||
s = "for " + keepalive + " " + tunit;
|
||||
s = "for " + keepalive + " " + timeUnit;
|
||||
} else {
|
||||
s = "indefinitely";
|
||||
}
|
||||
|
@ -289,11 +289,11 @@ public class PoolingClientConnectionManager implements ClientConnectionManager,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idleTimeout, final TimeUnit tunit) {
|
||||
public void closeIdleConnections(final long idleTimeout, final TimeUnit timeUnit) {
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
|
||||
this.log.debug("Closing connections idle longer than " + idleTimeout + " " + timeUnit);
|
||||
}
|
||||
this.pool.closeIdle(idleTimeout, tunit);
|
||||
this.pool.closeIdle(idleTimeout, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -186,7 +186,7 @@ public class SingleClientConnManager implements ClientConnectionManager {
|
|||
|
||||
@Override
|
||||
public ManagedClientConnection getConnection(
|
||||
final long timeout, final TimeUnit tunit) {
|
||||
final long timeout, final TimeUnit timeUnit) {
|
||||
return SingleClientConnManager.this.getConnection(
|
||||
route, state);
|
||||
}
|
||||
|
@ -317,16 +317,16 @@ public class SingleClientConnManager implements ClientConnectionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
assertStillUp();
|
||||
|
||||
// idletime can be 0 or negative, no problem there
|
||||
Args.notNull(tunit, "Time unit");
|
||||
Args.notNull(timeUnit, "Time unit");
|
||||
|
||||
synchronized (this) {
|
||||
if ((managedConn == null) && uniquePoolEntry.connection.isOpen()) {
|
||||
final long cutoff =
|
||||
System.currentTimeMillis() - tunit.toMillis(idletime);
|
||||
System.currentTimeMillis() - timeUnit.toMillis(idletime);
|
||||
if (lastReleaseTime <= cutoff) {
|
||||
try {
|
||||
uniquePoolEntry.close();
|
||||
|
|
|
@ -99,7 +99,7 @@ public abstract class AbstractConnPool {
|
|||
* @param route the route for which to get the connection
|
||||
* @param state the state
|
||||
* @param timeout the timeout, 0 or negative for no timeout
|
||||
* @param tunit the unit for the {@code timeout},
|
||||
* @param timeUnit the unit for the {@code timeout},
|
||||
* may be {@code null} only if there is no timeout
|
||||
*
|
||||
* @return pool entry holding a connection for the route
|
||||
|
@ -114,9 +114,9 @@ public abstract class AbstractConnPool {
|
|||
final HttpRoute route,
|
||||
final Object state,
|
||||
final long timeout,
|
||||
final TimeUnit tunit)
|
||||
final TimeUnit timeUnit)
|
||||
throws ConnectionPoolTimeoutException, InterruptedException {
|
||||
return requestPoolEntry(route, state).getPoolEntry(timeout, tunit);
|
||||
return requestPoolEntry(route, state).getPoolEntry(timeout, timeUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -154,16 +154,16 @@ public abstract class AbstractConnPool {
|
|||
*
|
||||
* @param idletime the time the connections should have been idle
|
||||
* in order to be closed now
|
||||
* @param tunit the unit for the {@code idletime}
|
||||
* @param timeUnit the unit for the {@code idletime}
|
||||
*/
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
|
||||
// idletime can be 0 or negative, no problem there
|
||||
Args.notNull(tunit, "Time unit");
|
||||
Args.notNull(timeUnit, "Time unit");
|
||||
|
||||
poolLock.lock();
|
||||
try {
|
||||
idleConnHandler.closeIdleConnections(tunit.toMillis(idletime));
|
||||
idleConnHandler.closeIdleConnections(timeUnit.toMillis(idletime));
|
||||
} finally {
|
||||
poolLock.unlock();
|
||||
}
|
||||
|
|
|
@ -295,9 +295,9 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
@Override
|
||||
public BasicPoolEntry getPoolEntry(
|
||||
final long timeout,
|
||||
final TimeUnit tunit)
|
||||
final TimeUnit timeUnit)
|
||||
throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
return getEntryBlocking(route, state, timeout, tunit, aborter);
|
||||
return getEntryBlocking(route, state, timeout, timeUnit, aborter);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -310,7 +310,7 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
*
|
||||
* @param route the route for which to get the connection
|
||||
* @param timeout the timeout, 0 or negative for no timeout
|
||||
* @param tunit the unit for the {@code timeout},
|
||||
* @param timeUnit the unit for the {@code timeout},
|
||||
* may be {@code null} only if there is no timeout
|
||||
* @param aborter an object which can abort a {@link WaitingThread}.
|
||||
*
|
||||
|
@ -323,14 +323,14 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
*/
|
||||
protected BasicPoolEntry getEntryBlocking(
|
||||
final HttpRoute route, final Object state,
|
||||
final long timeout, final TimeUnit tunit,
|
||||
final long timeout, final TimeUnit timeUnit,
|
||||
final WaitingThreadAborter aborter)
|
||||
throws ConnectionPoolTimeoutException, InterruptedException {
|
||||
|
||||
Date deadline = null;
|
||||
if (timeout > 0) {
|
||||
deadline = new Date
|
||||
(System.currentTimeMillis() + tunit.toMillis(timeout));
|
||||
(System.currentTimeMillis() + timeUnit.toMillis(timeout));
|
||||
}
|
||||
|
||||
BasicPoolEntry entry = null;
|
||||
|
@ -710,17 +710,17 @@ public class ConnPoolByRoute extends AbstractConnPool {
|
|||
*
|
||||
* @param idletime the time the connections should have been idle
|
||||
* in order to be closed now
|
||||
* @param tunit the unit for the {@code idletime}
|
||||
* @param timeUnit the unit for the {@code idletime}
|
||||
*/
|
||||
@Override
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
Args.notNull(tunit, "Time unit");
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
Args.notNull(timeUnit, "Time unit");
|
||||
final long t = idletime > 0 ? idletime : 0;
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Closing connections idle longer than " + t + " " + tunit);
|
||||
log.debug("Closing connections idle longer than " + t + " " + timeUnit);
|
||||
}
|
||||
// the latest time for which connections will be closed
|
||||
final long deadline = System.currentTimeMillis() - tunit.toMillis(t);
|
||||
final long deadline = System.currentTimeMillis() - timeUnit.toMillis(t);
|
||||
poolLock.lock();
|
||||
try {
|
||||
final Iterator<BasicPoolEntry> iter = freeConnections.iterator();
|
||||
|
|
|
@ -46,7 +46,7 @@ public interface PoolEntryRequest {
|
|||
* an {@link InterruptedException} is thrown.
|
||||
*
|
||||
* @param timeout the timeout, 0 or negative for no timeout
|
||||
* @param tunit the unit for the {@code timeout},
|
||||
* @param timeUnit the unit for the {@code timeout},
|
||||
* may be {@code null} only if there is no timeout
|
||||
*
|
||||
* @return pool entry holding a connection for the route
|
||||
|
@ -58,7 +58,7 @@ public interface PoolEntryRequest {
|
|||
*/
|
||||
BasicPoolEntry getPoolEntry(
|
||||
long timeout,
|
||||
TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException;
|
||||
TimeUnit timeUnit) throws InterruptedException, ConnectionPoolTimeoutException;
|
||||
|
||||
/**
|
||||
* Aborts the active or next call to
|
||||
|
|
|
@ -232,7 +232,7 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
|||
|
||||
@Override
|
||||
public ManagedClientConnection getConnection(
|
||||
final long timeout, final TimeUnit tunit) throws InterruptedException,
|
||||
final long timeout, final TimeUnit timeUnit) throws InterruptedException,
|
||||
ConnectionPoolTimeoutException {
|
||||
Args.notNull(route, "Route");
|
||||
|
||||
|
@ -240,7 +240,7 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
|||
log.debug("Get connection: " + route + ", timeout = " + timeout);
|
||||
}
|
||||
|
||||
final BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, tunit);
|
||||
final BasicPoolEntry entry = poolRequest.getPoolEntry(timeout, timeUnit);
|
||||
return new BasicPooledConnAdapter(ThreadSafeClientConnManager.this, entry);
|
||||
}
|
||||
|
||||
|
@ -327,11 +327,11 @@ public class ThreadSafeClientConnManager implements ClientConnectionManager {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idleTimeout, final TimeUnit tunit) {
|
||||
public void closeIdleConnections(final long idleTimeout, final TimeUnit timeUnit) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
|
||||
log.debug("Closing connections idle longer than " + idleTimeout + " " + timeUnit);
|
||||
}
|
||||
pool.closeIdleConnections(idleTimeout, tunit);
|
||||
pool.closeIdleConnections(idleTimeout, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -112,9 +112,8 @@ public final class AuthSchemeRegistry implements Lookup<AuthSchemeProvider> {
|
|||
final AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase(Locale.ENGLISH));
|
||||
if (factory != null) {
|
||||
return factory.newInstance(params);
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported authentication scheme: " + name);
|
||||
}
|
||||
throw new IllegalStateException("Unsupported authentication scheme: " + name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,23 +79,22 @@ public class DecompressingEntity extends HttpEntityWrapper {
|
|||
content = getDecompressingStream();
|
||||
}
|
||||
return content;
|
||||
} else {
|
||||
return getDecompressingStream();
|
||||
}
|
||||
return getDecompressingStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final InputStream instream = getContent();
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
final InputStream inStream = getContent();
|
||||
try {
|
||||
final byte[] buffer = new byte[BUFFER_SIZE];
|
||||
int l;
|
||||
while ((l = instream.read(buffer)) != -1) {
|
||||
outstream.write(buffer, 0, l);
|
||||
while ((l = inStream.read(buffer)) != -1) {
|
||||
outStream.write(buffer, 0, l);
|
||||
}
|
||||
} finally {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,9 +101,9 @@ public class GzipCompressingEntity extends HttpEntityWrapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
final GZIPOutputStream gzip = new GZIPOutputStream(outstream);
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
final GZIPOutputStream gzip = new GZIPOutputStream(outStream);
|
||||
wrappedEntity.writeTo(gzip);
|
||||
// Only close output stream if the wrapped entity has been
|
||||
// successfully written out
|
||||
|
|
|
@ -36,6 +36,6 @@ import java.io.InputStream;
|
|||
*/
|
||||
public interface InputStreamFactory {
|
||||
|
||||
InputStream create(InputStream instream) throws IOException;
|
||||
InputStream create(InputStream inStream) throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -189,11 +189,10 @@ public class HttpRequestWrapper extends AbstractHttpMessage implements HttpUriRe
|
|||
*/
|
||||
public static HttpRequestWrapper wrap(final HttpRequest request, final HttpHost target) {
|
||||
Args.notNull(request, "HTTP request");
|
||||
if (request instanceof HttpEntityEnclosingRequest) {
|
||||
return new HttpEntityEnclosingRequestWrapper((HttpEntityEnclosingRequest) request, target);
|
||||
} else {
|
||||
return new HttpRequestWrapper(request, target);
|
||||
}
|
||||
return request instanceof HttpEntityEnclosingRequest
|
||||
? new HttpEntityEnclosingRequestWrapper(
|
||||
(HttpEntityEnclosingRequest) request, target)
|
||||
: new HttpRequestWrapper(request, target);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -134,11 +134,9 @@ public class HttpClientContext extends HttpCoreContext {
|
|||
public static final String REQUEST_CONFIG = "http.request-config";
|
||||
|
||||
public static HttpClientContext adapt(final HttpContext context) {
|
||||
if (context instanceof HttpClientContext) {
|
||||
return (HttpClientContext) context;
|
||||
} else {
|
||||
return new HttpClientContext(context);
|
||||
}
|
||||
return context instanceof HttpClientContext
|
||||
? (HttpClientContext) context
|
||||
: new HttpClientContext(context);
|
||||
}
|
||||
|
||||
public static HttpClientContext create() {
|
||||
|
|
|
@ -59,15 +59,13 @@ public class CloneUtils {
|
|||
final Throwable cause = ex.getCause();
|
||||
if (cause instanceof CloneNotSupportedException) {
|
||||
throw ((CloneNotSupportedException) cause);
|
||||
} else {
|
||||
throw new Error("Unexpected exception", cause);
|
||||
}
|
||||
throw new Error("Unexpected exception", cause);
|
||||
} catch (final IllegalAccessException ex) {
|
||||
throw new IllegalAccessError(ex.getMessage());
|
||||
}
|
||||
} else {
|
||||
throw new CloneNotSupportedException();
|
||||
}
|
||||
throw new CloneNotSupportedException();
|
||||
}
|
||||
|
||||
public static Object clone(final Object obj) throws CloneNotSupportedException {
|
||||
|
|
|
@ -495,11 +495,9 @@ public class URIBuilder {
|
|||
}
|
||||
|
||||
public List<NameValuePair> getQueryParams() {
|
||||
if (this.queryParams != null) {
|
||||
return new ArrayList<NameValuePair>(this.queryParams);
|
||||
} else {
|
||||
return new ArrayList<NameValuePair>();
|
||||
}
|
||||
return this.queryParams != null
|
||||
? new ArrayList<NameValuePair>(this.queryParams)
|
||||
: new ArrayList<NameValuePair>();
|
||||
}
|
||||
|
||||
public String getFragment() {
|
||||
|
|
|
@ -211,20 +211,12 @@ public class URIUtils {
|
|||
}
|
||||
if (route.getProxyHost() != null && !route.isTunnelled()) {
|
||||
// Make sure the request URI is absolute
|
||||
if (!uri.isAbsolute()) {
|
||||
final HttpHost target = route.getTargetHost();
|
||||
return rewriteURI(uri, target, true);
|
||||
} else {
|
||||
return rewriteURI(uri);
|
||||
}
|
||||
} else {
|
||||
// Make sure the request URI is relative
|
||||
if (uri.isAbsolute()) {
|
||||
return rewriteURI(uri, null, true);
|
||||
} else {
|
||||
return rewriteURI(uri);
|
||||
}
|
||||
return uri.isAbsolute()
|
||||
? rewriteURI(uri)
|
||||
: rewriteURI(uri, route.getTargetHost(), true);
|
||||
}
|
||||
// Make sure the request URI is relative
|
||||
return uri.isAbsolute() ? rewriteURI(uri, null, true) : rewriteURI(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -124,14 +124,14 @@ public class URLEncodedUtils {
|
|||
final long len = entity.getContentLength();
|
||||
Args.check(len <= Integer.MAX_VALUE, "HTTP entity is too large");
|
||||
final Charset charset = contentType.getCharset() != null ? contentType.getCharset() : HTTP.DEF_CONTENT_CHARSET;
|
||||
final InputStream instream = entity.getContent();
|
||||
if (instream == null) {
|
||||
final InputStream inStream = entity.getContent();
|
||||
if (inStream == null) {
|
||||
return createEmptyList();
|
||||
}
|
||||
final CharArrayBuffer buf;
|
||||
try {
|
||||
buf = new CharArrayBuffer(len > 0 ? (int) len : 1024);
|
||||
final Reader reader = new InputStreamReader(instream, charset);
|
||||
final Reader reader = new InputStreamReader(inStream, charset);
|
||||
final char[] tmp = new char[1024];
|
||||
int l;
|
||||
while((l = reader.read(tmp)) != -1) {
|
||||
|
@ -139,7 +139,7 @@ public class URLEncodedUtils {
|
|||
}
|
||||
|
||||
} finally {
|
||||
instream.close();
|
||||
inStream.close();
|
||||
}
|
||||
if (buf.isEmpty()) {
|
||||
return createEmptyList();
|
||||
|
|
|
@ -92,11 +92,11 @@ public interface ClientConnectionManager {
|
|||
* All expired connections will also be closed.
|
||||
*
|
||||
* @param idletime the idle time of connections to be closed
|
||||
* @param tunit the unit for the {@code idletime}
|
||||
* @param timeUnit the unit for the {@code idletime}
|
||||
*
|
||||
* @see #closeExpiredConnections()
|
||||
*/
|
||||
void closeIdleConnections(long idletime, TimeUnit tunit);
|
||||
void closeIdleConnections(long idletime, TimeUnit timeUnit);
|
||||
|
||||
/**
|
||||
* Closes all expired connections in the pool.
|
||||
|
|
|
@ -51,7 +51,7 @@ public interface ClientConnectionRequest {
|
|||
* be thrown.
|
||||
*
|
||||
* @param timeout the timeout, 0 or negative for no timeout
|
||||
* @param tunit the unit for the {@code timeout},
|
||||
* @param timeUnit the unit for the {@code timeout},
|
||||
* may be {@code null} only if there is no timeout
|
||||
*
|
||||
* @return a connection that can be used to communicate
|
||||
|
@ -62,7 +62,7 @@ public interface ClientConnectionRequest {
|
|||
* @throws InterruptedException
|
||||
* if the calling thread is interrupted while waiting
|
||||
*/
|
||||
ManagedClientConnection getConnection(long timeout, TimeUnit tunit)
|
||||
ManagedClientConnection getConnection(long timeout, TimeUnit timeUnit)
|
||||
throws InterruptedException, ConnectionPoolTimeoutException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@ public interface ConnectionRequest extends Cancellable {
|
|||
* be thrown.
|
||||
*
|
||||
* @param timeout the timeout, 0 or negative for no timeout
|
||||
* @param tunit the unit for the {@code timeout},
|
||||
* @param timeUnit the unit for the {@code timeout},
|
||||
* may be {@code null} only if there is no timeout
|
||||
*
|
||||
* @return a connection that can be used to communicate
|
||||
|
@ -63,7 +63,7 @@ public interface ConnectionRequest extends Cancellable {
|
|||
* @throws InterruptedException
|
||||
* if the calling thread is interrupted while waiting
|
||||
*/
|
||||
HttpClientConnection get(long timeout, TimeUnit tunit)
|
||||
HttpClientConnection get(long timeout, TimeUnit timeUnit)
|
||||
throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException;
|
||||
|
||||
}
|
||||
|
|
|
@ -111,36 +111,36 @@ public class EofSensorInputStream extends InputStream implements ConnectionRelea
|
|||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
int l = -1;
|
||||
int readLen = -1;
|
||||
|
||||
if (isReadAllowed()) {
|
||||
try {
|
||||
l = wrappedStream.read();
|
||||
checkEOF(l);
|
||||
readLen = wrappedStream.read();
|
||||
checkEOF(readLen);
|
||||
} catch (final IOException ex) {
|
||||
checkAbort();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
return readLen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(final byte[] b, final int off, final int len) throws IOException {
|
||||
int l = -1;
|
||||
int readLen = -1;
|
||||
|
||||
if (isReadAllowed()) {
|
||||
try {
|
||||
l = wrappedStream.read(b, off, len);
|
||||
checkEOF(l);
|
||||
readLen = wrappedStream.read(b, off, len);
|
||||
checkEOF(readLen);
|
||||
} catch (final IOException ex) {
|
||||
checkAbort();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
return l;
|
||||
return readLen;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -155,11 +155,11 @@ public interface HttpClientConnectionManager {
|
|||
* </p>
|
||||
*
|
||||
* @param idletime the idle time of connections to be closed
|
||||
* @param tunit the unit for the {@code idletime}
|
||||
* @param timeUnit the unit for the {@code idletime}
|
||||
*
|
||||
* @see #closeExpiredConnections()
|
||||
*/
|
||||
void closeIdleConnections(long idletime, TimeUnit tunit);
|
||||
void closeIdleConnections(long idletime, TimeUnit timeUnit);
|
||||
|
||||
/**
|
||||
* Closes all expired connections in the pool.
|
||||
|
|
|
@ -32,7 +32,6 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import javax.net.ssl.SSLSession;
|
||||
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.conn.routing.HttpRoute;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
@ -48,7 +47,7 @@ import org.apache.http.protocol.HttpContext;
|
|||
*/
|
||||
@Deprecated
|
||||
public interface ManagedClientConnection extends
|
||||
HttpClientConnection, HttpRoutedConnection, ManagedHttpClientConnection, ConnectionReleaseTrigger {
|
||||
HttpRoutedConnection, ManagedHttpClientConnection, ConnectionReleaseTrigger {
|
||||
|
||||
/**
|
||||
* Indicates whether this connection is secure.
|
||||
|
|
|
@ -103,16 +103,13 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
|||
private static HttpHost normalize(final HttpHost target) {
|
||||
if (target.getPort() >= 0 ) {
|
||||
return target;
|
||||
} else {
|
||||
final InetAddress address = target.getAddress();
|
||||
final String schemeName = target.getSchemeName();
|
||||
if (address != null) {
|
||||
return new HttpHost(address, getDefaultPort(schemeName), schemeName);
|
||||
} else {
|
||||
final String hostName = target.getHostName();
|
||||
return new HttpHost(hostName, getDefaultPort(schemeName), schemeName);
|
||||
}
|
||||
}
|
||||
final InetAddress address = target.getAddress();
|
||||
final String schemeName = target.getSchemeName();
|
||||
return address != null
|
||||
? new HttpHost(address, getDefaultPort(schemeName), schemeName)
|
||||
: new HttpHost(target.getHostName(), getDefaultPort(schemeName),
|
||||
schemeName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -238,11 +235,7 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
|||
Args.notNegative(hop, "Hop index");
|
||||
final int hopcount = getHopCount();
|
||||
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
|
||||
if (hop < hopcount - 1) {
|
||||
return this.proxyChain.get(hop);
|
||||
} else {
|
||||
return this.targetHost;
|
||||
}
|
||||
return hop < hopcount - 1 ? this.proxyChain.get(hop) : this.targetHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -298,9 +291,8 @@ public final class HttpRoute implements RouteInfo, Cloneable {
|
|||
LangUtils.equals(this.targetHost, that.targetHost) &&
|
||||
LangUtils.equals(this.localAddress, that.localAddress) &&
|
||||
LangUtils.equals(this.proxyChain, that.proxyChain);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -163,14 +163,11 @@ public final class Scheme {
|
|||
public final SocketFactory getSocketFactory() {
|
||||
if (this.socketFactory instanceof SchemeSocketFactoryAdaptor) {
|
||||
return ((SchemeSocketFactoryAdaptor) this.socketFactory).getFactory();
|
||||
} else {
|
||||
if (this.layered) {
|
||||
return new LayeredSocketFactoryAdaptor(
|
||||
(LayeredSchemeSocketFactory) this.socketFactory);
|
||||
} else {
|
||||
return new SocketFactoryAdaptor(this.socketFactory);
|
||||
}
|
||||
}
|
||||
return this.layered
|
||||
? new LayeredSocketFactoryAdaptor(
|
||||
(LayeredSchemeSocketFactory) this.socketFactory)
|
||||
: new SocketFactoryAdaptor(this.socketFactory);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -245,9 +242,8 @@ public final class Scheme {
|
|||
return this.name.equals(that.name)
|
||||
&& this.defaultPort == that.defaultPort
|
||||
&& this.layered == that.layered;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -88,11 +88,9 @@ class SchemeSocketFactoryAdaptor implements SchemeSocketFactory {
|
|||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof SchemeSocketFactoryAdaptor) {
|
||||
return this.factory.equals(((SchemeSocketFactoryAdaptor)obj).factory);
|
||||
} else {
|
||||
return this.factory.equals(obj);
|
||||
}
|
||||
return obj instanceof SchemeSocketFactoryAdaptor
|
||||
? this.factory.equals(((SchemeSocketFactoryAdaptor) obj).factory)
|
||||
: this.factory.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -85,11 +85,9 @@ class SocketFactoryAdaptor implements SocketFactory {
|
|||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof SocketFactoryAdaptor) {
|
||||
return this.factory.equals(((SocketFactoryAdaptor)obj).factory);
|
||||
} else {
|
||||
return this.factory.equals(obj);
|
||||
}
|
||||
return obj instanceof SocketFactoryAdaptor
|
||||
? this.factory.equals(((SocketFactoryAdaptor) obj).factory)
|
||||
: this.factory.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -214,9 +214,8 @@ public abstract class AbstractVerifier implements X509HostnameVerifier {
|
|||
match = normalizedHost.endsWith(normalizedIdentity.substring(1));
|
||||
}
|
||||
return match && (!strict || countDots(normalizedHost) == countDots(normalizedIdentity));
|
||||
} else {
|
||||
return normalizedHost.equals(normalizedIdentity);
|
||||
}
|
||||
return normalizedHost.equals(normalizedIdentity);
|
||||
}
|
||||
|
||||
private static boolean validCountryWildcard(final String parts[]) {
|
||||
|
|
|
@ -351,9 +351,8 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor
|
|||
sslsock.startHandshake();
|
||||
verifyHostname(sslsock, host.getHostName());
|
||||
return sock;
|
||||
} else {
|
||||
return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
|
||||
}
|
||||
return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -103,11 +103,7 @@ public final class PublicSuffixMatcher {
|
|||
return false;
|
||||
}
|
||||
final DomainType domainType = map.get(rule);
|
||||
if (domainType == null) {
|
||||
return false;
|
||||
} else {
|
||||
return expectedType == null || domainType.equals(expectedType);
|
||||
}
|
||||
return domainType == null ? false : expectedType == null || domainType.equals(expectedType);
|
||||
}
|
||||
|
||||
private boolean hasRule(final String rule, final DomainType expectedType) {
|
||||
|
|
|
@ -107,9 +107,8 @@ public final class CookieSpecRegistry implements Lookup<CookieSpecProvider> {
|
|||
final CookieSpecFactory factory = registeredSpecs.get(name.toLowerCase(Locale.ENGLISH));
|
||||
if (factory != null) {
|
||||
return factory.newInstance(params);
|
||||
} else {
|
||||
throw new IllegalStateException("Unsupported cookie spec: " + name);
|
||||
}
|
||||
throw new IllegalStateException("Unsupported cookie spec: " + name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -159,11 +159,7 @@ public abstract class AuthSchemeBase implements ContextAwareAuthScheme {
|
|||
@Override
|
||||
public String toString() {
|
||||
final String name = getSchemeName();
|
||||
if (name != null) {
|
||||
return name.toUpperCase(Locale.ROOT);
|
||||
} else {
|
||||
return super.toString();
|
||||
}
|
||||
return name != null ? name.toUpperCase(Locale.ROOT) : super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -152,11 +152,7 @@ public class DigestScheme extends RFC2617Scheme {
|
|||
@Override
|
||||
public boolean isComplete() {
|
||||
final String s = getParameter("stale");
|
||||
if ("true".equalsIgnoreCase(s)) {
|
||||
return false;
|
||||
} else {
|
||||
return this.complete;
|
||||
}
|
||||
return "true".equalsIgnoreCase(s) ? false : this.complete;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -120,11 +120,9 @@ public abstract class GGSSchemeBase extends AuthSchemeBase {
|
|||
}
|
||||
|
||||
final GSSContext gssContext = createGSSContext(manager, oid, serverName, gssCredential);
|
||||
if (input != null) {
|
||||
return gssContext.initSecContext(input, 0, input.length);
|
||||
} else {
|
||||
return gssContext.initSecContext(new byte[] {}, 0, 0);
|
||||
}
|
||||
return input != null
|
||||
? gssContext.initSecContext(input, 0, input.length)
|
||||
: gssContext.initSecContext(new byte[] {}, 0, 0);
|
||||
}
|
||||
|
||||
GSSContext createGSSContext(
|
||||
|
|
|
@ -79,21 +79,20 @@ public class HttpAuthenticator {
|
|||
authStrategy.authFailed(host, authState.getAuthScheme(), context);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
switch (authState.getState()) {
|
||||
case CHALLENGED:
|
||||
case HANDSHAKE:
|
||||
this.log.debug("Authentication succeeded");
|
||||
authState.setState(AuthProtocolState.SUCCESS);
|
||||
authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
|
||||
break;
|
||||
case SUCCESS:
|
||||
break;
|
||||
default:
|
||||
authState.setState(AuthProtocolState.UNCHALLENGED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
switch (authState.getState()) {
|
||||
case CHALLENGED:
|
||||
case HANDSHAKE:
|
||||
this.log.debug("Authentication succeeded");
|
||||
authState.setState(AuthProtocolState.SUCCESS);
|
||||
authStrategy.authSucceeded(host, authState.getAuthScheme(), context);
|
||||
break;
|
||||
case SUCCESS:
|
||||
break;
|
||||
default:
|
||||
authState.setState(AuthProtocolState.UNCHALLENGED);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean handleAuthChallenge(
|
||||
|
@ -141,14 +140,12 @@ public class HttpAuthenticator {
|
|||
authState.reset();
|
||||
authState.setState(AuthProtocolState.FAILURE);
|
||||
return false;
|
||||
} else {
|
||||
authState.setState(AuthProtocolState.HANDSHAKE);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
authState.reset();
|
||||
// Retry authentication with a different scheme
|
||||
authState.setState(AuthProtocolState.HANDSHAKE);
|
||||
return true;
|
||||
}
|
||||
authState.reset();
|
||||
// Retry authentication with a different scheme
|
||||
}
|
||||
}
|
||||
final Queue<AuthOption> authOptions = authStrategy.select(challenges, host, response, context);
|
||||
|
@ -159,9 +156,8 @@ public class HttpAuthenticator {
|
|||
authState.setState(AuthProtocolState.CHALLENGED);
|
||||
authState.update(authOptions);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
} catch (final MalformedChallengeException ex) {
|
||||
if (this.log.isWarnEnabled()) {
|
||||
this.log.warn("Malformed challenge: " + ex.getMessage());
|
||||
|
@ -209,9 +205,8 @@ public class HttpAuthenticator {
|
|||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
ensureAuthScheme(authScheme);
|
||||
}
|
||||
ensureAuthScheme(authScheme);
|
||||
}
|
||||
if (authScheme != null) {
|
||||
try {
|
||||
|
@ -235,11 +230,10 @@ public class HttpAuthenticator {
|
|||
final Credentials creds,
|
||||
final HttpRequest request,
|
||||
final HttpContext context) throws AuthenticationException {
|
||||
if (authScheme instanceof ContextAwareAuthScheme) {
|
||||
return ((ContextAwareAuthScheme) authScheme).authenticate(creds, request, context);
|
||||
} else {
|
||||
return authScheme.authenticate(creds, request);
|
||||
}
|
||||
return authScheme instanceof ContextAwareAuthScheme
|
||||
? ((ContextAwareAuthScheme) authScheme).authenticate(creds, request,
|
||||
context)
|
||||
: authScheme.authenticate(creds, request);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
targetInformation, peerServerCertificate, type1Message, type2Message).getResponse();
|
||||
}
|
||||
|
||||
private static int readULong(final byte[] src, final int index) throws NTLMEngineException {
|
||||
private static int readULong(final byte[] src, final int index) {
|
||||
if (src.length < index + 4) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -217,14 +217,14 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
| ((src[index + 2] & 0xff) << 16) | ((src[index + 3] & 0xff) << 24);
|
||||
}
|
||||
|
||||
private static int readUShort(final byte[] src, final int index) throws NTLMEngineException {
|
||||
private static int readUShort(final byte[] src, final int index) {
|
||||
if (src.length < index + 2) {
|
||||
return 0;
|
||||
}
|
||||
return (src[index] & 0xff) | ((src[index + 1] & 0xff) << 8);
|
||||
}
|
||||
|
||||
private static byte[] readSecurityBuffer(final byte[] src, final int index) throws NTLMEngineException {
|
||||
private static byte[] readSecurityBuffer(final byte[] src, final int index) {
|
||||
final int length = readUShort(src, index);
|
||||
final int offset = readULong(src, index + 4);
|
||||
if (src.length < offset + length) {
|
||||
|
@ -236,7 +236,7 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
}
|
||||
|
||||
/** Calculate a challenge block */
|
||||
private static byte[] makeRandomChallenge(final Random random) throws NTLMEngineException {
|
||||
private static byte[] makeRandomChallenge(final Random random) {
|
||||
final byte[] rval = new byte[8];
|
||||
synchronized (random) {
|
||||
random.nextBytes(rval);
|
||||
|
@ -245,7 +245,7 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
}
|
||||
|
||||
/** Calculate a 16-byte secondary key */
|
||||
private static byte[] makeSecondaryKey(final Random random) throws NTLMEngineException {
|
||||
private static byte[] makeSecondaryKey(final Random random) {
|
||||
final byte[] rval = new byte[16];
|
||||
synchronized (random) {
|
||||
random.nextBytes(rval);
|
||||
|
@ -747,8 +747,7 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
* @return The response (either NTLMv2 or LMv2, depending on the client
|
||||
* data).
|
||||
*/
|
||||
private static byte[] lmv2Response(final byte[] hash, final byte[] challenge, final byte[] clientData)
|
||||
throws NTLMEngineException {
|
||||
private static byte[] lmv2Response(final byte[] hash, final byte[] challenge, final byte[] clientData) {
|
||||
final HMACMD5 hmacMD5 = new HMACMD5(hash);
|
||||
hmacMD5.update(challenge);
|
||||
hmacMD5.update(clientData);
|
||||
|
@ -856,17 +855,17 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
sequenceNumber++;
|
||||
}
|
||||
|
||||
private byte[] encrypt( final byte[] data ) throws NTLMEngineException
|
||||
private byte[] encrypt( final byte[] data )
|
||||
{
|
||||
return rc4.update( data );
|
||||
}
|
||||
|
||||
private byte[] decrypt( final byte[] data ) throws NTLMEngineException
|
||||
private byte[] decrypt( final byte[] data )
|
||||
{
|
||||
return rc4.update( data );
|
||||
}
|
||||
|
||||
private byte[] computeSignature( final byte[] message ) throws NTLMEngineException
|
||||
private byte[] computeSignature( final byte[] message )
|
||||
{
|
||||
final byte[] sig = new byte[16];
|
||||
|
||||
|
@ -892,7 +891,7 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
return sig;
|
||||
}
|
||||
|
||||
private boolean validateSignature( final byte[] signature, final byte message[] ) throws NTLMEngineException
|
||||
private boolean validateSignature( final byte[] signature, final byte message[] )
|
||||
{
|
||||
final byte[] computedSignature = computeSignature( message );
|
||||
// log.info( "SSSSS validateSignature("+seqNumber+")\n"
|
||||
|
@ -1036,12 +1035,11 @@ final class NTLMEngineImpl implements NTLMEngine {
|
|||
{
|
||||
if ((flags & FLAG_REQUEST_UNICODE_ENCODING) == 0) {
|
||||
return DEFAULT_CHARSET;
|
||||
} else {
|
||||
if (UNICODE_LITTLE_UNMARKED == null) {
|
||||
throw new NTLMEngineException( "Unicode not supported" );
|
||||
}
|
||||
return UNICODE_LITTLE_UNMARKED;
|
||||
}
|
||||
if (UNICODE_LITTLE_UNMARKED == null) {
|
||||
throw new NTLMEngineException( "Unicode not supported" );
|
||||
}
|
||||
return UNICODE_LITTLE_UNMARKED;
|
||||
}
|
||||
|
||||
/** Strip dot suffix from a name */
|
||||
|
|
|
@ -90,9 +90,8 @@ public class BasicAuthCache implements AuthCache {
|
|||
return host;
|
||||
}
|
||||
return new HttpHost(host.getHostName(), port, host.getSchemeName());
|
||||
} else {
|
||||
return host;
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,9 +141,8 @@ public class BasicAuthCache implements AuthCache {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -138,11 +138,10 @@ public class DefaultHttpRequestRetryHandler implements HttpRequestRetryHandler {
|
|||
}
|
||||
if (this.nonRetriableClasses.contains(exception.getClass())) {
|
||||
return false;
|
||||
} else {
|
||||
for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
|
||||
if (rejectException.isInstance(exception)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (final Class<? extends IOException> rejectException : this.nonRetriableClasses) {
|
||||
if (rejectException.isInstance(exception)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final HttpClientContext clientContext = HttpClientContext.adapt(context);
|
||||
|
|
|
@ -226,11 +226,9 @@ public class DefaultRedirectStrategy implements RedirectStrategy {
|
|||
return new HttpGet(uri);
|
||||
} else {
|
||||
final int status = response.getStatusLine().getStatusCode();
|
||||
if (status == HttpStatus.SC_TEMPORARY_REDIRECT) {
|
||||
return RequestBuilder.copy(request).setUri(uri).build();
|
||||
} else {
|
||||
return new HttpGet(uri);
|
||||
}
|
||||
return status == HttpStatus.SC_TEMPORARY_REDIRECT
|
||||
? RequestBuilder.copy(request).setUri(uri).build()
|
||||
: new HttpGet(uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,9 +105,9 @@ public class EntityEnclosingRequestWrapper extends RequestWrapper
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
consumed = true;
|
||||
super.writeTo(outstream);
|
||||
super.writeTo(outStream);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -82,9 +82,8 @@ public class HttpRequestFutureTask<V> extends FutureTask<V> {
|
|||
public long endedTime() {
|
||||
if (isDone()) {
|
||||
return callable.getEnded();
|
||||
} else {
|
||||
throw new IllegalStateException("Task is not done yet");
|
||||
}
|
||||
throw new IllegalStateException("Task is not done yet");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -94,9 +93,8 @@ public class HttpRequestFutureTask<V> extends FutureTask<V> {
|
|||
public long requestDuration() {
|
||||
if (isDone()) {
|
||||
return endedTime() - startedTime();
|
||||
} else {
|
||||
throw new IllegalStateException("Task is not done yet");
|
||||
}
|
||||
throw new IllegalStateException("Task is not done yet");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,9 +103,8 @@ public class HttpRequestFutureTask<V> extends FutureTask<V> {
|
|||
public long taskDuration() {
|
||||
if (isDone()) {
|
||||
return endedTime() - scheduledTime();
|
||||
} else {
|
||||
throw new IllegalStateException("Task is not done yet");
|
||||
}
|
||||
throw new IllegalStateException("Task is not done yet");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -106,9 +106,8 @@ class HttpRequestTaskCallable<V> implements Callable<V> {
|
|||
metrics.getTasks().increment(started);
|
||||
metrics.getActiveConnections().decrementAndGet();
|
||||
}
|
||||
} else {
|
||||
throw new IllegalStateException("call has been cancelled for request " + request.getURI());
|
||||
}
|
||||
throw new IllegalStateException("call has been cancelled for request " + request.getURI());
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
|
|
|
@ -104,8 +104,8 @@ public final class IdleConnectionEvictor {
|
|||
return thread.isAlive();
|
||||
}
|
||||
|
||||
public void awaitTermination(final long time, final TimeUnit tunit) throws InterruptedException {
|
||||
thread.join((tunit != null ? tunit : TimeUnit.MILLISECONDS).toMillis(time));
|
||||
public void awaitTermination(final long time, final TimeUnit timeUnit) throws InterruptedException {
|
||||
thread.join((timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(time));
|
||||
}
|
||||
|
||||
static class DefaultThreadFactory implements ThreadFactory {
|
||||
|
|
|
@ -240,8 +240,8 @@ class InternalHttpClient extends CloseableHttpClient implements Configurable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
connManager.closeIdleConnections(idletime, tunit);
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
connManager.closeIdleConnections(idletime, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -150,8 +150,8 @@ class MinimalHttpClient extends CloseableHttpClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
connManager.closeIdleConnections(idletime, tunit);
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
connManager.closeIdleConnections(idletime, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -142,19 +142,13 @@ public class SystemDefaultCredentialsProvider implements CredentialsProvider {
|
|||
systemcreds.getUserName(),
|
||||
new String(systemcreds.getPassword()),
|
||||
null, domain);
|
||||
} else {
|
||||
if (AuthSchemes.NTLM.equalsIgnoreCase(authscope.getScheme())) {
|
||||
// Domain may be specified in a fully qualified user name
|
||||
return new NTCredentials(
|
||||
systemcreds.getUserName(),
|
||||
new String(systemcreds.getPassword()),
|
||||
null, null);
|
||||
} else {
|
||||
return new UsernamePasswordCredentials(
|
||||
systemcreds.getUserName(),
|
||||
new String(systemcreds.getPassword()));
|
||||
}
|
||||
}
|
||||
return AuthSchemes.NTLM.equalsIgnoreCase(authscope.getScheme())
|
||||
// Domain may be specified in a fully qualified user name
|
||||
? new NTCredentials(systemcreds.getUserName(),
|
||||
new String(systemcreds.getPassword()), null, null)
|
||||
: new UsernamePasswordCredentials(systemcreds.getUserName(),
|
||||
new String(systemcreds.getPassword()));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -200,7 +200,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
}
|
||||
|
||||
@Override
|
||||
public HttpClientConnection get(final long timeout, final TimeUnit tunit) {
|
||||
public HttpClientConnection get(final long timeout, final TimeUnit timeUnit) {
|
||||
return BasicHttpClientConnectionManager.this.getConnection(
|
||||
route, state);
|
||||
}
|
||||
|
@ -255,7 +255,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
public synchronized void releaseConnection(
|
||||
final HttpClientConnection conn,
|
||||
final Object state,
|
||||
final long keepalive, final TimeUnit tunit) {
|
||||
final long keepalive, final TimeUnit timeUnit) {
|
||||
Args.notNull(conn, "Connection");
|
||||
Asserts.check(conn == this.conn, "Connection not obtained from this manager");
|
||||
if (this.log.isDebugEnabled()) {
|
||||
|
@ -277,14 +277,14 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
if (this.log.isDebugEnabled()) {
|
||||
final String s;
|
||||
if (keepalive > 0) {
|
||||
s = "for " + keepalive + " " + tunit;
|
||||
s = "for " + keepalive + " " + timeUnit;
|
||||
} else {
|
||||
s = "indefinitely";
|
||||
}
|
||||
this.log.debug("Connection can be kept alive " + s);
|
||||
}
|
||||
if (keepalive > 0) {
|
||||
this.expiry = this.updated + tunit.toMillis(keepalive);
|
||||
this.expiry = this.updated + timeUnit.toMillis(keepalive);
|
||||
} else {
|
||||
this.expiry = Long.MAX_VALUE;
|
||||
}
|
||||
|
@ -343,13 +343,13 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
Args.notNull(tunit, "Time unit");
|
||||
public synchronized void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
Args.notNull(timeUnit, "Time unit");
|
||||
if (this.isShutdown.get()) {
|
||||
return;
|
||||
}
|
||||
if (!this.leased) {
|
||||
long time = tunit.toMillis(idletime);
|
||||
long time = timeUnit.toMillis(idletime);
|
||||
if (time < 0) {
|
||||
time = 0;
|
||||
}
|
||||
|
|
|
@ -49,21 +49,21 @@ class CPool extends AbstractConnPool<HttpRoute, ManagedHttpClientConnection, CPo
|
|||
|
||||
private final Log log = LogFactory.getLog(CPool.class);
|
||||
private final long timeToLive;
|
||||
private final TimeUnit tunit;
|
||||
private final TimeUnit timeUnit;
|
||||
|
||||
public CPool(
|
||||
final ConnFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
|
||||
final int defaultMaxPerRoute, final int maxTotal,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
super(connFactory, defaultMaxPerRoute, maxTotal);
|
||||
this.timeToLive = timeToLive;
|
||||
this.tunit = tunit;
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CPoolEntry createEntry(final HttpRoute route, final ManagedHttpClientConnection conn) {
|
||||
final String id = Long.toString(COUNTER.getAndIncrement());
|
||||
return new CPoolEntry(this.log, id, route, conn, this.timeToLive, this.tunit);
|
||||
return new CPoolEntry(this.log, id, route, conn, this.timeToLive, this.timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,8 +52,8 @@ class CPoolEntry extends PoolEntry<HttpRoute, ManagedHttpClientConnection> {
|
|||
final String id,
|
||||
final HttpRoute route,
|
||||
final ManagedHttpClientConnection conn,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
super(id, route, conn, timeToLive, tunit);
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
super(id, route, conn, timeToLive, timeUnit);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
|
|
|
@ -98,21 +98,13 @@ class CPoolProxy implements ManagedHttpClientConnection, HttpContext {
|
|||
@Override
|
||||
public boolean isOpen() {
|
||||
final CPoolEntry local = this.poolEntry;
|
||||
if (local != null) {
|
||||
return !local.isClosed();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return local != null ? !local.isClosed() : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStale() {
|
||||
final HttpClientConnection conn = getConnection();
|
||||
if (conn != null) {
|
||||
return conn.isStale();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return conn != null ? conn.isStale() : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -203,11 +195,7 @@ class CPoolProxy implements ManagedHttpClientConnection, HttpContext {
|
|||
@Override
|
||||
public Object getAttribute(final String id) {
|
||||
final ManagedHttpClientConnection conn = getValidConnection();
|
||||
if (conn instanceof HttpContext) {
|
||||
return ((HttpContext) conn).getAttribute(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return conn instanceof HttpContext ? ((HttpContext) conn).getAttribute(id) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -221,11 +209,7 @@ class CPoolProxy implements ManagedHttpClientConnection, HttpContext {
|
|||
@Override
|
||||
public Object removeAttribute(final String id) {
|
||||
final ManagedHttpClientConnection conn = getValidConnection();
|
||||
if (conn instanceof HttpContext) {
|
||||
return ((HttpContext) conn).removeAttribute(id);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return conn instanceof HttpContext ? ((HttpContext) conn).removeAttribute(id) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -153,11 +153,9 @@ public class DefaultHttpClientConnectionOperator implements HttpClientConnection
|
|||
} catch (final ConnectException ex) {
|
||||
if (last) {
|
||||
final String msg = ex.getMessage();
|
||||
if ("Connection timed out".equals(msg)) {
|
||||
throw new ConnectTimeoutException(ex, host, addresses);
|
||||
} else {
|
||||
throw new HttpHostConnectException(ex, host, addresses);
|
||||
}
|
||||
throw "Connection timed out".equals(msg)
|
||||
? new ConnectTimeoutException(ex, host, addresses)
|
||||
: new HttpHostConnectException(ex, host, addresses);
|
||||
}
|
||||
} catch (final NoRouteToHostException ex) {
|
||||
if (last) {
|
||||
|
|
|
@ -62,16 +62,16 @@ public class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnec
|
|||
|
||||
public DefaultManagedHttpClientConnection(
|
||||
final String id,
|
||||
final int buffersize,
|
||||
final int bufferSize,
|
||||
final int fragmentSizeHint,
|
||||
final CharsetDecoder chardecoder,
|
||||
final CharsetEncoder charencoder,
|
||||
final CharsetDecoder charDecoder,
|
||||
final CharsetEncoder charEncoder,
|
||||
final MessageConstraints constraints,
|
||||
final ContentLengthStrategy incomingContentStrategy,
|
||||
final ContentLengthStrategy outgoingContentStrategy,
|
||||
final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
|
||||
final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
|
||||
super(buffersize, fragmentSizeHint, chardecoder, charencoder,
|
||||
super(bufferSize, fragmentSizeHint, charDecoder, charEncoder,
|
||||
constraints, incomingContentStrategy, outgoingContentStrategy,
|
||||
requestWriterFactory, responseParserFactory);
|
||||
this.id = id;
|
||||
|
@ -80,8 +80,8 @@ public class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnec
|
|||
|
||||
public DefaultManagedHttpClientConnection(
|
||||
final String id,
|
||||
final int buffersize) {
|
||||
this(id, buffersize, buffersize, null, null, null, null, null, null, null);
|
||||
final int bufferSize) {
|
||||
this(id, bufferSize, bufferSize, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,11 +128,7 @@ public class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnec
|
|||
@Override
|
||||
public SSLSession getSSLSession() {
|
||||
final Socket socket = super.getSocket();
|
||||
if (socket instanceof SSLSocket) {
|
||||
return ((SSLSocket) socket).getSession();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return socket instanceof SSLSocket ? ((SSLSocket) socket).getSession() : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -92,11 +92,9 @@ public class DefaultRoutePlanner implements HttpRoutePlanner {
|
|||
target = host;
|
||||
}
|
||||
final boolean secure = target.getSchemeName().equalsIgnoreCase("https");
|
||||
if (proxy == null) {
|
||||
return new HttpRoute(target, local, secure);
|
||||
} else {
|
||||
return new HttpRoute(target, local, proxy, secure);
|
||||
}
|
||||
return proxy == null
|
||||
? new HttpRoute(target, local, secure)
|
||||
: new HttpRoute(target, local, proxy, secure);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -46,29 +46,29 @@ import org.apache.http.io.HttpMessageWriterFactory;
|
|||
class LoggingManagedHttpClientConnection extends DefaultManagedHttpClientConnection {
|
||||
|
||||
private final Log log;
|
||||
private final Log headerlog;
|
||||
private final Log headerLog;
|
||||
private final Wire wire;
|
||||
|
||||
public LoggingManagedHttpClientConnection(
|
||||
final String id,
|
||||
final Log log,
|
||||
final Log headerlog,
|
||||
final Log wirelog,
|
||||
final int buffersize,
|
||||
final Log headerLog,
|
||||
final Log wireLog,
|
||||
final int bufferSize,
|
||||
final int fragmentSizeHint,
|
||||
final CharsetDecoder chardecoder,
|
||||
final CharsetEncoder charencoder,
|
||||
final CharsetDecoder charDecoder,
|
||||
final CharsetEncoder charEncoder,
|
||||
final MessageConstraints constraints,
|
||||
final ContentLengthStrategy incomingContentStrategy,
|
||||
final ContentLengthStrategy outgoingContentStrategy,
|
||||
final HttpMessageWriterFactory<HttpRequest> requestWriterFactory,
|
||||
final HttpMessageParserFactory<HttpResponse> responseParserFactory) {
|
||||
super(id, buffersize, fragmentSizeHint, chardecoder, charencoder,
|
||||
super(id, bufferSize, fragmentSizeHint, charDecoder, charEncoder,
|
||||
constraints, incomingContentStrategy, outgoingContentStrategy,
|
||||
requestWriterFactory, responseParserFactory);
|
||||
this.log = log;
|
||||
this.headerlog = headerlog;
|
||||
this.wire = new Wire(wirelog, id);
|
||||
this.headerLog = headerLog;
|
||||
this.wire = new Wire(wireLog, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -118,22 +118,22 @@ class LoggingManagedHttpClientConnection extends DefaultManagedHttpClientConnect
|
|||
|
||||
@Override
|
||||
protected void onResponseReceived(final HttpResponse response) {
|
||||
if (response != null && this.headerlog.isDebugEnabled()) {
|
||||
this.headerlog.debug(getId() + " << " + response.getStatusLine().toString());
|
||||
if (response != null && this.headerLog.isDebugEnabled()) {
|
||||
this.headerLog.debug(getId() + " << " + response.getStatusLine().toString());
|
||||
final Header[] headers = response.getAllHeaders();
|
||||
for (final Header header : headers) {
|
||||
this.headerlog.debug(getId() + " << " + header.toString());
|
||||
this.headerLog.debug(getId() + " << " + header.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRequestSubmitted(final HttpRequest request) {
|
||||
if (request != null && this.headerlog.isDebugEnabled()) {
|
||||
this.headerlog.debug(getId() + " >> " + request.getRequestLine().toString());
|
||||
if (request != null && this.headerLog.isDebugEnabled()) {
|
||||
this.headerLog.debug(getId() + " >> " + request.getRequestLine().toString());
|
||||
final Header[] headers = request.getAllHeaders();
|
||||
for (final Header header : headers) {
|
||||
this.headerlog.debug(getId() + " >> " + header.toString());
|
||||
this.headerLog.debug(getId() + " >> " + header.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ public class ManagedHttpClientConnectionFactory
|
|||
public static final ManagedHttpClientConnectionFactory INSTANCE = new ManagedHttpClientConnectionFactory();
|
||||
|
||||
private final Log log = LogFactory.getLog(DefaultManagedHttpClientConnection.class);
|
||||
private final Log headerlog = LogFactory.getLog("org.apache.http.headers");
|
||||
private final Log wirelog = LogFactory.getLog("org.apache.http.wire");
|
||||
private final Log headerLog = LogFactory.getLog("org.apache.http.headers");
|
||||
private final Log wireLog = LogFactory.getLog("org.apache.http.wire");
|
||||
|
||||
private final HttpMessageWriterFactory<HttpRequest> requestWriterFactory;
|
||||
private final HttpMessageParserFactory<HttpResponse> responseParserFactory;
|
||||
|
@ -108,31 +108,31 @@ public class ManagedHttpClientConnectionFactory
|
|||
@Override
|
||||
public ManagedHttpClientConnection create(final HttpRoute route, final ConnectionConfig config) {
|
||||
final ConnectionConfig cconfig = config != null ? config : ConnectionConfig.DEFAULT;
|
||||
CharsetDecoder chardecoder = null;
|
||||
CharsetEncoder charencoder = null;
|
||||
CharsetDecoder charDecoder = null;
|
||||
CharsetEncoder charEncoder = null;
|
||||
final Charset charset = cconfig.getCharset();
|
||||
final CodingErrorAction malformedInputAction = cconfig.getMalformedInputAction() != null ?
|
||||
cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
|
||||
final CodingErrorAction unmappableInputAction = cconfig.getUnmappableInputAction() != null ?
|
||||
cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
|
||||
if (charset != null) {
|
||||
chardecoder = charset.newDecoder();
|
||||
chardecoder.onMalformedInput(malformedInputAction);
|
||||
chardecoder.onUnmappableCharacter(unmappableInputAction);
|
||||
charencoder = charset.newEncoder();
|
||||
charencoder.onMalformedInput(malformedInputAction);
|
||||
charencoder.onUnmappableCharacter(unmappableInputAction);
|
||||
charDecoder = charset.newDecoder();
|
||||
charDecoder.onMalformedInput(malformedInputAction);
|
||||
charDecoder.onUnmappableCharacter(unmappableInputAction);
|
||||
charEncoder = charset.newEncoder();
|
||||
charEncoder.onMalformedInput(malformedInputAction);
|
||||
charEncoder.onUnmappableCharacter(unmappableInputAction);
|
||||
}
|
||||
final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement());
|
||||
return new LoggingManagedHttpClientConnection(
|
||||
id,
|
||||
log,
|
||||
headerlog,
|
||||
wirelog,
|
||||
headerLog,
|
||||
wireLog,
|
||||
cconfig.getBufferSize(),
|
||||
cconfig.getFragmentSizeHint(),
|
||||
chardecoder,
|
||||
charencoder,
|
||||
charDecoder,
|
||||
charEncoder,
|
||||
cconfig.getMessageConstraints(),
|
||||
incomingContentStrategy,
|
||||
outgoingContentStrategy,
|
||||
|
|
|
@ -121,8 +121,8 @@ public class PoolingHttpClientConnectionManager
|
|||
this(getDefaultRegistry());
|
||||
}
|
||||
|
||||
public PoolingHttpClientConnectionManager(final long timeToLive, final TimeUnit tunit) {
|
||||
this(getDefaultRegistry(), null, null ,null, timeToLive, tunit);
|
||||
public PoolingHttpClientConnectionManager(final long timeToLive, final TimeUnit timeUnit) {
|
||||
this(getDefaultRegistry(), null, null ,null, timeToLive, timeUnit);
|
||||
}
|
||||
|
||||
public PoolingHttpClientConnectionManager(
|
||||
|
@ -159,11 +159,11 @@ public class PoolingHttpClientConnectionManager
|
|||
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
|
||||
final SchemePortResolver schemePortResolver,
|
||||
final DnsResolver dnsResolver,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
this(
|
||||
new DefaultHttpClientConnectionOperator(socketFactoryRegistry, schemePortResolver, dnsResolver),
|
||||
connFactory,
|
||||
timeToLive, tunit
|
||||
timeToLive, timeUnit
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -173,11 +173,11 @@ public class PoolingHttpClientConnectionManager
|
|||
public PoolingHttpClientConnectionManager(
|
||||
final HttpClientConnectionOperator httpClientConnectionOperator,
|
||||
final HttpConnectionFactory<HttpRoute, ManagedHttpClientConnection> connFactory,
|
||||
final long timeToLive, final TimeUnit tunit) {
|
||||
final long timeToLive, final TimeUnit timeUnit) {
|
||||
super();
|
||||
this.configData = new ConfigData();
|
||||
this.pool = new CPool(new InternalConnectionFactory(
|
||||
this.configData, connFactory), 2, 20, timeToLive, tunit);
|
||||
this.configData, connFactory), 2, 20, timeToLive, timeUnit);
|
||||
this.pool.setValidateAfterInactivity(2000);
|
||||
this.connectionOperator = Args.notNull(httpClientConnectionOperator, "HttpClientConnectionOperator");
|
||||
this.isShutDown = new AtomicBoolean(false);
|
||||
|
@ -275,8 +275,8 @@ public class PoolingHttpClientConnectionManager
|
|||
@Override
|
||||
public HttpClientConnection get(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
|
||||
final HttpClientConnection conn = leaseConnection(future, timeout, tunit);
|
||||
final TimeUnit timeUnit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
|
||||
final HttpClientConnection conn = leaseConnection(future, timeout, timeUnit);
|
||||
if (conn.isOpen()) {
|
||||
final HttpHost host;
|
||||
if (route.getProxyHost() != null) {
|
||||
|
@ -297,10 +297,10 @@ public class PoolingHttpClientConnectionManager
|
|||
protected HttpClientConnection leaseConnection(
|
||||
final Future<CPoolEntry> future,
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
|
||||
final TimeUnit timeUnit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException {
|
||||
final CPoolEntry entry;
|
||||
try {
|
||||
entry = future.get(timeout, tunit);
|
||||
entry = future.get(timeout, timeUnit);
|
||||
if (entry == null || future.isCancelled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ public class PoolingHttpClientConnectionManager
|
|||
public void releaseConnection(
|
||||
final HttpClientConnection managedConn,
|
||||
final Object state,
|
||||
final long keepalive, final TimeUnit tunit) {
|
||||
final long keepalive, final TimeUnit timeUnit) {
|
||||
Args.notNull(managedConn, "Managed connection");
|
||||
synchronized (managedConn) {
|
||||
final CPoolEntry entry = CPoolProxy.detach(managedConn);
|
||||
|
@ -328,7 +328,7 @@ public class PoolingHttpClientConnectionManager
|
|||
final ManagedHttpClientConnection conn = entry.getConnection();
|
||||
try {
|
||||
if (conn.isOpen()) {
|
||||
final TimeUnit effectiveUnit = tunit != null ? tunit : TimeUnit.MILLISECONDS;
|
||||
final TimeUnit effectiveUnit = timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS;
|
||||
entry.setState(state);
|
||||
entry.updateExpiry(keepalive, effectiveUnit);
|
||||
if (this.log.isDebugEnabled()) {
|
||||
|
@ -416,11 +416,11 @@ public class PoolingHttpClientConnectionManager
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idleTimeout, final TimeUnit tunit) {
|
||||
public void closeIdleConnections(final long idleTimeout, final TimeUnit timeUnit) {
|
||||
if (this.log.isDebugEnabled()) {
|
||||
this.log.debug("Closing connections idle longer than " + idleTimeout + " " + tunit);
|
||||
this.log.debug("Closing connections idle longer than " + idleTimeout + " " + timeUnit);
|
||||
}
|
||||
this.pool.closeIdle(idleTimeout, tunit);
|
||||
this.pool.closeIdle(idleTimeout, timeUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,11 +59,11 @@ public class Wire {
|
|||
this(log, "");
|
||||
}
|
||||
|
||||
private void wire(final String header, final InputStream instream)
|
||||
private void wire(final String header, final InputStream inStream)
|
||||
throws IOException {
|
||||
final StringBuilder buffer = new StringBuilder();
|
||||
int ch;
|
||||
while ((ch = instream.read()) != -1) {
|
||||
while ((ch = inStream.read()) != -1) {
|
||||
if (ch == 13) {
|
||||
buffer.append("[\\r]");
|
||||
} else if (ch == 10) {
|
||||
|
@ -93,16 +93,16 @@ public class Wire {
|
|||
return log.isDebugEnabled();
|
||||
}
|
||||
|
||||
public void output(final InputStream outstream)
|
||||
public void output(final InputStream outStream)
|
||||
throws IOException {
|
||||
Args.notNull(outstream, "Output");
|
||||
wire(">> ", outstream);
|
||||
Args.notNull(outStream, "Output");
|
||||
wire(">> ", outStream);
|
||||
}
|
||||
|
||||
public void input(final InputStream instream)
|
||||
public void input(final InputStream inStream)
|
||||
throws IOException {
|
||||
Args.notNull(instream, "Input");
|
||||
wire("<< ", instream);
|
||||
Args.notNull(inStream, "Input");
|
||||
wire("<< ", inStream);
|
||||
}
|
||||
|
||||
public void output(final byte[] b, final int off, final int len)
|
||||
|
|
|
@ -105,14 +105,14 @@ public class DefaultCookieSpec implements CookieSpec {
|
|||
final CookieOrigin origin) throws MalformedCookieException {
|
||||
Args.notNull(header, "Header");
|
||||
Args.notNull(origin, "Cookie origin");
|
||||
HeaderElement[] helems = header.getElements();
|
||||
HeaderElement[] hElems = header.getElements();
|
||||
boolean versioned = false;
|
||||
boolean netscape = false;
|
||||
for (final HeaderElement helem: helems) {
|
||||
if (helem.getParameterByName("version") != null) {
|
||||
for (final HeaderElement hElem: hElems) {
|
||||
if (hElem.getParameterByName("version") != null) {
|
||||
versioned = true;
|
||||
}
|
||||
if (helem.getParameterByName("expires") != null) {
|
||||
if (hElem.getParameterByName("expires") != null) {
|
||||
netscape = true;
|
||||
}
|
||||
}
|
||||
|
@ -128,23 +128,20 @@ public class DefaultCookieSpec implements CookieSpec {
|
|||
((FormattedHeader) header).getValuePos(),
|
||||
buffer.length());
|
||||
} else {
|
||||
final String s = header.getValue();
|
||||
if (s == null) {
|
||||
final String hValue = header.getValue();
|
||||
if (hValue == null) {
|
||||
throw new MalformedCookieException("Header value is null");
|
||||
}
|
||||
buffer = new CharArrayBuffer(s.length());
|
||||
buffer.append(s);
|
||||
buffer = new CharArrayBuffer(hValue.length());
|
||||
buffer.append(hValue);
|
||||
cursor = new ParserCursor(0, buffer.length());
|
||||
}
|
||||
helems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
|
||||
return netscapeDraft.parse(helems, origin);
|
||||
} else {
|
||||
if (SM.SET_COOKIE2.equals(header.getName())) {
|
||||
return strict.parse(helems, origin);
|
||||
} else {
|
||||
return obsoleteStrict.parse(helems, origin);
|
||||
}
|
||||
hElems = new HeaderElement[] { parser.parseHeader(buffer, cursor) };
|
||||
return netscapeDraft.parse(hElems, origin);
|
||||
}
|
||||
return SM.SET_COOKIE2.equals(header.getName())
|
||||
? strict.parse(hElems, origin)
|
||||
: obsoleteStrict.parse(hElems, origin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -169,14 +166,11 @@ public class DefaultCookieSpec implements CookieSpec {
|
|||
Args.notNull(cookie, "Cookie");
|
||||
Args.notNull(origin, "Cookie origin");
|
||||
if (cookie.getVersion() > 0) {
|
||||
if (cookie instanceof SetCookie2) {
|
||||
return strict.match(cookie, origin);
|
||||
} else {
|
||||
return obsoleteStrict.match(cookie, origin);
|
||||
}
|
||||
} else {
|
||||
return netscapeDraft.match(cookie, origin);
|
||||
return cookie instanceof SetCookie2
|
||||
? strict.match(cookie, origin)
|
||||
: obsoleteStrict.match(cookie, origin);
|
||||
}
|
||||
return netscapeDraft.match(cookie, origin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,14 +187,11 @@ public class DefaultCookieSpec implements CookieSpec {
|
|||
}
|
||||
}
|
||||
if (version > 0) {
|
||||
if (isSetCookie2) {
|
||||
return strict.formatCookies(cookies);
|
||||
} else {
|
||||
return obsoleteStrict.formatCookies(cookies);
|
||||
}
|
||||
} else {
|
||||
return netscapeDraft.formatCookies(cookies);
|
||||
return isSetCookie2
|
||||
? strict.formatCookies(cookies)
|
||||
: obsoleteStrict.formatCookies(cookies);
|
||||
}
|
||||
return netscapeDraft.formatCookies(cookies);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -205,10 +205,9 @@ public class LaxExpiresHandler extends AbstractCookieAttributeHandler implements
|
|||
final char current = buf.charAt(i);
|
||||
if (DELIMS.get(current)) {
|
||||
break;
|
||||
} else {
|
||||
pos++;
|
||||
dst.append(current);
|
||||
}
|
||||
pos++;
|
||||
dst.append(current);
|
||||
}
|
||||
cursor.updatePos(pos);
|
||||
}
|
||||
|
|
|
@ -143,11 +143,7 @@ public class RFC2109Spec extends CookieSpecBase {
|
|||
} else {
|
||||
cookieList = cookies;
|
||||
}
|
||||
if (this.oneHeader) {
|
||||
return doFormatOneHeader(cookieList);
|
||||
} else {
|
||||
return doFormatManyHeaders(cookieList);
|
||||
}
|
||||
return this.oneHeader ? doFormatOneHeader(cookieList) : doFormatManyHeaders(cookieList);
|
||||
}
|
||||
|
||||
private List<Header> doFormatOneHeader(final List<Cookie> cookies) {
|
||||
|
|
|
@ -64,7 +64,6 @@ public class RFC2965Spec extends RFC2109Spec {
|
|||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
*/
|
||||
public RFC2965Spec() {
|
||||
this(null, false);
|
||||
|
@ -222,7 +221,7 @@ public class RFC2965Spec extends RFC2109Spec {
|
|||
* @param origin origin where cookie is received from or being sent to.
|
||||
*/
|
||||
private static CookieOrigin adjustEffectiveHost(final CookieOrigin origin) {
|
||||
String host = origin.getHost();
|
||||
final String host = origin.getHost();
|
||||
|
||||
// Test if the host name appears to be a fully qualified DNS name,
|
||||
// IPv4 address or IPv6 address
|
||||
|
@ -234,16 +233,13 @@ public class RFC2965Spec extends RFC2109Spec {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (isLocalHost) {
|
||||
host += ".local";
|
||||
return new CookieOrigin(
|
||||
host,
|
||||
origin.getPort(),
|
||||
origin.getPath(),
|
||||
origin.isSecure());
|
||||
} else {
|
||||
return origin;
|
||||
}
|
||||
return isLocalHost
|
||||
? new CookieOrigin(
|
||||
host + ".local",
|
||||
origin.getPort(),
|
||||
origin.getPath(),
|
||||
origin.isSecure())
|
||||
: origin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,7 +56,7 @@ class ConnectionHolder implements ConnectionReleaseTrigger, Cancellable, Closeab
|
|||
private volatile boolean reusable;
|
||||
private volatile Object state;
|
||||
private volatile long validDuration;
|
||||
private volatile TimeUnit tunit;
|
||||
private volatile TimeUnit timeUnit;
|
||||
|
||||
public ConnectionHolder(
|
||||
final Log log,
|
||||
|
@ -85,10 +85,10 @@ class ConnectionHolder implements ConnectionReleaseTrigger, Cancellable, Closeab
|
|||
this.state = state;
|
||||
}
|
||||
|
||||
public void setValidFor(final long duration, final TimeUnit tunit) {
|
||||
public void setValidFor(final long duration, final TimeUnit timeUnit) {
|
||||
synchronized (this.managedConn) {
|
||||
this.validDuration = duration;
|
||||
this.tunit = tunit;
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ class ConnectionHolder implements ConnectionReleaseTrigger, Cancellable, Closeab
|
|||
synchronized (this.managedConn) {
|
||||
if (reusable) {
|
||||
this.manager.releaseConnection(this.managedConn,
|
||||
this.state, this.validDuration, this.tunit);
|
||||
this.state, this.validDuration, this.timeUnit);
|
||||
} else {
|
||||
try {
|
||||
this.managedConn.close();
|
||||
|
|
|
@ -116,9 +116,9 @@ class RequestEntityProxy implements HttpEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
consumed = true;
|
||||
original.writeTo(outstream);
|
||||
original.writeTo(outStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -94,10 +94,10 @@ class ResponseEntityProxy extends HttpEntityWrapper implements EofSensorWatcher
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
try {
|
||||
if (outstream != null) {
|
||||
this.wrappedEntity.writeTo(outstream);
|
||||
if (outStream != null) {
|
||||
this.wrappedEntity.writeTo(outStream);
|
||||
}
|
||||
releaseConnection();
|
||||
} catch (final IOException ex) {
|
||||
|
|
|
@ -203,13 +203,13 @@ public class TestCredentials {
|
|||
public void testUsernamePasswordCredentialsSerialization() throws Exception {
|
||||
final UsernamePasswordCredentials orig = new UsernamePasswordCredentials("name", "pwd");
|
||||
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
|
||||
outstream.writeObject(orig);
|
||||
outstream.close();
|
||||
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
||||
outStream.writeObject(orig);
|
||||
outStream.close();
|
||||
final byte[] raw = outbuffer.toByteArray();
|
||||
final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream instream = new ObjectInputStream(inbuffer);
|
||||
final UsernamePasswordCredentials clone = (UsernamePasswordCredentials) instream.readObject();
|
||||
final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
|
||||
final UsernamePasswordCredentials clone = (UsernamePasswordCredentials) inStream.readObject();
|
||||
Assert.assertEquals(orig, clone);
|
||||
}
|
||||
|
||||
|
@ -217,13 +217,13 @@ public class TestCredentials {
|
|||
public void testNTCredentialsSerialization() throws Exception {
|
||||
final NTCredentials orig = new NTCredentials("name", "pwd", "somehost", "domain");
|
||||
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
|
||||
outstream.writeObject(orig);
|
||||
outstream.close();
|
||||
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
||||
outStream.writeObject(orig);
|
||||
outStream.close();
|
||||
final byte[] raw = outbuffer.toByteArray();
|
||||
final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream instream = new ObjectInputStream(inbuffer);
|
||||
final NTCredentials clone = (NTCredentials) instream.readObject();
|
||||
final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
|
||||
final NTCredentials clone = (NTCredentials) inStream.readObject();
|
||||
Assert.assertEquals(orig, clone);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,8 +97,8 @@ public class TestDecompressingEntity {
|
|||
super(wrapped, new InputStreamFactory() {
|
||||
|
||||
@Override
|
||||
public InputStream create(final InputStream instream) throws IOException {
|
||||
return new CheckedInputStream(instream, checksum);
|
||||
public InputStream create(final InputStream inStream) throws IOException {
|
||||
return new CheckedInputStream(inStream, checksum);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.apache.http.entity.StringEntity;
|
|||
import org.apache.http.util.EntityUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class TestGZip {
|
||||
|
@ -71,7 +72,7 @@ public class TestGZip {
|
|||
@Test
|
||||
public void testCompressionIOExceptionLeavesOutputStreamOpen() throws Exception {
|
||||
final HttpEntity in = Mockito.mock(HttpEntity.class);
|
||||
Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(Mockito.<OutputStream>any());
|
||||
Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(Matchers.<OutputStream>any());
|
||||
final GzipCompressingEntity gzipe = new GzipCompressingEntity(in);
|
||||
final OutputStream out = Mockito.mock(OutputStream.class);
|
||||
try {
|
||||
|
|
|
@ -97,8 +97,8 @@ public class TestHttpRequestBase {
|
|||
|
||||
@Test(expected=CloneNotSupportedException.class)
|
||||
public void testCloneStreamingEntityEnclosingRequests() throws Exception {
|
||||
final ByteArrayInputStream instream = new ByteArrayInputStream(new byte[] {});
|
||||
final InputStreamEntity e2 = new InputStreamEntity(instream, -1);
|
||||
final ByteArrayInputStream inStream = new ByteArrayInputStream(new byte[] {});
|
||||
final InputStreamEntity e2 = new InputStreamEntity(inStream, -1);
|
||||
final HttpPost httppost = new HttpPost("http://host/path");
|
||||
httppost.setEntity(e2);
|
||||
httppost.clone();
|
||||
|
|
|
@ -57,6 +57,7 @@ import org.apache.http.protocol.HttpCoreContext;
|
|||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class TestRequestAddCookies {
|
||||
|
@ -402,7 +403,7 @@ public class TestRequestAddCookies {
|
|||
Assert.assertNotNull(headers2);
|
||||
Assert.assertEquals(0, headers2.length);
|
||||
|
||||
Mockito.verify(this.cookieStore, Mockito.times(1)).clearExpired(Mockito.<Date>any());
|
||||
Mockito.verify(this.cookieStore, Mockito.times(1)).clearExpired(Matchers.<Date>any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -66,22 +66,22 @@ public class TestHttpClientUtils {
|
|||
public void testCloseQuietlyResponseEntity() throws Exception {
|
||||
final HttpResponse response = Mockito.mock(HttpResponse.class);
|
||||
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||
final InputStream instream = Mockito.mock(InputStream.class);
|
||||
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
HttpClientUtils.closeQuietly(response);
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseQuietlyResponseIgnoreIOError() throws Exception {
|
||||
final HttpResponse response = Mockito.mock(HttpResponse.class);
|
||||
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||
final InputStream instream = Mockito.mock(InputStream.class);
|
||||
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.doThrow(new IOException()).when(instream).close();
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
Mockito.doThrow(new IOException()).when(inStream).close();
|
||||
HttpClientUtils.closeQuietly(response);
|
||||
}
|
||||
|
||||
|
@ -114,12 +114,12 @@ public class TestHttpClientUtils {
|
|||
public void testCloseQuietlyCloseableResponseEntity() throws Exception {
|
||||
final CloseableHttpResponse response = Mockito.mock(CloseableHttpResponse.class);
|
||||
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||
final InputStream instream = Mockito.mock(InputStream.class);
|
||||
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
HttpClientUtils.closeQuietly(response);
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
Mockito.verify(response).close();
|
||||
}
|
||||
|
||||
|
@ -127,10 +127,10 @@ public class TestHttpClientUtils {
|
|||
public void testCloseQuietlyCloseableResponseIgnoreIOError() throws Exception {
|
||||
final CloseableHttpResponse response = Mockito.mock(CloseableHttpResponse.class);
|
||||
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||
final InputStream instream = Mockito.mock(InputStream.class);
|
||||
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.doThrow(new IOException()).when(instream).close();
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
Mockito.doThrow(new IOException()).when(inStream).close();
|
||||
HttpClientUtils.closeQuietly(response);
|
||||
}
|
||||
|
||||
|
|
|
@ -37,15 +37,15 @@ import org.mockito.Mockito;
|
|||
@SuppressWarnings({"boxing","static-access"}) // test code
|
||||
public class TestEofSensorInputStream {
|
||||
|
||||
private InputStream instream;
|
||||
private InputStream inStream;
|
||||
private EofSensorWatcher eofwatcher;
|
||||
private EofSensorInputStream eofstream;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
instream = Mockito.mock(InputStream.class);
|
||||
inStream = Mockito.mock(InputStream.class);
|
||||
eofwatcher = Mockito.mock(EofSensorWatcher.class);
|
||||
eofstream = new EofSensorInputStream(instream, eofwatcher);
|
||||
eofstream = new EofSensorInputStream(inStream, eofwatcher);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -57,8 +57,8 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertTrue(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(instream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).streamClosed(instream);
|
||||
Mockito.verify(inStream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).streamClosed(inStream);
|
||||
|
||||
eofstream.close();
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertTrue(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(eofwatcher).streamClosed(instream);
|
||||
Mockito.verify(eofwatcher).streamClosed(inStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -87,8 +87,8 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertTrue(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(instream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).streamClosed(instream);
|
||||
Mockito.verify(inStream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).streamClosed(inStream);
|
||||
|
||||
eofstream.releaseConnection();
|
||||
}
|
||||
|
@ -102,8 +102,8 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertTrue(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(instream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).streamAbort(instream);
|
||||
Mockito.verify(inStream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).streamAbort(inStream);
|
||||
|
||||
eofstream.abortConnection();
|
||||
}
|
||||
|
@ -120,28 +120,28 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertTrue(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(eofwatcher).streamAbort(instream);
|
||||
Mockito.verify(eofwatcher).streamAbort(inStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(instream.read()).thenReturn(0, -1);
|
||||
Mockito.when(inStream.read()).thenReturn(0, -1);
|
||||
|
||||
Assert.assertEquals(0, eofstream.read());
|
||||
|
||||
Assert.assertFalse(eofstream.isSelfClosed());
|
||||
Assert.assertNotNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(eofwatcher, Mockito.never()).eofDetected(instream);
|
||||
Mockito.verify(eofwatcher, Mockito.never()).eofDetected(inStream);
|
||||
|
||||
Assert.assertEquals(-1, eofstream.read());
|
||||
|
||||
Assert.assertFalse(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(instream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).eofDetected(instream);
|
||||
Mockito.verify(inStream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).eofDetected(inStream);
|
||||
|
||||
Assert.assertEquals(-1, eofstream.read());
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ public class TestEofSensorInputStream {
|
|||
@Test
|
||||
public void testReadIOError() throws Exception {
|
||||
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(instream.read()).thenThrow(new IOException());
|
||||
Mockito.when(inStream.read()).thenThrow(new IOException());
|
||||
|
||||
try {
|
||||
eofstream.read();
|
||||
|
@ -159,13 +159,13 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertFalse(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(eofwatcher).streamAbort(instream);
|
||||
Mockito.verify(eofwatcher).streamAbort(inStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadByteArray() throws Exception {
|
||||
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
|
||||
Mockito.when(inStream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
|
||||
.thenReturn(1, -1);
|
||||
|
||||
final byte[] tmp = new byte[1];
|
||||
|
@ -175,15 +175,15 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertFalse(eofstream.isSelfClosed());
|
||||
Assert.assertNotNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(eofwatcher, Mockito.never()).eofDetected(instream);
|
||||
Mockito.verify(eofwatcher, Mockito.never()).eofDetected(inStream);
|
||||
|
||||
Assert.assertEquals(-1, eofstream.read(tmp));
|
||||
|
||||
Assert.assertFalse(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(instream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).eofDetected(instream);
|
||||
Mockito.verify(inStream, Mockito.times(1)).close();
|
||||
Mockito.verify(eofwatcher).eofDetected(inStream);
|
||||
|
||||
Assert.assertEquals(-1, eofstream.read(tmp));
|
||||
}
|
||||
|
@ -191,7 +191,7 @@ public class TestEofSensorInputStream {
|
|||
@Test
|
||||
public void testReadByteArrayIOError() throws Exception {
|
||||
Mockito.when(eofwatcher.eofDetected(Mockito.<InputStream>any())).thenReturn(Boolean.TRUE);
|
||||
Mockito.when(instream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
|
||||
Mockito.when(inStream.read(Mockito.<byte []>any(), Mockito.anyInt(), Mockito.anyInt()))
|
||||
.thenThrow(new IOException());
|
||||
|
||||
final byte[] tmp = new byte[1];
|
||||
|
@ -203,7 +203,7 @@ public class TestEofSensorInputStream {
|
|||
Assert.assertFalse(eofstream.isSelfClosed());
|
||||
Assert.assertNull(eofstream.getWrappedStream());
|
||||
|
||||
Mockito.verify(eofwatcher).streamAbort(instream);
|
||||
Mockito.verify(eofwatcher).streamAbort(inStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -85,11 +85,7 @@ public final class MockConnPoolControl implements ConnPoolControl<HttpRoute> {
|
|||
@Override
|
||||
public int getMaxPerRoute(final HttpRoute route) {
|
||||
final Integer max = this.maxPerHostMap.get(route);
|
||||
if (max != null) {
|
||||
return max.intValue();
|
||||
} else {
|
||||
return this.defaultMax;
|
||||
}
|
||||
return max != null ? max.intValue() : this.defaultMax;
|
||||
}
|
||||
|
||||
public void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
|
||||
|
|
|
@ -69,10 +69,10 @@ public class TestAbstractResponseHandler {
|
|||
@SuppressWarnings("boxing")
|
||||
@Test
|
||||
public void testUnsuccessfulResponse() throws Exception {
|
||||
final InputStream instream = Mockito.mock(InputStream.class);
|
||||
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
final StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "Not Found");
|
||||
final HttpResponse response = Mockito.mock(HttpResponse.class);
|
||||
Mockito.when(response.getStatusLine()).thenReturn(sl);
|
||||
|
@ -87,7 +87,7 @@ public class TestAbstractResponseHandler {
|
|||
Assert.assertEquals("Not Found", ex.getMessage());
|
||||
}
|
||||
Mockito.verify(entity).getContent();
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ public class TestBasicCookieStore {
|
|||
final BasicCookieStore store = new BasicCookieStore();
|
||||
store.addCookie(new BasicClientCookie("name1", "value1"));
|
||||
store.addCookies(new BasicClientCookie[] {new BasicClientCookie("name2", "value2")});
|
||||
List<Cookie> l = store.getCookies();
|
||||
Assert.assertNotNull(l);
|
||||
Assert.assertEquals(2, l.size());
|
||||
Assert.assertEquals("name1", l.get(0).getName());
|
||||
Assert.assertEquals("name2", l.get(1).getName());
|
||||
List<Cookie> list = store.getCookies();
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertEquals(2, list.size());
|
||||
Assert.assertEquals("name1", list.get(0).getName());
|
||||
Assert.assertEquals("name2", list.get(1).getName());
|
||||
store.clear();
|
||||
l = store.getCookies();
|
||||
Assert.assertNotNull(l);
|
||||
Assert.assertEquals(0, l.size());
|
||||
list = store.getCookies();
|
||||
Assert.assertNotNull(list);
|
||||
Assert.assertEquals(0, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -80,13 +80,13 @@ public class TestBasicCookieStore {
|
|||
orig.addCookie(new BasicClientCookie("name1", "value1"));
|
||||
orig.addCookie(new BasicClientCookie("name2", "value2"));
|
||||
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
|
||||
outstream.writeObject(orig);
|
||||
outstream.close();
|
||||
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
||||
outStream.writeObject(orig);
|
||||
outStream.close();
|
||||
final byte[] raw = outbuffer.toByteArray();
|
||||
final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream instream = new ObjectInputStream(inbuffer);
|
||||
final BasicCookieStore clone = (BasicCookieStore) instream.readObject();
|
||||
final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
|
||||
final BasicCookieStore clone = (BasicCookieStore) inStream.readObject();
|
||||
final List<Cookie> expected = orig.getCookies();
|
||||
final List<Cookie> clones = clone.getCookies();
|
||||
Assert.assertNotNull(expected);
|
||||
|
|
|
@ -61,10 +61,10 @@ public class TestBasicResponseHandler {
|
|||
|
||||
@Test
|
||||
public void testUnsuccessfulResponse() throws Exception {
|
||||
final InputStream instream = Mockito.mock(InputStream.class);
|
||||
final InputStream inStream = Mockito.mock(InputStream.class);
|
||||
final HttpEntity entity = Mockito.mock(HttpEntity.class);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
final StatusLine sl = new BasicStatusLine(HttpVersion.HTTP_1_1, 404, "Not Found");
|
||||
final HttpResponse response = Mockito.mock(HttpResponse.class);
|
||||
Mockito.when(response.getStatusLine()).thenReturn(sl);
|
||||
|
@ -79,7 +79,7 @@ public class TestBasicResponseHandler {
|
|||
Assert.assertEquals("Not Found", ex.getMessage());
|
||||
}
|
||||
Mockito.verify(entity).getContent();
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
|
|||
import org.apache.http.conn.HttpClientConnectionManager;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Matchers;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
/**
|
||||
|
@ -68,7 +69,7 @@ public class TestIdleConnectionEvictor {
|
|||
Thread.sleep(1000);
|
||||
|
||||
Mockito.verify(cm, Mockito.atLeast(1)).closeExpiredConnections();
|
||||
Mockito.verify(cm, Mockito.never()).closeIdleConnections(Mockito.anyLong(), Mockito.<TimeUnit>any());
|
||||
Mockito.verify(cm, Mockito.never()).closeIdleConnections(Matchers.anyLong(), Matchers.<TimeUnit>any());
|
||||
|
||||
Assert.assertTrue(connectionEvictor.isRunning());
|
||||
|
||||
|
|
|
@ -373,20 +373,19 @@ public class TestAbortHandling extends LocalServerTestBase {
|
|||
@Override
|
||||
public HttpClientConnection get(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
final TimeUnit timeUnit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
connLatch.countDown(); // notify waiter that we're getting a connection
|
||||
|
||||
// zero usually means sleep forever, but CountDownLatch doesn't interpret it that way.
|
||||
if(!awaitLatch.await(timeout > 0 ? timeout : Integer.MAX_VALUE, tunit)) {
|
||||
if(!awaitLatch.await(timeout > 0 ? timeout : Integer.MAX_VALUE, timeUnit)) {
|
||||
throw new ConnectionPoolTimeoutException();
|
||||
}
|
||||
|
||||
return Mockito.mock(HttpClientConnection.class);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
return super.requestConnection(route, state);
|
||||
}
|
||||
return super.requestConnection(route, state);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +400,7 @@ public class TestAbortHandling extends LocalServerTestBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit tunit) {
|
||||
public void closeIdleConnections(final long idletime, final TimeUnit timeUnit) {
|
||||
throw new UnsupportedOperationException("just a mockup");
|
||||
}
|
||||
|
||||
|
@ -411,7 +410,7 @@ public class TestAbortHandling extends LocalServerTestBase {
|
|||
}
|
||||
|
||||
public HttpClientConnection getConnection(final HttpRoute route,
|
||||
final long timeout, final TimeUnit tunit) {
|
||||
final long timeout, final TimeUnit timeUnit) {
|
||||
throw new UnsupportedOperationException("just a mockup");
|
||||
}
|
||||
|
||||
|
@ -433,11 +432,11 @@ public class TestAbortHandling extends LocalServerTestBase {
|
|||
@Override
|
||||
public HttpClientConnection get(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
final TimeUnit timeUnit) throws InterruptedException, ConnectionPoolTimeoutException {
|
||||
connLatch.countDown(); // notify waiter that we're getting a connection
|
||||
|
||||
// zero usually means sleep forever, but CountDownLatch doesn't interpret it that way.
|
||||
if(!awaitLatch.await(timeout > 0 ? timeout : Integer.MAX_VALUE, tunit)) {
|
||||
if(!awaitLatch.await(timeout > 0 ? timeout : Integer.MAX_VALUE, timeUnit)) {
|
||||
throw new ConnectionPoolTimeoutException();
|
||||
}
|
||||
|
||||
|
|
|
@ -178,10 +178,10 @@ public class TestConnectionAutoRelease extends LocalServerTestBase {
|
|||
|
||||
@Override
|
||||
public void writeTo(
|
||||
final OutputStream outstream) throws IOException {
|
||||
final OutputStream outStream) throws IOException {
|
||||
final byte[] tmp = new byte[5];
|
||||
outstream.write(tmp);
|
||||
outstream.flush();
|
||||
outStream.write(tmp);
|
||||
outStream.flush();
|
||||
|
||||
// do something comletely ugly in order to trigger
|
||||
// MalformedChunkCodingException
|
||||
|
|
|
@ -50,8 +50,8 @@ public class TestMalformedServerResponse extends LocalServerTestBase {
|
|||
|
||||
static class BrokenServerConnection extends DefaultBHttpServerConnection {
|
||||
|
||||
public BrokenServerConnection(final int buffersize) {
|
||||
super(buffersize);
|
||||
public BrokenServerConnection(final int bufferSize) {
|
||||
super(bufferSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -45,39 +45,39 @@ public class SessionInputBufferMock extends SessionInputBufferImpl {
|
|||
public static final int BUFFER_SIZE = 16;
|
||||
|
||||
public SessionInputBufferMock(
|
||||
final InputStream instream,
|
||||
final int buffersize,
|
||||
final InputStream inStream,
|
||||
final int bufferSize,
|
||||
final MessageConstraints constrains,
|
||||
final CharsetDecoder decoder) {
|
||||
super(new HttpTransportMetricsImpl(), buffersize, -1, constrains, decoder);
|
||||
bind(instream);
|
||||
super(new HttpTransportMetricsImpl(), bufferSize, -1, constrains, decoder);
|
||||
bind(inStream);
|
||||
}
|
||||
|
||||
public SessionInputBufferMock(
|
||||
final InputStream instream,
|
||||
final int buffersize) {
|
||||
this(instream, buffersize, null, null);
|
||||
final InputStream inStream,
|
||||
final int bufferSize) {
|
||||
this(inStream, bufferSize, null, null);
|
||||
}
|
||||
|
||||
public SessionInputBufferMock(
|
||||
final byte[] bytes,
|
||||
final int buffersize,
|
||||
final int bufferSize,
|
||||
final MessageConstraints constrains,
|
||||
final CharsetDecoder decoder) {
|
||||
this(new ByteArrayInputStream(bytes), buffersize, constrains, decoder);
|
||||
this(new ByteArrayInputStream(bytes), bufferSize, constrains, decoder);
|
||||
}
|
||||
|
||||
public SessionInputBufferMock(
|
||||
final byte[] bytes,
|
||||
final int buffersize,
|
||||
final int bufferSize,
|
||||
final MessageConstraints constrains) {
|
||||
this(new ByteArrayInputStream(bytes), buffersize, constrains, null);
|
||||
this(new ByteArrayInputStream(bytes), bufferSize, constrains, null);
|
||||
}
|
||||
|
||||
public SessionInputBufferMock(
|
||||
final byte[] bytes,
|
||||
final int buffersize) {
|
||||
this(new ByteArrayInputStream(bytes), buffersize);
|
||||
final int bufferSize) {
|
||||
this(new ByteArrayInputStream(bytes), bufferSize);
|
||||
}
|
||||
|
||||
public SessionInputBufferMock(
|
||||
|
|
|
@ -55,8 +55,8 @@ public class TestDefaultHttpResponseParser {
|
|||
"header2: value2\r\n" +
|
||||
"\r\n";
|
||||
|
||||
final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
|
||||
final SessionInputBuffer inBuffer = new SessionInputBufferMock(s, Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inBuffer);
|
||||
|
||||
final HttpResponse response = parser.parse();
|
||||
Assert.assertNotNull(response);
|
||||
|
@ -81,8 +81,8 @@ public class TestDefaultHttpResponseParser {
|
|||
"header2: value2\r\n" +
|
||||
"\r\n";
|
||||
|
||||
final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer) {
|
||||
final SessionInputBuffer inBuffer = new SessionInputBufferMock(s, Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inBuffer) {
|
||||
|
||||
@Override
|
||||
protected boolean reject(final CharArrayBuffer line, final int count) {
|
||||
|
@ -95,8 +95,8 @@ public class TestDefaultHttpResponseParser {
|
|||
|
||||
@Test(expected=NoHttpResponseException.class)
|
||||
public void testResponseParsingNoResponse() throws Exception {
|
||||
final SessionInputBuffer inbuffer = new SessionInputBufferMock("", Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
|
||||
final SessionInputBuffer inBuffer = new SessionInputBufferMock("", Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inBuffer);
|
||||
parser.parse();
|
||||
}
|
||||
|
||||
|
@ -107,8 +107,8 @@ public class TestDefaultHttpResponseParser {
|
|||
"garbage\r\n" +
|
||||
"more garbage\r\n" +
|
||||
"a lot more garbage\r\n";
|
||||
final SessionInputBuffer inbuffer = new SessionInputBufferMock(s, Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inbuffer);
|
||||
final SessionInputBuffer inBuffer = new SessionInputBufferMock(s, Consts.ASCII);
|
||||
final HttpMessageParser<HttpResponse> parser = new DefaultHttpResponseParser(inBuffer);
|
||||
parser.parse();
|
||||
}
|
||||
|
||||
|
|
|
@ -75,13 +75,13 @@ public class TestBasicClientCookie {
|
|||
orig.setPath("/");
|
||||
orig.setAttribute("attrib", "stuff");
|
||||
final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream();
|
||||
final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer);
|
||||
outstream.writeObject(orig);
|
||||
outstream.close();
|
||||
final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer);
|
||||
outStream.writeObject(orig);
|
||||
outStream.close();
|
||||
final byte[] raw = outbuffer.toByteArray();
|
||||
final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream instream = new ObjectInputStream(inbuffer);
|
||||
final BasicClientCookie clone = (BasicClientCookie) instream.readObject();
|
||||
final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw);
|
||||
final ObjectInputStream inStream = new ObjectInputStream(inBuffer);
|
||||
final BasicClientCookie clone = (BasicClientCookie) inStream.readObject();
|
||||
Assert.assertEquals(orig.getName(), clone.getName());
|
||||
Assert.assertEquals(orig.getValue(), clone.getValue());
|
||||
Assert.assertEquals(orig.getDomain(), clone.getDomain());
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue