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.NHttpClientEventHandler;
37  import org.apache.http.nio.NHttpClientHandler;
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      @Override
53      public void connected(final NHttpClientConnection conn, final Object attachment) {
54          this.handler.connected(conn, attachment);
55      }
56  
57      @Override
58      public void requestReady(
59              final NHttpClientConnection conn) throws IOException, HttpException {
60          this.handler.requestReady(conn);
61      }
62  
63      @Override
64      public void responseReceived(
65              final NHttpClientConnection conn) throws IOException, HttpException {
66          this.handler.responseReceived(conn);
67      }
68  
69      @Override
70      public void inputReady(
71              final NHttpClientConnection conn,
72              final ContentDecoder decoder) throws IOException, HttpException {
73          this.handler.inputReady(conn, decoder);
74      }
75  
76      @Override
77      public void outputReady(
78              final NHttpClientConnection conn,
79              final ContentEncoder encoder) throws IOException, HttpException {
80          this.handler.outputReady(conn, encoder);
81      }
82  
83      @Override
84      public void exception(final NHttpClientConnection conn, final Exception ex) {
85          if (ex instanceof HttpException) {
86              this.handler.exception(conn, (HttpException) ex);
87          } else if (ex instanceof IOException) {
88              this.handler.exception(conn, (IOException) ex);
89          } else {
90              if (ex instanceof RuntimeException) {
91                  throw (RuntimeException) ex;
92              } else {
93                  throw new Error("Unexpected exception: ", ex);
94              }
95          }
96      }
97  
98      @Override
99      public void endOfInput(final NHttpClientConnection conn) throws IOException {
100         conn.close();
101     }
102 
103     @Override
104     public void timeout(final NHttpClientConnection conn) {
105         this.handler.timeout(conn);
106     }
107 
108     @Override
109     public void closed(final NHttpClientConnection conn) {
110         this.handler.closed(conn);
111     }
112 
113 }