001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.impl.nio; 029 030import java.io.IOException; 031 032import org.apache.http.HttpException; 033import org.apache.http.nio.ContentDecoder; 034import org.apache.http.nio.ContentEncoder; 035import org.apache.http.nio.NHttpClientConnection; 036import org.apache.http.nio.NHttpClientEventHandler; 037import org.apache.http.nio.NHttpClientHandler; 038 039/** 040 * @deprecated (4.2) 041 */ 042@Deprecated 043class NHttpClientEventHandlerAdaptor implements NHttpClientEventHandler { 044 045 private final NHttpClientHandler handler; 046 047 public NHttpClientEventHandlerAdaptor(final NHttpClientHandler handler) { 048 super(); 049 this.handler = handler; 050 } 051 052 @Override 053 public void connected(final NHttpClientConnection conn, final Object attachment) { 054 this.handler.connected(conn, attachment); 055 } 056 057 @Override 058 public void requestReady( 059 final NHttpClientConnection conn) throws IOException, HttpException { 060 this.handler.requestReady(conn); 061 } 062 063 @Override 064 public void responseReceived( 065 final NHttpClientConnection conn) throws IOException, HttpException { 066 this.handler.responseReceived(conn); 067 } 068 069 @Override 070 public void inputReady( 071 final NHttpClientConnection conn, 072 final ContentDecoder decoder) throws IOException, HttpException { 073 this.handler.inputReady(conn, decoder); 074 } 075 076 @Override 077 public void outputReady( 078 final NHttpClientConnection conn, 079 final ContentEncoder encoder) throws IOException, HttpException { 080 this.handler.outputReady(conn, encoder); 081 } 082 083 @Override 084 public void exception(final NHttpClientConnection conn, final Exception ex) { 085 if (ex instanceof HttpException) { 086 this.handler.exception(conn, (HttpException) ex); 087 } else if (ex instanceof IOException) { 088 this.handler.exception(conn, (IOException) ex); 089 } else { 090 if (ex instanceof RuntimeException) { 091 throw (RuntimeException) ex; 092 } else { 093 throw new Error("Unexpected exception: ", ex); 094 } 095 } 096 } 097 098 @Override 099 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}