Permalink
Browse files

Tweaked NHttpClient example; updated logging contrib; fixed warning i…

…n OSGi metadata

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk@1233840 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent db8bc61 commit 3d2d3735ed0db9e1ac08f5115d2b013a9051ecdd @ok2c ok2c committed Jan 20, 2012
View
8 ...e-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientConnection.java
@@ -39,7 +39,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseFactory;
import org.apache.http.impl.nio.DefaultNHttpClientConnection;
-import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientEventHandler;
import org.apache.http.nio.NHttpMessageParser;
import org.apache.http.nio.NHttpMessageWriter;
import org.apache.http.nio.reactor.IOSession;
@@ -99,15 +99,15 @@ public void submitRequest(final HttpRequest request) throws IOException, HttpExc
}
@Override
- public void consumeInput(final NHttpClientHandler handler) {
+ public void consumeInput(final NHttpClientEventHandler handler) {
if (this.log.isDebugEnabled()) {
this.log.debug(this.id + ": Consume input");
}
super.consumeInput(handler);
}
@Override
- public void produceOutput(final NHttpClientHandler handler) {
+ public void produceOutput(final NHttpClientEventHandler handler) {
if (this.log.isDebugEnabled()) {
this.log.debug(this.id + ": Produce output");
}
@@ -193,4 +193,4 @@ public HttpResponse parse() throws IOException, HttpException {
}
-}
+}
View
39 ...core-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpClientHandler.java
@@ -36,19 +36,19 @@
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpClientConnection;
-import org.apache.http.nio.NHttpClientHandler;
+import org.apache.http.nio.NHttpClientEventHandler;
/**
* Decorator class intended to transparently extend an {@link NHttpClientHandler}
* with basic event logging capabilities using Commons Logging.
*
*/
-public class LoggingNHttpClientHandler implements NHttpClientHandler {
+public class LoggingNHttpClientHandler implements NHttpClientEventHandler {
private final Log log;
- private final NHttpClientHandler handler;
+ private final NHttpClientEventHandler handler;
- public LoggingNHttpClientHandler(final NHttpClientHandler handler) {
+ public LoggingNHttpClientHandler(final NHttpClientEventHandler handler) {
super();
if (handler == null) {
throw new IllegalArgumentException("HTTP client handler may not be null");
@@ -57,7 +57,9 @@ public LoggingNHttpClientHandler(final NHttpClientHandler handler) {
this.log = LogFactory.getLog(handler.getClass());
}
- public void connected(final NHttpClientConnection conn, final Object attachment) {
+ public void connected(
+ final NHttpClientConnection conn,
+ final Object attachment) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Connected (" + attachment + ")");
}
@@ -71,24 +73,23 @@ public void closed(final NHttpClientConnection conn) {
this.handler.closed(conn);
}
- public void exception(final NHttpClientConnection conn, final IOException ex) {
+ public void exception(
+ final NHttpClientConnection conn, final Exception ex) {
this.log.error(conn + ": " + ex.getMessage(), ex);
this.handler.exception(conn, ex);
}
- public void exception(final NHttpClientConnection conn, final HttpException ex) {
- this.log.error(conn + ": " + ex.getMessage(), ex);
- this.handler.exception(conn, ex);
- }
-
- public void requestReady(final NHttpClientConnection conn) {
+ public void requestReady(
+ final NHttpClientConnection conn) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Request ready");
}
this.handler.requestReady(conn);
}
- public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
+ public void outputReady(
+ final NHttpClientConnection conn,
+ final ContentEncoder encoder) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Output ready");
}
@@ -98,15 +99,18 @@ public void outputReady(final NHttpClientConnection conn, final ContentEncoder e
}
}
- public void responseReceived(final NHttpClientConnection conn) {
+ public void responseReceived(
+ final NHttpClientConnection conn) throws IOException, HttpException {
HttpResponse response = conn.getHttpResponse();
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": " + response.getStatusLine());
}
this.handler.responseReceived(conn);
}
- public void inputReady(final NHttpClientConnection conn, final ContentDecoder decoder) {
+ public void inputReady(
+ final NHttpClientConnection conn,
+ final ContentDecoder decoder) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Input ready");
}
@@ -116,11 +120,12 @@ public void inputReady(final NHttpClientConnection conn, final ContentDecoder de
}
}
- public void timeout(final NHttpClientConnection conn) {
+ public void timeout(
+ final NHttpClientConnection conn) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Timeout");
}
this.handler.timeout(conn);
}
-}
+}
View
8 ...e-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServerConnection.java
@@ -41,7 +41,7 @@
import org.apache.http.impl.nio.DefaultNHttpServerConnection;
import org.apache.http.nio.NHttpMessageParser;
import org.apache.http.nio.NHttpMessageWriter;
-import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.NHttpServerEventHandler;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.nio.reactor.SessionOutputBuffer;
@@ -99,15 +99,15 @@ public void submitResponse(final HttpResponse response) throws IOException, Http
}
@Override
- public void consumeInput(final NHttpServiceHandler handler) {
+ public void consumeInput(final NHttpServerEventHandler handler) {
if (this.log.isDebugEnabled()) {
this.log.debug(this.id + ": Consume input");
}
super.consumeInput(handler);
}
@Override
- public void produceOutput(final NHttpServiceHandler handler) {
+ public void produceOutput(final NHttpServerEventHandler handler) {
if (this.log.isDebugEnabled()) {
this.log.debug(this.id + ": Produce output");
}
@@ -193,4 +193,4 @@ public HttpRequest parse() throws IOException, HttpException {
}
-}
+}
View
38 ...ore-contrib/src/main/java/org/apache/http/contrib/logging/LoggingNHttpServiceHandler.java
@@ -36,19 +36,19 @@
import org.apache.http.nio.ContentDecoder;
import org.apache.http.nio.ContentEncoder;
import org.apache.http.nio.NHttpServerConnection;
-import org.apache.http.nio.NHttpServiceHandler;
+import org.apache.http.nio.NHttpServerEventHandler;
/**
* Decorator class intended to transparently extend an {@link NHttpServiceHandler}
* with basic event logging capabilities using Commons Logging.
*
*/
-public class LoggingNHttpServiceHandler implements NHttpServiceHandler {
+public class LoggingNHttpServiceHandler implements NHttpServerEventHandler {
private final Log log;
- private final NHttpServiceHandler handler;
+ private final NHttpServerEventHandler handler;
- public LoggingNHttpServiceHandler(final NHttpServiceHandler handler) {
+ public LoggingNHttpServiceHandler(final NHttpServerEventHandler handler) {
super();
if (handler == null) {
throw new IllegalArgumentException("HTTP service handler may not be null");
@@ -57,7 +57,8 @@ public LoggingNHttpServiceHandler(final NHttpServiceHandler handler) {
this.log = LogFactory.getLog(handler.getClass());
}
- public void connected(final NHttpServerConnection conn) {
+ public void connected(
+ final NHttpServerConnection conn) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Connected");
}
@@ -71,25 +72,24 @@ public void closed(final NHttpServerConnection conn) {
this.handler.closed(conn);
}
- public void exception(final NHttpServerConnection conn, final IOException ex) {
+ public void exception(
+ final NHttpServerConnection conn, final Exception ex) {
this.log.error(conn + ": " + ex.getMessage(), ex);
this.handler.exception(conn, ex);
}
- public void exception(final NHttpServerConnection conn, final HttpException ex) {
- this.log.error(conn + ": " + ex.getMessage(), ex);
- this.handler.exception(conn, ex);
- }
-
- public void requestReceived(final NHttpServerConnection conn) {
+ public void requestReceived(
+ final NHttpServerConnection conn) throws IOException, HttpException {
HttpRequest request = conn.getHttpRequest();
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": " + request.getRequestLine());
}
this.handler.requestReceived(conn);
}
- public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {
+ public void outputReady(
+ final NHttpServerConnection conn,
+ final ContentEncoder encoder) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Output ready");
}
@@ -99,14 +99,17 @@ public void outputReady(final NHttpServerConnection conn, final ContentEncoder e
}
}
- public void responseReady(final NHttpServerConnection conn) {
+ public void responseReady(
+ final NHttpServerConnection conn) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Response ready");
}
this.handler.responseReady(conn);
}
- public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder) {
+ public void inputReady(
+ final NHttpServerConnection conn,
+ final ContentDecoder decoder) throws IOException, HttpException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Input ready");
}
@@ -116,11 +119,12 @@ public void inputReady(final NHttpServerConnection conn, final ContentDecoder de
}
}
- public void timeout(final NHttpServerConnection conn) {
+ public void timeout(
+ final NHttpServerConnection conn) throws IOException {
if (this.log.isDebugEnabled()) {
this.log.debug(conn + ": Timeout");
}
this.handler.timeout(conn);
}
-}
+}
View
6 httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpClient.java
@@ -112,8 +112,8 @@ public void run() {
});
// Start the client thread
t.start();
- // Create HTTP request executor
- HttpAsyncRequester executor = new HttpAsyncRequester(
+ // Create HTTP requester
+ HttpAsyncRequester requester = new HttpAsyncRequester(
httpproc, new DefaultConnectionReuseStrategy(), params);
// Execute HTTP GETs to the following hosts and
HttpHost[] targets = new HttpHost[] {
@@ -124,7 +124,7 @@ public void run() {
final CountDownLatch latch = new CountDownLatch(targets.length);
for (final HttpHost target: targets) {
BasicHttpRequest request = new BasicHttpRequest("GET", "/");
- executor.execute(
+ requester.execute(
new BasicAsyncRequestProducer(target, request),
new BasicAsyncResponseConsumer(),
pool,
View
3 httpcore-osgi/pom.xml
@@ -71,11 +71,8 @@
<instructions>
<Bundle-Name>Apache ${project.name}</Bundle-Name>
<Bundle-SymbolicName>${project.groupId}.httpcore</Bundle-SymbolicName>
- <Import-Package>!org.apache.http*,*</Import-Package>
<_exportcontents>org.apache.http.*;version=${project.version}</_exportcontents>
<Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
- <!-- Stop the JAVA_1_n_HOME variables from being treated as headers by Bnd -->
- <_removeheaders>JAVA_1_3_HOME,JAVA_1_4_HOME</_removeheaders>
</instructions>
</configuration>
</plugin>

0 comments on commit 3d2d373

Please sign in to comment.