2
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/HttpException.java,v 1.19 2004/09/30 18:53:20 olegk Exp $
4
* $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
6
* ====================================================================
8
* Licensed to the Apache Software Foundation (ASF) under one or more
9
* contributor license agreements. See the NOTICE file distributed with
10
* this work for additional information regarding copyright ownership.
11
* The ASF licenses this file to You under the Apache License, Version 2.0
12
* (the "License"); you may not use this file except in compliance with
13
* the License. You may obtain a copy of the License at
15
* http://www.apache.org/licenses/LICENSE-2.0
17
* Unless required by applicable law or agreed to in writing, software
18
* distributed under the License is distributed on an "AS IS" BASIS,
19
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
* See the License for the specific language governing permissions and
21
* limitations under the License.
22
* ====================================================================
24
* This software consists of voluntary contributions made by many
25
* individuals on behalf of the Apache Software Foundation. For more
26
* information on the Apache Software Foundation, please see
27
* <http://www.apache.org/>.
31
package org.apache.commons.httpclient;
33
import java.io.IOException;
34
import java.io.PrintStream;
35
import java.io.PrintWriter;
36
import java.lang.reflect.Method;
39
* Signals that an HTTP or HttpClient exception has occurred.
41
* @author Laura Werner
43
* @version $Revision: 480424 $ $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
45
public class HttpException extends IOException {
48
* Creates a new HttpException with a <tt>null</tt> detail message.
50
public HttpException() {
56
* Creates a new HttpException with the specified detail message.
58
* @param message the exception detail message
60
public HttpException(String message) {
66
* Creates a new HttpException with the specified detail message and cause.
68
* @param message the exception detail message
69
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
70
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
74
public HttpException(String message, Throwable cause) {
78
// If we're running on JDK 1.4 or later, tell Throwable what the cause was
80
Class[] paramsClasses = new Class[] { Throwable.class };
81
Method initCause = Throwable.class.getMethod("initCause", paramsClasses);
82
initCause.invoke(this, new Object[] { cause });
83
} catch (Exception e) {
84
// The setCause method must not be available
89
* Return the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
90
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>.
92
* @return the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
93
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
97
public Throwable getCause() {
102
* Print this HttpException and its stack trace to the standard error stream.
106
public void printStackTrace() {
107
printStackTrace(System.err);
111
* Print this HttpException and its stack trace to the specified print stream.
113
* @param s the <tt>PrintStream</tt> to which the exception and its stack trace
118
public void printStackTrace(PrintStream s) {
120
// JDK 1.4 has a nice printStackTrace method that prints the cause's stack
121
// trace too and prunes out duplicate stack frames. Call it if possible,
122
// which is determined by checking whether JDK 1.4's getStackTrace method is present
123
Class[] paramsClasses = new Class[] { };
124
this.getClass().getMethod("getStackTrace", paramsClasses);
125
super.printStackTrace(s);
126
} catch (Exception ex) {
127
// If that didn't work, print it out ourselves
128
// First print this exception's stack trace.
129
super.printStackTrace(s);
131
// Print out the exception that caused this one.
132
// This will recurse if the cause is another HttpException.
133
s.print("Caused by: ");
134
cause.printStackTrace(s);
140
* Print this HttpException and its stack trace to the specified print writer.
142
* @param s the <tt>PrintWriter</tt> to which the exception and its stack trace
147
public void printStackTrace(PrintWriter s) {
149
// JDK 1.4 has a nice printStackTrace method that prints the cause's stack
150
// trace too and prunes out duplicate stack frames. Call it if possible,
151
// which is determined by checking whether JDK 1.4's getStackTrace method is present
152
Class[] paramsClasses = new Class[] { };
153
this.getClass().getMethod("getStackTrace", paramsClasses);
154
super.printStackTrace(s);
155
} catch (Exception ex) {
156
// If that didn't work, print it out ourselves
157
// First print this exception's stack trace.
158
super.printStackTrace(s);
160
// Print out the exception that caused this one.
161
// This will recurse if the cause is another HttpException.
162
s.print("Caused by: ");
163
cause.printStackTrace(s);
169
* Sets the text description of the reason for an exception.
171
* @param reason The reason for the exception.
173
* @deprecated HttpClient no longer uses this for itself. It is only
174
* provided for compatibility with existing clients, and will be removed
175
* in a future release.
177
public void setReason(String reason) {
178
this.reason = reason;
182
* Get the text description of the reason for an exception.
184
* @deprecated HttpClient no longer uses this for itself. It is only
185
* provided for compatibility with existing clients, and will be removed
186
* in a future release.
188
public String getReason() {
193
* Sets the status code description of the reason for an exception.
195
* @param code The reason for the exception. This is intended to be an
198
* @deprecated HttpClient no longer uses this for itself. It is only
199
* provided for compatibility with existing clients, and will be removed
200
* in a future release.
202
public void setReasonCode(int code) {
207
* Get the status code description of the reason for an exception.
209
* @deprecated HttpClient no longer uses this for itself. It is only
210
* provided for compatibility with existing clients, and will be removed
211
* in a future release.
213
public int getReasonCode() {
214
return this.reasonCode;
218
* A "reason" string provided for compatibility with older clients.
220
* @deprecated HttpClient no longer uses this field for itself. It
221
* is only provided for compatibility with existing clients.
223
private String reason;
226
* Reason code for compatibility with older clients.
228
* @deprecated HttpClient no longer uses this field for itself.
229
* It is only provided for compatibility with existing clients.
231
private int reasonCode = HttpStatus.SC_OK;
233
/** The original Throwable representing the cause of this error */
234
private final Throwable cause;