You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by gg...@apache.org on 2017/09/02 15:43:03 UTC
httpcomponents-core git commit: Use final.
Repository: httpcomponents-core
Updated Branches:
refs/heads/4.4.x f12e09eb3 -> 442d26066
Use final.
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/442d2606
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/442d2606
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/442d2606
Branch: refs/heads/4.4.x
Commit: 442d260664ef29207b8e59a443e332e45bb2c925
Parents: f12e09e
Author: Gary Gregory <ga...@gmail.com>
Authored: Sat Sep 2 09:43:00 2017 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sat Sep 2 09:43:00 2017 -0600
----------------------------------------------------------------------
.../http/examples/nio/ElementalEchoServer.java | 20 ++---
.../apache/http/examples/nio/NHttpClient.java | 22 ++---
.../http/examples/nio/NHttpFileServer.java | 24 ++---
.../http/examples/nio/NHttpReverseProxy.java | 94 ++++++++++----------
.../http/examples/nio/PipeliningHttpClient.java | 24 ++---
.../apache/http/nio/pool/TestNIOConnPool.java | 4 +-
6 files changed, 94 insertions(+), 94 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/442d2606/httpcore-nio/src/examples/org/apache/http/examples/nio/ElementalEchoServer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/ElementalEchoServer.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/ElementalEchoServer.java
index 0195e26..05438a6 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/ElementalEchoServer.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/ElementalEchoServer.java
@@ -39,15 +39,15 @@ import org.apache.http.nio.reactor.ListeningIOReactor;
public class ElementalEchoServer {
- public static void main(String[] args) throws Exception {
- IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch();
- ListeningIOReactor ioReactor = new DefaultListeningIOReactor();
+ public static void main(final String[] args) throws Exception {
+ final IOEventDispatch ioEventDispatch = new DefaultIoEventDispatch();
+ final ListeningIOReactor ioReactor = new DefaultListeningIOReactor();
ioReactor.listen(new InetSocketAddress(8080));
try {
ioReactor.execute(ioEventDispatch);
- } catch (InterruptedIOException ex) {
+ } catch (final InterruptedIOException ex) {
System.err.println("Interrupted");
- } catch (IOException e) {
+ } catch (final IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
@@ -57,7 +57,7 @@ public class ElementalEchoServer {
private final ByteBuffer buffer = ByteBuffer.allocate(1024);
- public void connected(IOSession session) {
+ public void connected(final IOSession session) {
System.out.println("connected");
session.setEventMask(EventMask.READ);
session.setSocketTimeout(20000);
@@ -67,7 +67,7 @@ public class ElementalEchoServer {
System.out.println("readable");
try {
this.buffer.compact();
- int bytesRead = session.channel().read(this.buffer);
+ final int bytesRead = session.channel().read(this.buffer);
if (this.buffer.position() > 0) {
session.setEventMask(EventMask.READ_WRITE);
}
@@ -75,7 +75,7 @@ public class ElementalEchoServer {
if (bytesRead == -1) {
session.close();
}
- } catch (IOException ex) {
+ } catch (final IOException ex) {
System.err.println("I/O error: " + ex.getMessage());
}
}
@@ -84,12 +84,12 @@ public class ElementalEchoServer {
System.out.println("writeable");
try {
this.buffer.flip();
- int bytesWritten = session.channel().write(this.buffer);
+ final int bytesWritten = session.channel().write(this.buffer);
if (!this.buffer.hasRemaining()) {
session.setEventMask(EventMask.READ);
}
System.out.println("Bytes written: " + bytesWritten);
- } catch (IOException ex) {
+ } catch (final IOException ex) {
System.err.println("I/O error: " + ex.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/442d2606/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
index 4fcf031..882531c 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
@@ -67,9 +67,9 @@ import org.apache.http.protocol.RequestUserAgent;
*/
public class NHttpClient {
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
// Create HTTP protocol processing chain
- HttpProcessor httpproc = HttpProcessorBuilder.create()
+ final HttpProcessor httpproc = HttpProcessorBuilder.create()
// Use standard client-side protocol interceptors
.add(new RequestContent())
.add(new RequestTargetHost())
@@ -77,27 +77,27 @@ public class NHttpClient {
.add(new RequestUserAgent("Test/1.1"))
.add(new RequestExpectContinue(true)).build();
// Create client-side HTTP protocol handler
- HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
+ final HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
// Create client-side I/O event dispatch
final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler,
ConnectionConfig.DEFAULT);
// Create client-side I/O reactor
final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
// Create HTTP connection pool
- BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT);
+ final BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT);
// Limit total number of connections to just two
pool.setDefaultMaxPerRoute(2);
pool.setMaxTotal(2);
// Run the I/O reactor in a separate thread
- Thread t = new Thread(new Runnable() {
+ final Thread t = new Thread(new Runnable() {
public void run() {
try {
// Ready to go!
ioReactor.execute(ioEventDispatch);
- } catch (InterruptedIOException ex) {
+ } catch (final InterruptedIOException ex) {
System.err.println("Interrupted");
- } catch (IOException e) {
+ } catch (final IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
@@ -107,17 +107,17 @@ public class NHttpClient {
// Start the client thread
t.start();
// Create HTTP requester
- HttpAsyncRequester requester = new HttpAsyncRequester(httpproc);
+ final HttpAsyncRequester requester = new HttpAsyncRequester(httpproc);
// Execute HTTP GETs to the following hosts and
- HttpHost[] targets = new HttpHost[] {
+ final HttpHost[] targets = new HttpHost[] {
new HttpHost("www.apache.org", 80, "http"),
new HttpHost("www.verisign.com", 443, "https"),
new HttpHost("www.google.com", 80, "http")
};
final CountDownLatch latch = new CountDownLatch(targets.length);
for (final HttpHost target: targets) {
- BasicHttpRequest request = new BasicHttpRequest("GET", "/");
- HttpCoreContext coreContext = HttpCoreContext.create();
+ final BasicHttpRequest request = new BasicHttpRequest("GET", "/");
+ final HttpCoreContext coreContext = HttpCoreContext.create();
requester.execute(
new BasicAsyncRequestProducer(target, request),
new BasicAsyncResponseConsumer(),
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/442d2606/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
index 28e7692..a9e54df 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
@@ -63,13 +63,13 @@ import org.apache.http.ssl.SSLContexts;
*/
public class NHttpFileServer {
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
if (args.length < 1) {
System.err.println("Please specify document root directory");
System.exit(1);
}
// Document root directory
- File docRoot = new File(args[0]);
+ final File docRoot = new File(args[0]);
int port = 8080;
if (args.length >= 2) {
port = Integer.parseInt(args[1]);
@@ -78,7 +78,7 @@ public class NHttpFileServer {
SSLContext sslContext = null;
if (port == 8443) {
// Initialize SSL context
- URL url = NHttpFileServer.class.getResource("/test.keystore");
+ final URL url = NHttpFileServer.class.getResource("/test.keystore");
if (url == null) {
System.out.println("Keystore not found");
System.exit(1);
@@ -89,7 +89,7 @@ public class NHttpFileServer {
.build();
}
- IOReactorConfig config = IOReactorConfig.custom()
+ final IOReactorConfig config = IOReactorConfig.custom()
.setSoTimeout(15000)
.setTcpNoDelay(true)
.build();
@@ -137,7 +137,7 @@ public class NHttpFileServer {
final HttpRequest request,
final HttpAsyncExchange httpexchange,
final HttpContext context) throws HttpException, IOException {
- HttpResponse response = httpexchange.getResponse();
+ final HttpResponse response = httpexchange.getResponse();
handleInternal(request, response, context);
httpexchange.submitResponse(new BasicAsyncResponseProducer(response));
}
@@ -147,17 +147,17 @@ public class NHttpFileServer {
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
- String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
+ final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH);
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
throw new MethodNotSupportedException(method + " method not supported");
}
- String target = request.getRequestLine().getUri();
+ final String target = request.getRequestLine().getUri();
final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
if (!file.exists()) {
response.setStatusCode(HttpStatus.SC_NOT_FOUND);
- NStringEntity entity = new NStringEntity(
+ final NStringEntity entity = new NStringEntity(
"<html><body><h1>File " + file.getPath() +
" not found</h1></body></html>",
ContentType.create("text/html", "UTF-8"));
@@ -167,7 +167,7 @@ public class NHttpFileServer {
} else if (!file.canRead() || file.isDirectory()) {
response.setStatusCode(HttpStatus.SC_FORBIDDEN);
- NStringEntity entity = new NStringEntity(
+ final NStringEntity entity = new NStringEntity(
"<html><body><h1>Access denied</h1></body></html>",
ContentType.create("text/html", "UTF-8"));
response.setEntity(entity);
@@ -175,10 +175,10 @@ public class NHttpFileServer {
} else {
- HttpCoreContext coreContext = HttpCoreContext.adapt(context);
- HttpConnection conn = coreContext.getConnection(HttpConnection.class);
+ final HttpCoreContext coreContext = HttpCoreContext.adapt(context);
+ final HttpConnection conn = coreContext.getConnection(HttpConnection.class);
response.setStatusCode(HttpStatus.SC_OK);
- NFileEntity body = new NFileEntity(file, ContentType.create("text/html"));
+ final NFileEntity body = new NFileEntity(file, ContentType.create("text/html"));
response.setEntity(body);
System.out.println(conn + ": serving file " + file.getPath());
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/442d2606/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
index e685262..4a2469c 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpReverseProxy.java
@@ -113,14 +113,14 @@ import org.apache.http.ssl.TrustStrategy;
*/
public class NHttpReverseProxy {
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: NHttpReverseProxy <HostNameURI> <Port> [\"TrustSelfSignedStrategy\"]");
System.exit(1);
}
// Extract command line arguments
- URI uri = new URI(args[0]);
- int port = Integer.parseInt(args[1]);
+ final URI uri = new URI(args[0]);
+ final int port = Integer.parseInt(args[1]);
SSLContext sslContext = null;
if (args.length > 2 && args[2].equals("TrustSelfSignedStrategy")) {
System.out.println("Using TrustSelfSignedStrategy (not for production)");
@@ -136,14 +136,14 @@ public class NHttpReverseProxy {
}
// Target host
- HttpHost targetHost = new HttpHost(
+ final HttpHost targetHost = new HttpHost(
uri.getHost(),
uri.getPort() > 0 ? uri.getPort() : 80,
uri.getScheme() != null ? uri.getScheme() : "http");
System.out.println("Reverse proxy to " + targetHost);
- IOReactorConfig config = IOReactorConfig.custom()
+ final IOReactorConfig config = IOReactorConfig.custom()
.setIoThreadCount(1)
.setSoTimeout(3000)
.setConnectTimeout(3000)
@@ -152,7 +152,7 @@ public class NHttpReverseProxy {
final ListeningIOReactor listeningIOReactor = new DefaultListeningIOReactor(config);
// Set up HTTP protocol processor for incoming connections
- HttpProcessor inhttpproc = new ImmutableHttpProcessor(
+ final HttpProcessor inhttpproc = new ImmutableHttpProcessor(
new HttpResponseInterceptor[] {
new ResponseDate(),
new ResponseServer("Test/1.1"),
@@ -161,7 +161,7 @@ public class NHttpReverseProxy {
});
// Set up HTTP protocol processor for outgoing connections
- HttpProcessor outhttpproc = new ImmutableHttpProcessor(
+ final HttpProcessor outhttpproc = new ImmutableHttpProcessor(
new HttpRequestInterceptor[] {
new RequestContent(),
new RequestTargetHost(),
@@ -170,22 +170,22 @@ public class NHttpReverseProxy {
new RequestExpectContinue(true)
});
- ProxyClientProtocolHandler clientHandler = new ProxyClientProtocolHandler();
- HttpAsyncRequester executor = new HttpAsyncRequester(
+ final ProxyClientProtocolHandler clientHandler = new ProxyClientProtocolHandler();
+ final HttpAsyncRequester executor = new HttpAsyncRequester(
outhttpproc, new ProxyOutgoingConnectionReuseStrategy());
// Without SSL: ProxyConnPool connPool = new ProxyConnPool(connectingIOReactor, ConnectionConfig.DEFAULT);
- ProxyConnPool connPool = new ProxyConnPool(connectingIOReactor,
+ final ProxyConnPool connPool = new ProxyConnPool(connectingIOReactor,
new BasicNIOConnFactory(new DefaultNHttpClientConnectionFactory(ConnectionConfig.DEFAULT),
new SSLNHttpClientConnectionFactory(sslContext, null, ConnectionConfig.DEFAULT)),
0);
connPool.setMaxTotal(100);
connPool.setDefaultMaxPerRoute(20);
- UriHttpAsyncRequestHandlerMapper handlerRegistry = new UriHttpAsyncRequestHandlerMapper();
+ final UriHttpAsyncRequestHandlerMapper handlerRegistry = new UriHttpAsyncRequestHandlerMapper();
handlerRegistry.register("*", new ProxyRequestHandler(targetHost, executor, connPool));
- ProxyServiceHandler serviceHandler = new ProxyServiceHandler(
+ final ProxyServiceHandler serviceHandler = new ProxyServiceHandler(
inhttpproc,
new ProxyIncomingConnectionReuseStrategy(),
handlerRegistry);
@@ -196,19 +196,19 @@ public class NHttpReverseProxy {
final IOEventDispatch listeningEventDispatch = new DefaultHttpServerIODispatch(
serviceHandler, ConnectionConfig.DEFAULT);
- Thread t = new Thread(new Runnable() {
+ final Thread t = new Thread(new Runnable() {
public void run() {
try {
connectingIOReactor.execute(connectingEventDispatch);
- } catch (InterruptedIOException ex) {
+ } catch (final InterruptedIOException ex) {
System.err.println("Interrupted");
- } catch (IOException ex) {
+ } catch (final IOException ex) {
ex.printStackTrace();
} finally {
try {
listeningIOReactor.shutdown();
- } catch (IOException ex2) {
+ } catch (final IOException ex2) {
ex2.printStackTrace();
}
}
@@ -219,14 +219,14 @@ public class NHttpReverseProxy {
try {
listeningIOReactor.listen(new InetSocketAddress(port));
listeningIOReactor.execute(listeningEventDispatch);
- } catch (InterruptedIOException ex) {
+ } catch (final InterruptedIOException ex) {
System.err.println("Interrupted");
- } catch (IOException ex) {
+ } catch (final IOException ex) {
ex.printStackTrace();
} finally {
try {
connectingIOReactor.shutdown();
- } catch (IOException ex2) {
+ } catch (final IOException ex2) {
ex2.printStackTrace();
}
}
@@ -387,7 +387,7 @@ public class NHttpReverseProxy {
}
synchronized (httpExchange) {
httpExchange.reset();
- String id = String.format("%08X", this.counter.getAndIncrement());
+ final String id = String.format("%08X", this.counter.getAndIncrement());
httpExchange.setId(id);
httpExchange.setTarget(this.target);
return new ProxyRequestConsumer(httpExchange, this.executor, this.connPool);
@@ -399,11 +399,11 @@ public class NHttpReverseProxy {
final HttpAsyncExchange responseTrigger,
final HttpContext context) throws HttpException, IOException {
synchronized (httpExchange) {
- Exception ex = httpExchange.getException();
+ final Exception ex = httpExchange.getException();
if (ex != null) {
System.out.println("[client<-proxy] " + httpExchange.getId() + " " + ex);
- int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
- HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, status,
+ final int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+ final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, status,
EnglishReasonPhraseCatalog.INSTANCE.getReason(status, Locale.US));
String message = ex.getMessage();
if (message == null) {
@@ -413,7 +413,7 @@ public class NHttpReverseProxy {
responseTrigger.submitResponse(new BasicAsyncResponseProducer(response));
System.out.println("[client<-proxy] " + httpExchange.getId() + " error response triggered");
}
- HttpResponse response = httpExchange.getResponse();
+ final HttpResponse response = httpExchange.getResponse();
if (response != null) {
responseTrigger.submitResponse(new ProxyResponseProducer(httpExchange));
System.out.println("[client<-proxy] " + httpExchange.getId() + " response triggered");
@@ -462,8 +462,8 @@ public class NHttpReverseProxy {
synchronized (this.httpExchange) {
this.httpExchange.setClientIOControl(ioctrl);
// Receive data from the client
- ByteBuffer buf = this.httpExchange.getInBuffer();
- int n = decoder.read(buf);
+ final ByteBuffer buf = this.httpExchange.getInBuffer();
+ final int n = decoder.read(buf);
System.out.println("[client->proxy] " + this.httpExchange.getId() + " " + n + " bytes read");
if (decoder.isCompleted()) {
System.out.println("[client->proxy] " + this.httpExchange.getId() + " content fully read");
@@ -535,11 +535,11 @@ public class NHttpReverseProxy {
public HttpRequest generateRequest() {
synchronized (this.httpExchange) {
- HttpRequest request = this.httpExchange.getRequest();
+ final HttpRequest request = this.httpExchange.getRequest();
System.out.println("[proxy->origin] " + this.httpExchange.getId() + " " + request.getRequestLine());
// Rewrite request!!!!
if (request instanceof HttpEntityEnclosingRequest) {
- BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(
+ final BasicHttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest(
request.getRequestLine());
r.setEntity(((HttpEntityEnclosingRequest) request).getEntity());
return r;
@@ -554,9 +554,9 @@ public class NHttpReverseProxy {
synchronized (this.httpExchange) {
this.httpExchange.setOriginIOControl(ioctrl);
// Send data to the origin server
- ByteBuffer buf = this.httpExchange.getInBuffer();
+ final ByteBuffer buf = this.httpExchange.getInBuffer();
buf.flip();
- int n = encoder.write(buf);
+ final int n = encoder.write(buf);
buf.compact();
System.out.println("[proxy->origin] " + this.httpExchange.getId() + " " + n + " bytes written");
// If there is space in the buffer and the message has not been
@@ -618,7 +618,7 @@ public class NHttpReverseProxy {
synchronized (this.httpExchange) {
System.out.println("[proxy<-origin] " + this.httpExchange.getId() + " " + response.getStatusLine());
this.httpExchange.setResponse(response);
- HttpAsyncExchange responseTrigger = this.httpExchange.getResponseTrigger();
+ final HttpAsyncExchange responseTrigger = this.httpExchange.getResponseTrigger();
if (responseTrigger != null && !responseTrigger.isCompleted()) {
System.out.println("[client<-proxy] " + this.httpExchange.getId() + " response triggered");
responseTrigger.submitResponse(new ProxyResponseProducer(this.httpExchange));
@@ -631,8 +631,8 @@ public class NHttpReverseProxy {
synchronized (this.httpExchange) {
this.httpExchange.setOriginIOControl(ioctrl);
// Receive data from the origin
- ByteBuffer buf = this.httpExchange.getOutBuffer();
- int n = decoder.read(buf);
+ final ByteBuffer buf = this.httpExchange.getOutBuffer();
+ final int n = decoder.read(buf);
System.out.println("[proxy<-origin] " + this.httpExchange.getId() + " " + n + " bytes read");
if (decoder.isCompleted()) {
System.out.println("[proxy<-origin] " + this.httpExchange.getId() + " content fully read");
@@ -676,11 +676,11 @@ public class NHttpReverseProxy {
}
this.completed = true;
this.httpExchange.setException(ex);
- HttpAsyncExchange responseTrigger = this.httpExchange.getResponseTrigger();
+ final HttpAsyncExchange responseTrigger = this.httpExchange.getResponseTrigger();
if (responseTrigger != null && !responseTrigger.isCompleted()) {
System.out.println("[client<-proxy] " + this.httpExchange.getId() + " " + ex);
- int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
- HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, status,
+ final int status = HttpStatus.SC_INTERNAL_SERVER_ERROR;
+ final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_0, status,
EnglishReasonPhraseCatalog.INSTANCE.getReason(status, Locale.US));
String message = ex.getMessage();
if (message == null) {
@@ -731,10 +731,10 @@ public class NHttpReverseProxy {
public HttpResponse generateResponse() {
synchronized (this.httpExchange) {
- HttpResponse response = this.httpExchange.getResponse();
+ final HttpResponse response = this.httpExchange.getResponse();
System.out.println("[client<-proxy] " + this.httpExchange.getId() + " " + response.getStatusLine());
// Rewrite response!!!!
- BasicHttpResponse r = new BasicHttpResponse(response.getStatusLine());
+ final BasicHttpResponse r = new BasicHttpResponse(response.getStatusLine());
r.setEntity(response.getEntity());
return r;
}
@@ -745,9 +745,9 @@ public class NHttpReverseProxy {
synchronized (this.httpExchange) {
this.httpExchange.setClientIOControl(ioctrl);
// Send data to the client
- ByteBuffer buf = this.httpExchange.getOutBuffer();
+ final ByteBuffer buf = this.httpExchange.getOutBuffer();
buf.flip();
- int n = encoder.write(buf);
+ final int n = encoder.write(buf);
buf.compact();
System.out.println("[client<-proxy] " + this.httpExchange.getId() + " " + n + " bytes written");
// If there is space in the buffer and the message has not been
@@ -788,9 +788,9 @@ public class NHttpReverseProxy {
@Override
public boolean keepAlive(final HttpResponse response, final HttpContext context) {
- NHttpConnection conn = (NHttpConnection) context.getAttribute(
+ final NHttpConnection conn = (NHttpConnection) context.getAttribute(
HttpCoreContext.HTTP_CONNECTION);
- boolean keepAlive = super.keepAlive(response, context);
+ final boolean keepAlive = super.keepAlive(response, context);
if (keepAlive) {
System.out.println("[client->proxy] connection kept alive " + conn);
}
@@ -803,9 +803,9 @@ public class NHttpReverseProxy {
@Override
public boolean keepAlive(final HttpResponse response, final HttpContext context) {
- NHttpConnection conn = (NHttpConnection) context.getAttribute(
+ final NHttpConnection conn = (NHttpConnection) context.getAttribute(
HttpCoreContext.HTTP_CONNECTION);
- boolean keepAlive = super.keepAlive(response, context);
+ final boolean keepAlive = super.keepAlive(response, context);
if (keepAlive) {
System.out.println("[proxy->origin] connection kept alive " + conn);
}
@@ -878,11 +878,11 @@ public class NHttpReverseProxy {
}
@Override
- public void release(final BasicNIOPoolEntry entry, boolean reusable) {
+ public void release(final BasicNIOPoolEntry entry, final boolean reusable) {
System.out.println("[proxy->origin] connection released " + entry.getConnection());
super.release(entry, reusable);
- StringBuilder buf = new StringBuilder();
- PoolStats totals = getTotalStats();
+ final StringBuilder buf = new StringBuilder();
+ final PoolStats totals = getTotalStats();
buf.append("[total kept alive: ").append(totals.getAvailable()).append("; ");
buf.append("total allocated: ").append(totals.getLeased() + totals.getAvailable());
buf.append(" of ").append(totals.getMax()).append("]");
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/442d2606/httpcore-nio/src/examples/org/apache/http/examples/nio/PipeliningHttpClient.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/examples/org/apache/http/examples/nio/PipeliningHttpClient.java b/httpcore-nio/src/examples/org/apache/http/examples/nio/PipeliningHttpClient.java
index 1240bc1..792b617 100644
--- a/httpcore-nio/src/examples/org/apache/http/examples/nio/PipeliningHttpClient.java
+++ b/httpcore-nio/src/examples/org/apache/http/examples/nio/PipeliningHttpClient.java
@@ -69,9 +69,9 @@ import org.apache.http.protocol.RequestUserAgent;
*/
public class PipeliningHttpClient {
- public static void main(String[] args) throws Exception {
+ public static void main(final String[] args) throws Exception {
// Create HTTP protocol processing chain
- HttpProcessor httpproc = HttpProcessorBuilder.create()
+ final HttpProcessor httpproc = HttpProcessorBuilder.create()
// Use standard client-side protocol interceptors
.add(new RequestContent())
.add(new RequestTargetHost())
@@ -79,27 +79,27 @@ public class PipeliningHttpClient {
.add(new RequestUserAgent("Test/1.1"))
.add(new RequestExpectContinue(true)).build();
// Create client-side HTTP protocol handler
- HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
+ final HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor();
// Create client-side I/O event dispatch
final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler,
ConnectionConfig.DEFAULT);
// Create client-side I/O reactor
final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor();
// Create HTTP connection pool
- BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT);
+ final BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT);
// Limit total number of connections to just two
pool.setDefaultMaxPerRoute(2);
pool.setMaxTotal(2);
// Run the I/O reactor in a separate thread
- Thread t = new Thread(new Runnable() {
+ final Thread t = new Thread(new Runnable() {
public void run() {
try {
// Ready to go!
ioReactor.execute(ioEventDispatch);
- } catch (InterruptedIOException ex) {
+ } catch (final InterruptedIOException ex) {
System.err.println("Interrupted");
- } catch (IOException e) {
+ } catch (final IOException e) {
System.err.println("I/O error: " + e.getMessage());
}
System.out.println("Shutdown");
@@ -109,15 +109,15 @@ public class PipeliningHttpClient {
// Start the client thread
t.start();
// Create HTTP requester
- HttpAsyncRequester requester = new HttpAsyncRequester(httpproc);
+ final HttpAsyncRequester requester = new HttpAsyncRequester(httpproc);
final HttpHost target = new HttpHost("www.apache.org");
- List<BasicAsyncRequestProducer> requestProducers = Arrays.asList(
+ final List<BasicAsyncRequestProducer> requestProducers = Arrays.asList(
new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/index.html")),
new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/foundation/index.html")),
new BasicAsyncRequestProducer(target, new BasicHttpRequest("GET", "/foundation/how-it-works.html"))
);
- List<BasicAsyncResponseConsumer> responseConsumers = Arrays.asList(
+ final List<BasicAsyncResponseConsumer> responseConsumers = Arrays.asList(
new BasicAsyncResponseConsumer(),
new BasicAsyncResponseConsumer(),
new BasicAsyncResponseConsumer()
@@ -125,7 +125,7 @@ public class PipeliningHttpClient {
final CountDownLatch latch = new CountDownLatch(1);
- HttpCoreContext context = HttpCoreContext.create();
+ final HttpCoreContext context = HttpCoreContext.create();
requester.executePipelined(
target, requestProducers, responseConsumers, pool, context,
new FutureCallback<List<HttpResponse>>() {
@@ -133,7 +133,7 @@ public class PipeliningHttpClient {
@Override
public void completed(final List<HttpResponse> result) {
latch.countDown();
- for (HttpResponse response: result) {
+ for (final HttpResponse response: result) {
System.out.println(target + "->" + response.getStatusLine());
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/442d2606/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
----------------------------------------------------------------------
diff --git a/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java b/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
index 82abb22..1cb357e 100644
--- a/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
+++ b/httpcore-nio/src/test/java/org/apache/http/nio/pool/TestNIOConnPool.java
@@ -263,7 +263,7 @@ public class TestNIOConnPool {
try {
future.get();
Assert.fail("CancellationException expected");
- } catch (CancellationException ignore) {
+ } catch (final CancellationException ignore) {
}
totals = pool.getTotalStats();
@@ -1053,7 +1053,7 @@ public class TestNIOConnPool {
try {
future1.get();
Assert.fail("CancellationException expected");
- } catch (CancellationException ignore) {
+ } catch (final CancellationException ignore) {
}
final PoolStats totals = pool.getTotalStats();