1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements.  See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License.  You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package java.net;
18
19import java.io.IOException;
20
21/**
22 * If a HTTP request has to be retried, this exception will be thrown if the
23 * request cannot be retried automatically.
24 */
25public class HttpRetryException extends IOException {
26
27    private static final long serialVersionUID = -9186022286469111381L;
28
29    private int responseCode;
30
31    private String location = null;
32
33    /**
34     * Creates a new {@code HttpRetryException} instance with the specified
35     * response code and the given detail message.
36     *
37     * @param detail
38     *            the detail message for this exception.
39     * @param code
40     *            the HTTP response code from target host.
41     */
42    public HttpRetryException(String detail, int code) {
43        super(detail);
44        responseCode = code;
45    }
46
47    /**
48     * Creates a new {@code HttpRetryException} instance with the specified
49     * response code, the given detail message and the value of the location
50     * field from the response header.
51     *
52     * @param detail
53     *            the detail message for this exception.
54     * @param code
55     *            the HTTP response code from target host.
56     * @param location
57     *            the destination URL of the redirection.
58     */
59    public HttpRetryException(String detail, int code, String location) {
60        super(detail);
61        responseCode = code;
62        this.location = location;
63    }
64
65    /**
66     * Gets the location value.
67     *
68     * @return the stored location from the HTTP header.
69     */
70    public String getLocation() {
71        return location;
72    }
73
74    /**
75     * Gets the detail message.
76     *
77     * @return the detail message.
78     */
79    public String getReason() {
80        return getMessage();
81    }
82
83    /**
84     * Gets the response code.
85     *
86     * @return the HTTP response code.
87     */
88    public int responseCode() {
89        return responseCode;
90    }
91}
92