View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
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 }