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.conn; 029 030import java.io.IOException; 031import java.io.InterruptedIOException; 032import java.net.InetAddress; 033import java.util.Arrays; 034 035import org.apache.http.HttpHost; 036 037/** 038 * A timeout while connecting to an HTTP server or waiting for an 039 * available connection from an HttpConnectionManager. 040 * 041 * 042 * @since 4.0 043 */ 044public class ConnectTimeoutException extends InterruptedIOException { 045 046 private static final long serialVersionUID = -4816682903149535989L; 047 048 private final HttpHost host; 049 050 /** 051 * Creates a ConnectTimeoutException with a {@code null} detail message. 052 */ 053 public ConnectTimeoutException() { 054 super(); 055 this.host = null; 056 } 057 058 /** 059 * Creates a ConnectTimeoutException with the specified detail message. 060 */ 061 public ConnectTimeoutException(final String message) { 062 super(message); 063 this.host = null; 064 } 065 066 /** 067 * Creates a ConnectTimeoutException based on original {@link IOException}. 068 * 069 * @since 4.3 070 */ 071 public ConnectTimeoutException( 072 final IOException cause, 073 final HttpHost host, 074 final InetAddress... remoteAddresses) { 075 super("Connect to " + 076 (host != null ? host.toHostString() : "remote host") + 077 (remoteAddresses != null && remoteAddresses.length > 0 ? 078 " " + Arrays.asList(remoteAddresses) : "") + 079 ((cause != null && cause.getMessage() != null) ? 080 " failed: " + cause.getMessage() : " timed out")); 081 this.host = host; 082 initCause(cause); 083 } 084 085 /** 086 * @since 4.3 087 */ 088 public HttpHost getHost() { 089 return host; 090 } 091 092}