1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.http.impl.nio.client;
29
30 import java.io.IOException;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.http.HttpException;
34 import org.apache.http.nio.ContentDecoder;
35 import org.apache.http.nio.ContentEncoder;
36 import org.apache.http.nio.NHttpClientConnection;
37 import org.apache.http.nio.NHttpClientEventHandler;
38
39 class InternalRequestExecutor implements NHttpClientEventHandler {
40
41 private final Log log;
42 private final NHttpClientEventHandler handler;
43
44 public InternalRequestExecutor(final Log log, final NHttpClientEventHandler handler) {
45 this.log = log;
46 this.handler = handler;
47 }
48
49 @Override
50 public void connected(
51 final NHttpClientConnection conn,
52 final Object attachment) throws IOException, HttpException {
53 if (this.log.isDebugEnabled()) {
54 this.log.debug(conn + ": Connected");
55 }
56 this.handler.connected(conn, attachment);
57 }
58
59 @Override
60 public void closed(final NHttpClientConnection conn) {
61 if (this.log.isDebugEnabled()) {
62 this.log.debug(conn + ": Disconnected");
63 }
64 this.handler.closed(conn);
65 }
66
67 @Override
68 public void requestReady(
69 final NHttpClientConnection conn) throws IOException, HttpException {
70 if (this.log.isDebugEnabled()) {
71 this.log.debug(conn + " Request ready");
72 }
73 this.handler.requestReady(conn);
74 }
75
76 @Override
77 public void inputReady(
78 final NHttpClientConnection conn,
79 final ContentDecoder decoder) throws IOException, HttpException {
80 if (this.log.isDebugEnabled()) {
81 this.log.debug(conn + " Input ready");
82 }
83 this.handler.inputReady(conn, decoder);
84 if (this.log.isDebugEnabled()) {
85 this.log.debug(conn + " " + decoder);
86 }
87 }
88
89 @Override
90 public void outputReady(
91 final NHttpClientConnection conn,
92 final ContentEncoder encoder) throws IOException, HttpException {
93 if (this.log.isDebugEnabled()) {
94 this.log.debug(conn + " Output ready");
95 }
96 this.handler.outputReady(conn, encoder);
97 if (this.log.isDebugEnabled()) {
98 this.log.debug(conn + " " + encoder);
99 }
100 }
101
102 @Override
103 public void responseReceived(
104 final NHttpClientConnection conn) throws HttpException, IOException {
105 if (this.log.isDebugEnabled()) {
106 this.log.debug(conn + " Response received");
107 }
108 this.handler.responseReceived(conn);
109 }
110
111 @Override
112 public void timeout(final NHttpClientConnection conn) throws HttpException, IOException {
113 if (this.log.isDebugEnabled()) {
114 this.log.debug(conn + " Timeout");
115 }
116 this.handler.timeout(conn);
117 }
118
119 @Override
120 public void exception(final NHttpClientConnection conn, final Exception ex) {
121 if (this.log.isDebugEnabled()) {
122 this.log.debug(conn + " Exception", ex);
123 }
124 this.handler.exception(conn, ex);
125 }
126
127 @Override
128 public void endOfInput(final NHttpClientConnection conn) throws IOException {
129 if (this.log.isDebugEnabled()) {
130 this.log.debug(conn + " End of input");
131 }
132 this.handler.endOfInput(conn);
133 }
134
135 }