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;
29  
30  import java.io.IOException;
31  
32  import org.apache.http.HttpException;
33  import org.apache.http.nio.ContentDecoder;
34  import org.apache.http.nio.ContentEncoder;
35  import org.apache.http.nio.NHttpClientConnection;
36  import org.apache.http.nio.NHttpClientHandler;
37  import org.apache.http.nio.NHttpClientEventHandler;
38  
39  /**
40   * @deprecated (4.2)
41   */
42  @Deprecated
43  class NHttpClientEventHandlerAdaptor implements NHttpClientEventHandler {
44  
45      private final NHttpClientHandler handler;
46  
47      public NHttpClientEventHandlerAdaptor(final NHttpClientHandler handler) {
48          super();
49          this.handler = handler;
50      }
51  
52      public void connected(final NHttpClientConnection conn, final Object attachment) {
53          this.handler.connected(conn, attachment);
54      }
55  
56      public void requestReady(
57              final NHttpClientConnection conn) throws IOException, HttpException {
58          this.handler.requestReady(conn);
59      }
60  
61      public void responseReceived(
62              final NHttpClientConnection conn) throws IOException, HttpException {
63          this.handler.responseReceived(conn);
64      }
65  
66      public void inputReady(
67              final NHttpClientConnection conn,
68              final ContentDecoder decoder) throws IOException, HttpException {
69          this.handler.inputReady(conn, decoder);
70      }
71  
72      public void outputReady(
73              final NHttpClientConnection conn,
74              final ContentEncoder encoder) throws IOException, HttpException {
75          this.handler.outputReady(conn, encoder);
76      }
77  
78      public void exception(final NHttpClientConnection conn, final Exception ex) {
79          if (ex instanceof HttpException) {
80              this.handler.exception(conn, (HttpException) ex);
81          } else if (ex instanceof IOException) {
82              this.handler.exception(conn, (IOException) ex);
83          } else {
84              if (ex instanceof RuntimeException) {
85                  throw (RuntimeException) ex;
86              } else {
87                  throw new Error("Unexpected exception: ", ex);
88              }
89          }
90      }
91  
92      public void endOfInput(final NHttpClientConnection conn) throws IOException {
93          conn.close();
94      }
95  
96      public void timeout(final NHttpClientConnection conn) {
97          this.handler.timeout(conn);
98      }
99  
100     public void closed(final NHttpClientConnection conn) {
101         this.handler.closed(conn);
102     }
103 
104 }