Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,8 @@ static File makeTestFileObject(final String testFileName) {
static void saveEntryToFile(final HttpCacheEntrySerializer<byte[]> serializer, final HttpCacheStorageEntry httpCacheStorageEntry, final File outFile) throws Exception {
final byte[] bytes = serializer.serialize(httpCacheStorageEntry);

OutputStream out = null;
try {
out = new FileOutputStream(outFile);
try (OutputStream out = new FileOutputStream(outFile)) {
out.write(bytes);
} finally {
if (out != null) {
out.close();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,8 @@ private static void assertIsAllowedClassNameFalse(final String className) {
private byte[] serializeProhibitedObject() throws IOException {
final BigDecimal bigDecimal = new BigDecimal("1000.00");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
try {
try (ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(bigDecimal);
} finally {
oos.close();
}
return baos.toByteArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ public void testSerializeWithHTTPException() throws Exception {
final HttpCacheStorageEntry testEntry = cacheObjectValues.toEntry();

final HttpByteArrayCacheEntrySerializer testSerializer = new HttpByteArrayCacheEntrySerializer() {
@Override
protected AbstractMessageWriter<SimpleHttpResponse> makeHttpResponseWriter(final SessionOutputBuffer outputBuffer) {
return throwyHttpWriter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.SocketTimeoutException;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.Random;
Expand Down Expand Up @@ -1380,9 +1381,7 @@ public void test206ResponseIsNotCombinedWithPreviousContentIfETagDoesNotMatch()
resp1.setHeader("Cache-Control", "max-age=3600");
resp1.setHeader("ETag", "\"etag1\"");
final byte[] bytes1 = new byte[128];
for (int i = 0; i < bytes1.length; i++) {
bytes1[i] = (byte) 1;
}
Arrays.fill(bytes1, (byte) 1);
resp1.setEntity(new ByteArrayEntity(bytes1, null));

final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
Expand All @@ -1397,9 +1396,7 @@ public void test206ResponseIsNotCombinedWithPreviousContentIfETagDoesNotMatch()
resp2.setHeader("ETag", "\"etag2\"");
resp2.setHeader("Content-Range", "bytes 0-50/128");
final byte[] bytes2 = new byte[51];
for (int i = 0; i < bytes2.length; i++) {
bytes2[i] = (byte) 2;
}
Arrays.fill(bytes2, (byte) 2);
resp2.setEntity(new ByteArrayEntity(bytes2, null));

final Date inTwoSeconds = new Date(now.getTime() + 2000L);
Expand All @@ -1409,9 +1406,7 @@ public void test206ResponseIsNotCombinedWithPreviousContentIfETagDoesNotMatch()
resp3.setHeader("Cache-Control", "max-age=3600");
resp3.setHeader("ETag", "\"etag2\"");
final byte[] bytes3 = new byte[128];
for (int i = 0; i < bytes3.length; i++) {
bytes3[i] = (byte) 2;
}
Arrays.fill(bytes3, (byte) 2);
resp3.setEntity(new ByteArrayEntity(bytes3, null));

EasyMock.expect(
Expand Down Expand Up @@ -1461,9 +1456,7 @@ public void test206ResponseIsNotCombinedWithPreviousContentIfLastModifiedDoesNot
resp1.setHeader("Cache-Control", "max-age=3600");
resp1.setHeader("Last-Modified", DateUtils.formatDate(oneHourAgo));
final byte[] bytes1 = new byte[128];
for (int i = 0; i < bytes1.length; i++) {
bytes1[i] = (byte) 1;
}
Arrays.fill(bytes1, (byte) 1);
resp1.setEntity(new ByteArrayEntity(bytes1, null));

final ClassicHttpRequest req2 = new BasicClassicHttpRequest("GET", "/");
Expand All @@ -1478,9 +1471,7 @@ public void test206ResponseIsNotCombinedWithPreviousContentIfLastModifiedDoesNot
resp2.setHeader("Last-Modified", DateUtils.formatDate(now));
resp2.setHeader("Content-Range", "bytes 0-50/128");
final byte[] bytes2 = new byte[51];
for (int i = 0; i < bytes2.length; i++) {
bytes2[i] = (byte) 2;
}
Arrays.fill(bytes2, (byte) 2);
resp2.setEntity(new ByteArrayEntity(bytes2, null));

final Date inTwoSeconds = new Date(now.getTime() + 2000L);
Expand All @@ -1490,9 +1481,7 @@ public void test206ResponseIsNotCombinedWithPreviousContentIfLastModifiedDoesNot
resp3.setHeader("Cache-Control", "max-age=3600");
resp3.setHeader("ETag", "\"etag2\"");
final byte[] bytes3 = new byte[128];
for (int i = 0; i < bytes3.length; i++) {
bytes3[i] = (byte) 2;
}
Arrays.fill(bytes3, (byte) 2);
resp3.setEntity(new ByteArrayEntity(bytes3, null));

EasyMock.expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void testConcurrentPostRequests() throws Exception {
.build();

final ReactiveResponseConsumer consumer = new ReactiveResponseConsumer(new FutureCallback<Message<HttpResponse, Publisher<ByteBuffer>>>() {
@Override
public void completed(final Message<HttpResponse, Publisher<ByteBuffer>> result) {
final Flowable<ByteBuffer> flowable = Flowable.fromPublisher(result.getBody())
.observeOn(Schedulers.io()); // Stream the data on an RxJava scheduler, not a client thread
Expand All @@ -169,7 +170,9 @@ public void accept(final StreamDescription streamDescription) {
}
});
}
@Override
public void failed(final Exception ex) { }
@Override
public void cancelled() { }
});
httpclient.execute(request, consumer, HttpClientContext.create(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public static boolean isWinAuthAvailable() {
if (os != null && os.contains("windows")) {
try {
return Sspi.MAX_TOKEN_SIZE > 0;
} catch (final Exception ignore) { // Likely ClassNotFound
return false;
} catch (final Exception ignore) {
// Likely ClassNotFound
}
}
return false;
Expand Down
28 changes: 14 additions & 14 deletions httpclient5/src/main/java/org/apache/hc/client5/http/HttpRoute.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,26 @@ public HttpRoute(final HttpHost target, final HttpHost proxy) {
}

@Override
public final HttpHost getTargetHost() {
public HttpHost getTargetHost() {
return this.targetHost;
}

@Override
public final InetAddress getLocalAddress() {
public InetAddress getLocalAddress() {
return this.localAddress;
}

public final InetSocketAddress getLocalSocketAddress() {
public InetSocketAddress getLocalSocketAddress() {
return this.localAddress != null ? new InetSocketAddress(this.localAddress, 0) : null;
}

@Override
public final int getHopCount() {
public int getHopCount() {
return proxyChain != null ? proxyChain.size() + 1 : 1;
}

@Override
public final HttpHost getHopTarget(final int hop) {
public HttpHost getHopTarget(final int hop) {
Args.notNegative(hop, "Hop index");
final int hopcount = getHopCount();
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
Expand All @@ -218,32 +218,32 @@ public final HttpHost getHopTarget(final int hop) {
}

@Override
public final HttpHost getProxyHost() {
public HttpHost getProxyHost() {
return proxyChain != null && !this.proxyChain.isEmpty() ? this.proxyChain.get(0) : null;
}

@Override
public final TunnelType getTunnelType() {
public TunnelType getTunnelType() {
return this.tunnelled;
}

@Override
public final boolean isTunnelled() {
public boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}

@Override
public final LayerType getLayerType() {
public LayerType getLayerType() {
return this.layered;
}

@Override
public final boolean isLayered() {
public boolean isLayered() {
return (this.layered == LayerType.LAYERED);
}

@Override
public final boolean isSecure() {
public boolean isSecure() {
return this.secure;
}

Expand All @@ -256,7 +256,7 @@ public final boolean isSecure() {
* {@code false}
*/
@Override
public final boolean equals(final Object obj) {
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
Expand All @@ -281,7 +281,7 @@ public final boolean equals(final Object obj) {
* @return the hash code
*/
@Override
public final int hashCode() {
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.targetHost);
hash = LangUtils.hashCode(hash, this.localAddress);
Expand All @@ -302,7 +302,7 @@ public final int hashCode() {
* @return a human-readable representation of this route
*/
@Override
public final String toString() {
public String toString() {
final StringBuilder cab = new StringBuilder(50 + getHopCount()*30);
if (this.localAddress != null) {
cab.append(this.localAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public RouteTracker(final HttpRoute route) {
* @param secure {@code true} if the route is secure,
* {@code false} otherwise
*/
public final void connectTarget(final boolean secure) {
public void connectTarget(final boolean secure) {
Asserts.check(!this.connected, "Already connected");
this.connected = true;
this.secure = secure;
Expand All @@ -125,7 +125,7 @@ public final void connectTarget(final boolean secure) {
* @param secure {@code true} if the route is secure,
* {@code false} otherwise
*/
public final void connectProxy(final HttpHost proxy, final boolean secure) {
public void connectProxy(final HttpHost proxy, final boolean secure) {
Args.notNull(proxy, "Proxy host");
Asserts.check(!this.connected, "Already connected");
this.connected = true;
Expand All @@ -139,7 +139,7 @@ public final void connectProxy(final HttpHost proxy, final boolean secure) {
* @param secure {@code true} if the route is secure,
* {@code false} otherwise
*/
public final void tunnelTarget(final boolean secure) {
public void tunnelTarget(final boolean secure) {
Asserts.check(this.connected, "No tunnel unless connected");
Asserts.notNull(this.proxyChain, "No tunnel without proxy");
this.tunnelled = TunnelType.TUNNELLED;
Expand All @@ -155,7 +155,7 @@ public final void tunnelTarget(final boolean secure) {
* @param secure {@code true} if the route is secure,
* {@code false} otherwise
*/
public final void tunnelProxy(final HttpHost proxy, final boolean secure) {
public void tunnelProxy(final HttpHost proxy, final boolean secure) {
Args.notNull(proxy, "Proxy host");
Asserts.check(this.connected, "No tunnel unless connected");
Asserts.notNull(this.proxyChain, "No tunnel without proxy");
Expand All @@ -175,7 +175,7 @@ public final void tunnelProxy(final HttpHost proxy, final boolean secure) {
* @param secure {@code true} if the route is secure,
* {@code false} otherwise
*/
public final void layerProtocol(final boolean secure) {
public void layerProtocol(final boolean secure) {
// it is possible to layer a protocol over a direct connection,
// although this case is probably not considered elsewhere
Asserts.check(this.connected, "No layered protocol unless connected");
Expand All @@ -184,17 +184,17 @@ public final void layerProtocol(final boolean secure) {
}

@Override
public final HttpHost getTargetHost() {
public HttpHost getTargetHost() {
return this.targetHost;
}

@Override
public final InetAddress getLocalAddress() {
public InetAddress getLocalAddress() {
return this.localAddress;
}

@Override
public final int getHopCount() {
public int getHopCount() {
int hops = 0;
if (this.connected) {
if (proxyChain == null) {
Expand All @@ -207,7 +207,7 @@ public final int getHopCount() {
}

@Override
public final HttpHost getHopTarget(final int hop) {
public HttpHost getHopTarget(final int hop) {
Args.notNegative(hop, "Hop index");
final int hopcount = getHopCount();
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
Expand All @@ -222,36 +222,36 @@ public final HttpHost getHopTarget(final int hop) {
}

@Override
public final HttpHost getProxyHost() {
public HttpHost getProxyHost() {
return (this.proxyChain == null) ? null : this.proxyChain[0];
}

public final boolean isConnected() {
public boolean isConnected() {
return this.connected;
}

@Override
public final TunnelType getTunnelType() {
public TunnelType getTunnelType() {
return this.tunnelled;
}

@Override
public final boolean isTunnelled() {
public boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}

@Override
public final LayerType getLayerType() {
public LayerType getLayerType() {
return this.layered;
}

@Override
public final boolean isLayered() {
public boolean isLayered() {
return (this.layered == LayerType.LAYERED);
}

@Override
public final boolean isSecure() {
public boolean isSecure() {
return this.secure;
}

Expand All @@ -263,7 +263,7 @@ public final boolean isSecure() {
* @return the tracked route, or
* {@code null} if nothing has been tracked so far
*/
public final HttpRoute toRoute() {
public HttpRoute toRoute() {
return !this.connected ?
null : new HttpRoute(this.targetHost, this.localAddress,
this.proxyChain, this.secure,
Expand All @@ -279,7 +279,7 @@ public final HttpRoute toRoute() {
* {@code false}
*/
@Override
public final boolean equals(final Object o) {
public boolean equals(final Object o) {
if (o == this) {
return true;
}
Expand Down Expand Up @@ -308,7 +308,7 @@ public final boolean equals(final Object o) {
* @return the hash code
*/
@Override
public final int hashCode() {
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.targetHost);
hash = LangUtils.hashCode(hash, this.localAddress);
Expand All @@ -330,7 +330,7 @@ public final int hashCode() {
* @return a human-readable representation of the tracked route
*/
@Override
public final String toString() {
public String toString() {
final StringBuilder cab = new StringBuilder(50 + getHopCount()*30);

cab.append("RouteTracker[");
Expand Down
Loading