- 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
4a9b00b509
commit
3aa9c1fd33
|
@ -32,6 +32,7 @@ import org.apache.hc.core5.util.Args;
|
|||
|
||||
public final class HttpCacheStorageEntry implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String key;
|
||||
private final HttpCacheEntry content;
|
||||
|
||||
|
|
|
@ -38,6 +38,8 @@ import java.io.Serializable;
|
|||
*/
|
||||
public abstract class Resource implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Returns resource content as a {@link InputStream}.
|
||||
*
|
||||
|
|
|
@ -33,6 +33,8 @@ import java.io.IOException;
|
|||
*/
|
||||
public class ResourceIOException extends IOException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public ResourceIOException(final String message) {
|
||||
super();
|
||||
}
|
||||
|
|
|
@ -396,11 +396,11 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler {
|
|||
final HttpEntity entity = backendResponse.getEntity();
|
||||
if (entity != null) {
|
||||
buf = new ByteArrayBuffer(1024);
|
||||
final InputStream instream = entity.getContent();
|
||||
final InputStream inStream = entity.getContent();
|
||||
final byte[] tmp = new byte[2048];
|
||||
long total = 0;
|
||||
int l;
|
||||
while ((l = instream.read(tmp)) != -1) {
|
||||
while ((l = inStream.read(tmp)) != -1) {
|
||||
buf.append(tmp, 0, l);
|
||||
total += l;
|
||||
if (total > cacheConfig.getMaxObjectSize()) {
|
||||
|
|
|
@ -99,13 +99,13 @@ class CombinedEntity implements HttpEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
try (InputStream instream = getContent()) {
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
try (InputStream inStream = getContent()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,9 +79,9 @@ public class FileResourceFactory implements ResourceFactory {
|
|||
final byte[] content, final int off, final int len) throws ResourceIOException {
|
||||
Args.notNull(requestId, "Request id");
|
||||
final File file = generateUniqueCacheFile(requestId);
|
||||
try (FileOutputStream outstream = new FileOutputStream(file)) {
|
||||
try (FileOutputStream outStream = new FileOutputStream(file)) {
|
||||
if (content != null) {
|
||||
outstream.write(content, off, len);
|
||||
outStream.write(content, off, len);
|
||||
}
|
||||
} catch (final IOException ex) {
|
||||
throw new ResourceIOException(ex.getMessage(), ex);
|
||||
|
|
|
@ -33,6 +33,8 @@ import org.apache.hc.client5.http.cache.ResourceIOException;
|
|||
*/
|
||||
class MemcachedOperationTimeoutException extends ResourceIOException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public MemcachedOperationTimeoutException(final Throwable cause) {
|
||||
super(cause != null ? cause.getMessage() : null, cause);
|
||||
}
|
||||
|
|
|
@ -359,12 +359,12 @@ public class Request {
|
|||
return body(new ByteArrayEntity(b, off, len, contentType));
|
||||
}
|
||||
|
||||
public Request bodyStream(final InputStream instream) {
|
||||
return body(new InputStreamEntity(instream, -1, null));
|
||||
public Request bodyStream(final InputStream inStream) {
|
||||
return body(new InputStreamEntity(inStream, -1, null));
|
||||
}
|
||||
|
||||
public Request bodyStream(final InputStream instream, final ContentType contentType) {
|
||||
return body(new InputStreamEntity(instream, -1, contentType));
|
||||
public Request bodyStream(final InputStream inStream, final ContentType contentType) {
|
||||
return body(new InputStreamEntity(inStream, -1, contentType));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -457,6 +457,8 @@ public abstract class AbstractHttpAsyncClientAuthentication<T extends CloseableH
|
|||
public AuthScheme create(final HttpContext context) {
|
||||
return new BasicScheme() {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "MyBasic";
|
||||
|
|
|
@ -57,8 +57,8 @@ public class ClientConnectionRelease {
|
|||
// If the response does not enclose an entity, there is no need
|
||||
// to bother about connection release
|
||||
if (entity != null) {
|
||||
try (InputStream instream = entity.getContent()) {
|
||||
instream.read();
|
||||
try (InputStream inStream = entity.getContent()) {
|
||||
inStream.read();
|
||||
// do something useful with the response
|
||||
} catch (final IOException ex) {
|
||||
// In case of an IOException the connection will be released
|
||||
|
|
|
@ -36,6 +36,7 @@ import org.apache.hc.core5.http.message.BasicHttpRequest;
|
|||
|
||||
public class ConfigurableHttpRequest extends BasicHttpRequest implements Configurable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private RequestConfig requestConfig;
|
||||
|
||||
public ConfigurableHttpRequest(final String method, final String path) {
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.apache.hc.core5.util.Args;
|
|||
|
||||
public final class SimpleHttpRequest extends ConfigurableHttpRequest {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private SimpleBody body;
|
||||
|
||||
public static SimpleHttpRequest copy(final HttpRequest original) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.apache.hc.core5.util.Args;
|
|||
|
||||
public final class SimpleHttpResponse extends BasicHttpResponse {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private SimpleBody body;
|
||||
|
||||
public SimpleHttpResponse(final int code) {
|
||||
|
|
|
@ -83,13 +83,13 @@ public class DecompressingEntity extends HttpEntityWrapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
Args.notNull(outstream, "Output stream");
|
||||
try (InputStream instream = getContent()) {
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
Args.notNull(outStream, "Output stream");
|
||||
try (InputStream inStream = getContent()) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,9 +71,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);
|
||||
super.writeTo(gzip);
|
||||
// Only close output stream if the wrapped entity has been
|
||||
// successfully written out
|
||||
|
|
|
@ -98,15 +98,15 @@ class MultipartFormEntity implements HttpEntity {
|
|||
} else if (this.contentLength > 25 * 1024) {
|
||||
throw new ContentTooLongException("Content length is too long: " + this.contentLength);
|
||||
}
|
||||
final ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
||||
writeTo(outstream);
|
||||
outstream.flush();
|
||||
return new ByteArrayInputStream(outstream.toByteArray());
|
||||
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
|
||||
writeTo(outStream);
|
||||
outStream.flush();
|
||||
return new ByteArrayInputStream(outStream.toByteArray());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(final OutputStream outstream) throws IOException {
|
||||
this.multipart.writeTo(outstream);
|
||||
public void writeTo(final OutputStream outStream) throws IOException {
|
||||
this.multipart.writeTo(outStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,11 +39,10 @@ public final class ConnPoolSupport {
|
|||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (object instanceof Identifiable) {
|
||||
return ((Identifiable) object).getId();
|
||||
} else {
|
||||
return object.getClass().getSimpleName() + "-" + Integer.toHexString(System.identityHashCode(object));
|
||||
}
|
||||
return object instanceof Identifiable
|
||||
? ((Identifiable) object).getId()
|
||||
: object.getClass().getSimpleName() + "-"
|
||||
+ Integer.toHexString(System.identityHashCode(object));
|
||||
}
|
||||
|
||||
public static String formatStats(
|
||||
|
|
|
@ -91,8 +91,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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,17 +49,17 @@ import org.slf4j.Logger;
|
|||
class LoggingIOSession implements TlsCapableIOSession {
|
||||
|
||||
private final Logger log;
|
||||
private final Wire wirelog;
|
||||
private final Wire wireLog;
|
||||
private final String id;
|
||||
private final TlsCapableIOSession session;
|
||||
private final ByteChannel channel;
|
||||
|
||||
public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wirelog) {
|
||||
public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wireLog) {
|
||||
super();
|
||||
this.session = session;
|
||||
this.id = id;
|
||||
this.log = log;
|
||||
this.wirelog = new Wire(wirelog, this.id);
|
||||
this.wireLog = new Wire(wireLog, this.id);
|
||||
this.channel = new LoggingByteChannel();
|
||||
}
|
||||
|
||||
|
@ -246,12 +246,12 @@ class LoggingIOSession implements TlsCapableIOSession {
|
|||
if (log.isDebugEnabled()) {
|
||||
log.debug(id + " " + session + ": " + bytesRead + " bytes read");
|
||||
}
|
||||
if (bytesRead > 0 && wirelog.isEnabled()) {
|
||||
if (bytesRead > 0 && wireLog.isEnabled()) {
|
||||
final ByteBuffer b = dst.duplicate();
|
||||
final int p = b.position();
|
||||
b.limit(p);
|
||||
b.position(p - bytesRead);
|
||||
wirelog.input(b);
|
||||
wireLog.input(b);
|
||||
}
|
||||
return bytesRead;
|
||||
}
|
||||
|
@ -262,12 +262,12 @@ class LoggingIOSession implements TlsCapableIOSession {
|
|||
if (log.isDebugEnabled()) {
|
||||
log.debug(id + " " + session + ": " + byteWritten + " bytes written");
|
||||
}
|
||||
if (byteWritten > 0 && wirelog.isEnabled()) {
|
||||
if (byteWritten > 0 && wireLog.isEnabled()) {
|
||||
final ByteBuffer b = src.duplicate();
|
||||
final int p = b.position();
|
||||
b.limit(p);
|
||||
b.position(p - byteWritten);
|
||||
wirelog.output(b);
|
||||
wireLog.output(b);
|
||||
}
|
||||
return byteWritten;
|
||||
}
|
||||
|
|
|
@ -53,11 +53,9 @@ public final class CloseableHttpResponse implements ClassicHttpResponse {
|
|||
if (response == null) {
|
||||
return null;
|
||||
}
|
||||
if (response instanceof CloseableHttpResponse) {
|
||||
return (CloseableHttpResponse) response;
|
||||
} else {
|
||||
return new CloseableHttpResponse(response, null);
|
||||
}
|
||||
return response instanceof CloseableHttpResponse
|
||||
? (CloseableHttpResponse) response
|
||||
: new CloseableHttpResponse(response, null);
|
||||
}
|
||||
|
||||
CloseableHttpResponse(final ClassicHttpResponse response, final ExecRuntime execRuntime) {
|
||||
|
|
|
@ -106,9 +106,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
|
||||
|
|
|
@ -92,10 +92,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) {
|
||||
super.writeTo(outstream);
|
||||
if (outStream != null) {
|
||||
super.writeTo(outStream);
|
||||
}
|
||||
releaseConnection();
|
||||
} catch (final IOException | RuntimeException ex) {
|
||||
|
|
|
@ -189,7 +189,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
@Override
|
||||
public ConnectionEndpoint get(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
try {
|
||||
return new InternalConnectionEndpoint(route, getConnection(route, state));
|
||||
} catch (final IOException ex) {
|
||||
|
@ -246,9 +246,8 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
private InternalConnectionEndpoint cast(final ConnectionEndpoint endpoint) {
|
||||
if (endpoint instanceof InternalConnectionEndpoint) {
|
||||
return (InternalConnectionEndpoint) endpoint;
|
||||
} else {
|
||||
throw new IllegalStateException("Unexpected endpoint class: " + endpoint.getClass());
|
||||
}
|
||||
throw new IllegalStateException("Unexpected endpoint class: " + endpoint.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -341,13 +340,13 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan
|
|||
}
|
||||
}
|
||||
|
||||
public synchronized void closeIdle(final long idletime, final TimeUnit tunit) {
|
||||
Args.notNull(tunit, "Time unit");
|
||||
public synchronized void closeIdle(final long idletime, final TimeUnit timeUnit) {
|
||||
Args.notNull(timeUnit, "Time unit");
|
||||
if (this.closed.get()) {
|
||||
return;
|
||||
}
|
||||
if (!this.leased) {
|
||||
long time = tunit.toMillis(idletime);
|
||||
long time = timeUnit.toMillis(idletime);
|
||||
if (time < 0) {
|
||||
time = 0;
|
||||
}
|
||||
|
|
|
@ -63,8 +63,8 @@ final class DefaultManagedHttpClientConnection
|
|||
extends DefaultBHttpClientConnection implements ManagedHttpClientConnection, Identifiable {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(DefaultManagedHttpClientConnection.class);
|
||||
private final Logger headerlog = LoggerFactory.getLogger("org.apache.hc.client5.http.headers");
|
||||
private final Logger wirelog = LoggerFactory.getLogger("org.apache.hc.client5.http.wire");
|
||||
private final Logger headerLog = LoggerFactory.getLogger("org.apache.hc.client5.http.headers");
|
||||
private final Logger wireLog = LoggerFactory.getLogger("org.apache.hc.client5.http.wire");
|
||||
|
||||
private final String id;
|
||||
private final AtomicBoolean closed;
|
||||
|
@ -73,14 +73,14 @@ final class DefaultManagedHttpClientConnection
|
|||
|
||||
public DefaultManagedHttpClientConnection(
|
||||
final String id,
|
||||
final CharsetDecoder chardecoder,
|
||||
final CharsetEncoder charencoder,
|
||||
final CharsetDecoder charDecoder,
|
||||
final CharsetEncoder charEncoder,
|
||||
final H1Config h1Config,
|
||||
final ContentLengthStrategy incomingContentStrategy,
|
||||
final ContentLengthStrategy outgoingContentStrategy,
|
||||
final HttpMessageWriterFactory<ClassicHttpRequest> requestWriterFactory,
|
||||
final HttpMessageParserFactory<ClassicHttpResponse> responseParserFactory) {
|
||||
super(h1Config, chardecoder, charencoder, incomingContentStrategy, outgoingContentStrategy, requestWriterFactory, responseParserFactory);
|
||||
super(h1Config, charDecoder, charEncoder, incomingContentStrategy, outgoingContentStrategy, requestWriterFactory, responseParserFactory);
|
||||
this.id = id;
|
||||
this.closed = new AtomicBoolean();
|
||||
}
|
||||
|
@ -152,28 +152,28 @@ final class DefaultManagedHttpClientConnection
|
|||
|
||||
@Override
|
||||
public void bind(final Socket socket) throws IOException {
|
||||
super.bind(this.wirelog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wirelog) : new SocketHolder(socket));
|
||||
super.bind(this.wireLog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wireLog) : new SocketHolder(socket));
|
||||
socketTimeout = socket.getSoTimeout();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResponseReceived(final ClassicHttpResponse response) {
|
||||
if (response != null && this.headerlog.isDebugEnabled()) {
|
||||
this.headerlog.debug(this.id + " << " + new StatusLine(response));
|
||||
if (response != null && this.headerLog.isDebugEnabled()) {
|
||||
this.headerLog.debug(this.id + " << " + new StatusLine(response));
|
||||
final Header[] headers = response.getAllHeaders();
|
||||
for (final Header header : headers) {
|
||||
this.headerlog.debug(this.id + " << " + header.toString());
|
||||
this.headerLog.debug(this.id + " << " + header.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRequestSubmitted(final ClassicHttpRequest request) {
|
||||
if (request != null && this.headerlog.isDebugEnabled()) {
|
||||
this.headerlog.debug(this.id + " >> " + new RequestLine(request));
|
||||
if (request != null && this.headerLog.isDebugEnabled()) {
|
||||
this.headerLog.debug(this.id + " >> " + new RequestLine(request));
|
||||
final Header[] headers = request.getAllHeaders();
|
||||
for (final Header header : headers) {
|
||||
this.headerlog.debug(this.id + " >> " + header.toString());
|
||||
this.headerLog.debug(this.id + " >> " + header.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,26 +108,26 @@ public class ManagedHttpClientConnectionFactory implements HttpConnectionFactory
|
|||
|
||||
@Override
|
||||
public ManagedHttpClientConnection createConnection(final Socket socket) throws IOException {
|
||||
CharsetDecoder chardecoder = null;
|
||||
CharsetEncoder charencoder = null;
|
||||
CharsetDecoder charDecoder = null;
|
||||
CharsetEncoder charEncoder = null;
|
||||
final Charset charset = this.charCodingConfig.getCharset();
|
||||
final CodingErrorAction malformedInputAction = this.charCodingConfig.getMalformedInputAction() != null ?
|
||||
this.charCodingConfig.getMalformedInputAction() : CodingErrorAction.REPORT;
|
||||
final CodingErrorAction unmappableInputAction = this.charCodingConfig.getUnmappableInputAction() != null ?
|
||||
this.charCodingConfig.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());
|
||||
final DefaultManagedHttpClientConnection conn = new DefaultManagedHttpClientConnection(
|
||||
id,
|
||||
chardecoder,
|
||||
charencoder,
|
||||
charDecoder,
|
||||
charEncoder,
|
||||
h1Config,
|
||||
incomingContentStrategy,
|
||||
outgoingContentStrategy,
|
||||
|
|
|
@ -264,13 +264,13 @@ public class PoolingHttpClientConnectionManager
|
|||
@Override
|
||||
public synchronized ConnectionEndpoint get(
|
||||
final long timeout,
|
||||
final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException {
|
||||
if (this.endpoint != null) {
|
||||
return this.endpoint;
|
||||
}
|
||||
final PoolEntry<HttpRoute, ManagedHttpClientConnection> poolEntry;
|
||||
try {
|
||||
poolEntry = leaseFuture.get(timeout, tunit);
|
||||
poolEntry = leaseFuture.get(timeout, timeUnit);
|
||||
if (poolEntry == null || leaseFuture.isCancelled()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public interface LeaseRequest 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 LeaseRequest extends Cancellable {
|
|||
* @throws InterruptedException
|
||||
* if the calling thread is interrupted while waiting
|
||||
*/
|
||||
ConnectionEndpoint get(long timeout, TimeUnit tunit)
|
||||
ConnectionEndpoint get(long timeout, TimeUnit timeUnit)
|
||||
throws InterruptedException, ExecutionException, TimeoutException;
|
||||
|
||||
}
|
|
@ -172,13 +172,13 @@ public class TestCredentials {
|
|||
public void testUsernamePasswordCredentialsSerialization() throws Exception {
|
||||
final UsernamePasswordCredentials orig = new UsernamePasswordCredentials("name","pwd".toCharArray());
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -186,13 +186,13 @@ public class TestCredentials {
|
|||
public void testNTCredentialsSerialization() throws Exception {
|
||||
final NTCredentials orig = new NTCredentials("name","pwd".toCharArray(), "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);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
@ -65,10 +65,10 @@ public class TestAbstractHttpClientResponseHandler {
|
|||
@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 ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
|
||||
Mockito.when(response.getCode()).thenReturn(404);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
|
@ -81,7 +81,7 @@ public class TestAbstractHttpClientResponseHandler {
|
|||
Assert.assertEquals(404, ex.getStatusCode());
|
||||
}
|
||||
Mockito.verify(entity).getContent();
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,10 +57,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 ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class);
|
||||
Mockito.when(response.getCode()).thenReturn(404);
|
||||
Mockito.when(response.getEntity()).thenReturn(entity);
|
||||
|
@ -73,7 +73,7 @@ public class TestBasicResponseHandler {
|
|||
Assert.assertEquals(404, ex.getStatusCode());
|
||||
}
|
||||
Mockito.verify(entity).getContent();
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -234,9 +234,9 @@ public class TestConnectExec {
|
|||
final ClassicHttpRequest request = new HttpGet("http://bar/test");
|
||||
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?");
|
||||
response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, "Basic realm=test");
|
||||
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
response1.setEntity(EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build());
|
||||
final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
|
||||
|
||||
|
@ -264,7 +264,7 @@ public class TestConnectExec {
|
|||
exec.execute(request, scope, execChain);
|
||||
|
||||
Mockito.verify(execRuntime).connect(context);
|
||||
Mockito.verify(instream1).close();
|
||||
Mockito.verify(inStream1).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -274,9 +274,9 @@ public class TestConnectExec {
|
|||
final ClassicHttpRequest request = new HttpGet("http://bar/test");
|
||||
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?");
|
||||
response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, "Basic realm=test");
|
||||
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
response1.setEntity(EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build());
|
||||
final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
|
||||
|
||||
|
@ -304,7 +304,7 @@ public class TestConnectExec {
|
|||
exec.execute(request, scope, execChain);
|
||||
|
||||
Mockito.verify(execRuntime).connect(context);
|
||||
Mockito.verify(instream1, Mockito.never()).close();
|
||||
Mockito.verify(inStream1, Mockito.never()).close();
|
||||
Mockito.verify(execRuntime).disconnect();
|
||||
}
|
||||
|
||||
|
|
|
@ -214,14 +214,14 @@ public class TestProtocolExec {
|
|||
final ClassicHttpRequest request = new HttpGet("http://foo/test");
|
||||
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
|
||||
response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
response1.setEntity(EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build());
|
||||
final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
|
||||
final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
|
||||
final InputStream inStream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
|
||||
response2.setEntity(EntityBuilder.create()
|
||||
.setStream(instream2)
|
||||
.setStream(inStream2)
|
||||
.build());
|
||||
|
||||
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
|
@ -240,8 +240,8 @@ public class TestProtocolExec {
|
|||
final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context);
|
||||
final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain);
|
||||
Mockito.verify(chain, Mockito.times(2)).proceed(request, scope);
|
||||
Mockito.verify(instream1).close();
|
||||
Mockito.verify(instream2, Mockito.never()).close();
|
||||
Mockito.verify(inStream1).close();
|
||||
Mockito.verify(inStream2, Mockito.never()).close();
|
||||
|
||||
Assert.assertNotNull(finalResponse);
|
||||
Assert.assertEquals(200, finalResponse.getCode());
|
||||
|
@ -253,14 +253,14 @@ public class TestProtocolExec {
|
|||
final ClassicHttpRequest request = new HttpGet("http://foo/test");
|
||||
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
|
||||
response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
response1.setEntity(EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build());
|
||||
final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK");
|
||||
final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
|
||||
final InputStream inStream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4}));
|
||||
response2.setEntity(EntityBuilder.create()
|
||||
.setStream(instream2)
|
||||
.setStream(inStream2)
|
||||
.build());
|
||||
|
||||
final HttpClientContext context = new HttpClientContext();
|
||||
|
@ -287,7 +287,7 @@ public class TestProtocolExec {
|
|||
final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain);
|
||||
Mockito.verify(chain, Mockito.times(2)).proceed(request, scope);
|
||||
Mockito.verify(execRuntime).disconnect();
|
||||
Mockito.verify(instream2, Mockito.never()).close();
|
||||
Mockito.verify(inStream2, Mockito.never()).close();
|
||||
|
||||
Assert.assertNotNull(finalResponse);
|
||||
Assert.assertEquals(200, finalResponse.getCode());
|
||||
|
@ -299,15 +299,15 @@ public class TestProtocolExec {
|
|||
final HttpRoute route = new HttpRoute(target);
|
||||
final HttpClientContext context = new HttpClientContext();
|
||||
final HttpPost request = new HttpPost("http://foo/test");
|
||||
final InputStream instream0 = new ByteArrayInputStream(new byte[] {1, 2, 3});
|
||||
final InputStream inStream0 = new ByteArrayInputStream(new byte[] {1, 2, 3});
|
||||
request.setEntity(EntityBuilder.create()
|
||||
.setStream(instream0)
|
||||
.setStream(inStream0)
|
||||
.build());
|
||||
final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?");
|
||||
response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test");
|
||||
final InputStream instream1 = new ByteArrayInputStream(new byte[] {1, 2, 3});
|
||||
final InputStream inStream1 = new ByteArrayInputStream(new byte[] {1, 2, 3});
|
||||
response1.setEntity(EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build());
|
||||
|
||||
final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
||||
|
|
|
@ -99,15 +99,15 @@ public class TestRedirectExec {
|
|||
final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));
|
||||
final URI redirect = new URI("http://localhost:80/redirect");
|
||||
response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());
|
||||
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final HttpEntity entity1 = EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build();
|
||||
response1.setEntity(entity1);
|
||||
final ClassicHttpResponse response2 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_OK));
|
||||
final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final HttpEntity entity2 = EntityBuilder.create()
|
||||
.setStream(instream2)
|
||||
.setStream(inStream2)
|
||||
.build();
|
||||
response2.setEntity(entity2);
|
||||
|
||||
|
@ -130,9 +130,9 @@ public class TestRedirectExec {
|
|||
Assert.assertSame(request, allValues.get(0));
|
||||
|
||||
Mockito.verify(response1, Mockito.times(1)).close();
|
||||
Mockito.verify(instream1, Mockito.times(2)).close();
|
||||
Mockito.verify(inStream1, Mockito.times(2)).close();
|
||||
Mockito.verify(response2, Mockito.never()).close();
|
||||
Mockito.verify(instream2, Mockito.never()).close();
|
||||
Mockito.verify(inStream2, Mockito.never()).close();
|
||||
}
|
||||
|
||||
@Test(expected = RedirectException.class)
|
||||
|
@ -332,9 +332,9 @@ public class TestRedirectExec {
|
|||
final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY));
|
||||
final URI redirect = new URI("http://localhost:80/redirect");
|
||||
response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString());
|
||||
final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3}));
|
||||
final HttpEntity entity1 = EntityBuilder.create()
|
||||
.setStream(instream1)
|
||||
.setStream(inStream1)
|
||||
.build();
|
||||
response1.setEntity(entity1);
|
||||
Mockito.when(chain.proceed(
|
||||
|
@ -349,7 +349,7 @@ public class TestRedirectExec {
|
|||
try {
|
||||
redirectExec.execute(request, scope, chain);
|
||||
} catch (final Exception ex) {
|
||||
Mockito.verify(instream1, Mockito.times(2)).close();
|
||||
Mockito.verify(inStream1, Mockito.times(2)).close();
|
||||
Mockito.verify(response1).close();
|
||||
throw ex;
|
||||
}
|
||||
|
|
|
@ -42,16 +42,16 @@ import org.mockito.Mockito;
|
|||
@SuppressWarnings("boxing") // test code
|
||||
public class TestResponseEntityWrapper {
|
||||
|
||||
private InputStream instream;
|
||||
private InputStream inStream;
|
||||
private HttpEntity entity;
|
||||
private ExecRuntime execRuntime;
|
||||
private ResponseEntityProxy wrapper;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
instream = Mockito.mock(InputStream.class);
|
||||
inStream = Mockito.mock(InputStream.class);
|
||||
entity = Mockito.mock(HttpEntity.class);
|
||||
Mockito.when(entity.getContent()).thenReturn(instream);
|
||||
Mockito.when(entity.getContent()).thenReturn(inStream);
|
||||
execRuntime = Mockito.mock(ExecRuntime.class);
|
||||
wrapper = new ResponseEntityProxy(entity, execRuntime);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ public class TestResponseEntityWrapper {
|
|||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
EntityUtils.consume(wrapper);
|
||||
|
||||
Mockito.verify(instream, Mockito.times(1)).close();
|
||||
Mockito.verify(inStream, Mockito.times(1)).close();
|
||||
Mockito.verify(execRuntime).releaseConnection();
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class TestResponseEntityWrapper {
|
|||
public void testReusableEntityStreamClosedIOError() throws Exception {
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
Mockito.doThrow(new IOException()).when(instream).close();
|
||||
Mockito.doThrow(new IOException()).when(inStream).close();
|
||||
try {
|
||||
EntityUtils.consume(wrapper);
|
||||
Assert.fail("IOException expected");
|
||||
|
@ -84,28 +84,28 @@ public class TestResponseEntityWrapper {
|
|||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionAcquired()).thenReturn(false);
|
||||
Mockito.doThrow(new SocketException()).when(instream).close();
|
||||
Mockito.doThrow(new SocketException()).when(inStream).close();
|
||||
EntityUtils.consume(wrapper);
|
||||
Mockito.verify(execRuntime).discardConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReusableEntityWriteTo() throws Exception {
|
||||
final OutputStream outstream = Mockito.mock(OutputStream.class);
|
||||
final OutputStream outStream = Mockito.mock(OutputStream.class);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
wrapper.writeTo(outstream);
|
||||
wrapper.writeTo(outStream);
|
||||
Mockito.verify(execRuntime).releaseConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReusableEntityWriteToIOError() throws Exception {
|
||||
final OutputStream outstream = Mockito.mock(OutputStream.class);
|
||||
final OutputStream outStream = Mockito.mock(OutputStream.class);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
Mockito.doThrow(new IOException()).when(entity).writeTo(outstream);
|
||||
Mockito.doThrow(new IOException()).when(entity).writeTo(outStream);
|
||||
try {
|
||||
wrapper.writeTo(outstream);
|
||||
wrapper.writeTo(outStream);
|
||||
Assert.fail("IOException expected");
|
||||
} catch (final IOException ex) {
|
||||
}
|
||||
|
@ -115,21 +115,21 @@ public class TestResponseEntityWrapper {
|
|||
|
||||
@Test
|
||||
public void testReusableEntityEndOfStream() throws Exception {
|
||||
Mockito.when(instream.read()).thenReturn(-1);
|
||||
Mockito.when(inStream.read()).thenReturn(-1);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
final InputStream content = wrapper.getContent();
|
||||
Assert.assertEquals(-1, content.read());
|
||||
Mockito.verify(instream).close();
|
||||
Mockito.verify(inStream).close();
|
||||
Mockito.verify(execRuntime).releaseConnection();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReusableEntityEndOfStreamIOError() throws Exception {
|
||||
Mockito.when(instream.read()).thenReturn(-1);
|
||||
Mockito.when(inStream.read()).thenReturn(-1);
|
||||
Mockito.when(entity.isStreaming()).thenReturn(true);
|
||||
Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true);
|
||||
Mockito.doThrow(new IOException()).when(instream).close();
|
||||
Mockito.doThrow(new IOException()).when(inStream).close();
|
||||
final InputStream content = wrapper.getContent();
|
||||
try {
|
||||
content.read();
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
@ -69,9 +69,9 @@ public class TestBasicCookieStore {
|
|||
c.add(Calendar.DAY_OF_YEAR, -10);
|
||||
cookie.setExpiryDate(c.getTime());
|
||||
store.addCookie(cookie);
|
||||
final List<Cookie> l = store.getCookies();
|
||||
Assert.assertNotNull(l);
|
||||
Assert.assertEquals(0, l.size());
|
||||
final List<Cookie> 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);
|
||||
|
|
Loading…
Reference in New Issue