Index: java/org/apache/commons/httpclient/ChunkedInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedInputStream.java,v retrieving revision 1.18 diff -u -r1.18 ChunkedInputStream.java --- java/org/apache/commons/httpclient/ChunkedInputStream.java 16 Jul 2003 20:48:27 -0000 1.18 +++ java/org/apache/commons/httpclient/ChunkedInputStream.java 30 Jul 2003 12:02:22 -0000 @@ -67,6 +67,7 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.commons.httpclient.util.ExceptionUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -337,7 +338,9 @@ footers = HttpParser.parseHeaders(in); } catch(HttpException e) { LOG.error("Error parsing trailer headers", e); - throw new IOException(e.getMessage()); + IOException ioe = new IOException(e.getMessage()); + ExceptionUtil.initCause(ioe, e); + throw ioe; } for (int i = 0; i < footers.length; i++) { Index: java/org/apache/commons/httpclient/ChunkedOutputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ChunkedOutputStream.java,v retrieving revision 1.10 diff -u -r1.10 ChunkedOutputStream.java --- java/org/apache/commons/httpclient/ChunkedOutputStream.java 19 Apr 2003 22:29:31 -0000 1.10 +++ java/org/apache/commons/httpclient/ChunkedOutputStream.java 30 Jul 2003 12:02:23 -0000 @@ -121,7 +121,7 @@ */ public ChunkedOutputStream(OutputStream stream) { if (stream == null) { - throw new NullPointerException("stream parameter is null"); + throw new IllegalArgumentException("Stream parameter may not be null"); } this.stream = stream; } Index: java/org/apache/commons/httpclient/HttpConnection.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnection.java,v retrieving revision 1.69 diff -u -r1.69 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 16 Jul 2003 20:48:27 -0000 1.69 +++ java/org/apache/commons/httpclient/HttpConnection.java 30 Jul 2003 12:02:24 -0000 @@ -1214,7 +1214,7 @@ "Output exception occurred on a used connection. Will treat as recoverable.", ioe ); - return new HttpRecoverableException(ioe.toString()); + return new HttpRecoverableException(ioe.getMessage(), ioe); } else { return ioe; } Index: java/org/apache/commons/httpclient/HttpException.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpException.java,v retrieving revision 1.14 diff -u -r1.14 HttpException.java --- java/org/apache/commons/httpclient/HttpException.java 15 Jul 2003 02:19:58 -0000 1.14 +++ java/org/apache/commons/httpclient/HttpException.java 30 Jul 2003 12:02:24 -0000 @@ -70,20 +70,9 @@ /** * Signals that an HTTP or HttpClient exception has occurred. - *

- * The usage of the reserved status and reason codes - *

- * - * @author Unascribed + * + * @author Laura Werner + * * @version $Revision: 1.14 $ $Date: 2003/07/15 02:19:58 $ */ public class HttpException extends IOException { @@ -123,7 +112,6 @@ Method initCause = Throwable.class.getMethod("initCause", paramsClasses); initCause.invoke(this, new Object[] { cause }); } catch (Exception e) { - e.printStackTrace(); // The setCause method must not be available } } Index: java/org/apache/commons/httpclient/HttpRecoverableException.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java,v retrieving revision 1.9 diff -u -r1.9 HttpRecoverableException.java --- java/org/apache/commons/httpclient/HttpRecoverableException.java 16 Jul 2003 20:48:27 -0000 1.9 +++ java/org/apache/commons/httpclient/HttpRecoverableException.java 30 Jul 2003 12:02:24 -0000 @@ -65,6 +65,8 @@ import java.io.IOException; +import org.apache.commons.httpclient.util.ExceptionUtil; + /** *

* Signals that an HTTP or HttpClient exception has occurred. This @@ -102,5 +104,7 @@ */ public HttpRecoverableException(String message, Throwable cause) { super(message); + // If we're running on JDK 1.4 or later, tell Throwable what the cause was + ExceptionUtil.initCause(this, cause); } } Index: java/org/apache/commons/httpclient/HttpTimeoutException.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpTimeoutException.java,v retrieving revision 1.1 diff -u -r1.1 HttpTimeoutException.java --- java/org/apache/commons/httpclient/HttpTimeoutException.java 15 Jul 2003 02:19:58 -0000 1.1 +++ java/org/apache/commons/httpclient/HttpTimeoutException.java 30 Jul 2003 12:02:24 -0000 @@ -95,7 +95,7 @@ * if the cause is unavailable, unknown, or not a Throwable */ public HttpTimeoutException(String message, Throwable cause) { - super(message); + super(message, cause); } } Index: java/org/apache/commons/httpclient/util/ExceptionUtil.java =================================================================== RCS file: java/org/apache/commons/httpclient/util/ExceptionUtil.java diff -N java/org/apache/commons/httpclient/util/ExceptionUtil.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ java/org/apache/commons/httpclient/util/ExceptionUtil.java 30 Jul 2003 12:02:25 -0000 @@ -0,0 +1,119 @@ +/* + * $Header$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * The Apache Software License, Version 1.1 + * + * Copyright (c) 1999-2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "The Jakarta Project", "Commons", and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + * [Additional notices, if required by prior licensing conditions] + * + */ +package org.apache.commons.httpclient.util; + +import java.lang.reflect.Method; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * The home for utility methods that handle various exception-related tasks. + * + * @author Oleg Kalnichevski + * @author Laura Werner + * + * @since 2.1 + */ +public class ExceptionUtil { + + /** Log object for this class. */ + private static final Log LOG = LogFactory.getLog(ExceptionUtil.class); + + /** A reference to Throwable's initCause method, or null if it's not there in this JVM */ + static private final Method initCause = getInitCauseMethod(); + + /** + * Returns a Method allowing access to + * {@link Throwable.initCause(Throwable) initCause} method of {@link Throwable}, + * or null if the method + * does not exist. + * + * @return A Method for Throwable.initCause, or + * null if unavailable. + */ + static private Method getInitCauseMethod() { + try { + Class[] paramsClasses = new Class[] { Throwable.class }; + return Throwable.class.getMethod("initCause", paramsClasses); + } catch (NoSuchMethodException e) { + return null; + } + } + + /** + * If we're running on JDK 1.4 or later, initialize the cause for the given throwable. + * + * @param throwable The throwable. + * @param cause The cause of the throwable. + */ + public static void initCause(Throwable throwable, Throwable cause) { + if (initCause != null) { + try { + initCause.invoke(throwable, new Object[] { cause }); + } catch (Exception e) { + LOG.warn("Exception invoking Throwable.initCause", e); + } + } + } +} Index: test/org/apache/commons/httpclient/TestExceptions.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestExceptions.java,v retrieving revision 1.1 diff -u -r1.1 TestExceptions.java --- test/org/apache/commons/httpclient/TestExceptions.java 15 Jul 2003 02:19:58 -0000 1.1 +++ test/org/apache/commons/httpclient/TestExceptions.java 30 Jul 2003 12:02:25 -0000 @@ -66,7 +66,9 @@ import java.io.PrintWriter; import java.io.StringWriter; +import junit.framework.Test; import junit.framework.TestCase; +import junit.framework.TestSuite; /** * @@ -75,13 +77,21 @@ public class TestExceptions extends TestCase { - /** - * Constructor for TestExceptions. - * @param arg0 - */ - public TestExceptions(String arg0) - { - super(arg0); + // ------------------------------------------------------------ Constructor + public TestExceptions(String testName) { + super(testName); + } + + // ------------------------------------------------------------------- Main + public static void main(String args[]) { + String[] testCaseName = { TestChallengeParser.class.getName() }; + junit.textui.TestRunner.main(testCaseName); + } + + // ------------------------------------------------------- TestCase Methods + + public static Test suite() { + return new TestSuite(TestChallengeParser.class); } /** Make sure that you can retrieve the "cause" from an HttpException */ Index: test/org/apache/commons/httpclient/TestNoHost.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestNoHost.java,v retrieving revision 1.23 diff -u -r1.23 TestNoHost.java --- test/org/apache/commons/httpclient/TestNoHost.java 13 Jul 2003 13:54:51 -0000 1.23 +++ test/org/apache/commons/httpclient/TestNoHost.java 30 Jul 2003 12:02:25 -0000 @@ -105,6 +105,7 @@ suite.addTest(TestRequestLine.suite()); suite.addTest(TestPartsNoHost.suite()); suite.addTest(TestMethodCharEncoding.suite()); + suite.addTest(TestExceptions.suite()); return suite; }