? log2.diff ? log3.diff Index: java/org/apache/commons/httpclient/Authenticator.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java,v retrieving revision 1.22 diff -u -u -r1.22 Authenticator.java --- java/org/apache/commons/httpclient/Authenticator.java 26 Jul 2002 00:45:01 -0000 1.22 +++ java/org/apache/commons/httpclient/Authenticator.java 28 Jul 2002 17:55:09 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -98,7 +98,7 @@ class Authenticator { /** org.apache.commons.httpclient.Authenticator log. */ - private static final Log log = LogFactory.getLog(Authenticator.class.getName()); + private static final Log log = LogFactory.getLog(Authenticator.class); /** Base 64 encoder. */ private static Base64 base64 = new Base64(); @@ -149,13 +149,12 @@ * @see #authenticate(HttpMethod,HttpState,Header,String) */ static boolean authenticate(HttpMethod method, HttpState state) - throws HttpException, UnsupportedOperationException { + throws HttpException, UnsupportedOperationException { + log.trace("enter Authenticator.authenticate(HttpMethod, HttpState)"); - log.debug("enter Authenticator.authenticate(HttpMethod, HttpState)"); - Header challengeHeader = method.getResponseHeader(WWW_AUTH); - - return authenticate(method, state, challengeHeader, WWW_AUTH_RESP); - } + Header challengeHeader = method.getResponseHeader(WWW_AUTH); + return authenticate(method, state, challengeHeader, WWW_AUTH_RESP); + } /** * Add requisite proxy authentication credentials to the given method @@ -172,13 +171,12 @@ * @see #authenticate(HttpMethod,HttpState,Header,String) */ static boolean authenticateProxy(HttpMethod method, HttpState state) - throws HttpException, UnsupportedOperationException { - - log.debug("enter Authenticator.authenticateProxy(HttpMethod, HttpState)"); - Header challengeHeader = method.getResponseHeader(PROXY_AUTH); + throws HttpException, UnsupportedOperationException { + log.trace("enter Authenticator.authenticateProxy(HttpMethod, HttpState)"); - return authenticate(method, state, challengeHeader, PROXY_AUTH_RESP); - } + Header challengeHeader = method.getResponseHeader(PROXY_AUTH); + return authenticate(method, state, challengeHeader, PROXY_AUTH_RESP); + } /** @@ -202,8 +200,10 @@ * @see #digest * @see HttpMethod#addRequestHeader */ - private static boolean authenticate(HttpMethod method, HttpState state, Header challengeHeader, String respHeader) throws HttpException, UnsupportedOperationException { - log.debug("enter Authenticator.authenticate(HttpMethod, HttpState, Header, String)"); + private static boolean authenticate(HttpMethod method, HttpState state, Header challengeHeader, String respHeader) + throws HttpException, UnsupportedOperationException { + + log.trace("enter Authenticator.authenticate(HttpMethod, HttpState, Header, String)"); //check the preemptive policy //TODO: this needs to be a service from some configuration class @@ -296,9 +296,10 @@ * * @throws HttpException when no matching credentials are available */ - static Header basic(String realm, HttpState state, String respHeader) throws HttpException { + static Header basic(String realm, HttpState state, String respHeader) + throws HttpException { + log.trace("enter Authenticator.basic(String, HttpState, String)"); - log.debug("enter Authenticator.basic(String, HttpState)"); boolean proxy = PROXY_AUTH_RESP.equals(respHeader); UsernamePasswordCredentials cred = null; try { @@ -320,7 +321,10 @@ * Return a Basic Authorization header value for the * given {@link UsernamePasswordCredentials}. */ - static String basic(UsernamePasswordCredentials cred) throws HttpException { + static String basic(UsernamePasswordCredentials cred) + throws HttpException { + log.trace("enter Authenticator.basic(UsernamePasswordCredentials)"); + String authString = cred.getUserName() + ":" + cred.getPassword(); return "Basic " + new String(base64.encode(authString.getBytes())); } @@ -338,8 +342,10 @@ * * @throws HttpException when no matching credentials are available */ - static Header digest(String realm, HttpMethod method, HttpState state, String respHeader) throws HttpException { - log.debug("Authenticator.digest(String,HttpState)"); + static Header digest(String realm, HttpMethod method, HttpState state, String respHeader) + throws HttpException { + log.trace("enter Authenticator.digest(String, HttpMethod, HttpState, String)"); + boolean proxy = PROXY_AUTH_RESP.equals(respHeader); UsernamePasswordCredentials cred = null; try { @@ -377,7 +383,10 @@ * Return a Digest Authorization header value for the * given {@link UsernamePasswordCredentials}. */ - static String digest(UsernamePasswordCredentials cred, Hashtable headers) throws HttpException { + static String digest(UsernamePasswordCredentials cred, Hashtable headers) + throws HttpException { + log.trace("enter Authenticator.digest(UsernamePasswordCredentials, Hashtable)"); + String digest = createDigest(cred.getUserName(), cred.getPassword(), headers); return "Digest " + createDigestHeader(cred.getUserName(), headers, digest); } @@ -394,8 +403,11 @@ * @return The created digest as string. This will be the response tag's * value in the Authentication HTTP header. */ - public static String createDigest(String uname, String pwd, Hashtable dCreds) throws HttpException { - String digAlg = "MD5"; + public static String createDigest(String uname, String pwd, Hashtable dCreds) + throws HttpException { + log.trace("enter Authenticator.createDigest(String, String, Hashtable)"); + + final String digAlg = "MD5"; // Collecting required tokens String uri = removeQuotes((String)dCreds.get("uri")); @@ -437,8 +449,10 @@ * @throws AxisFault if MD5 algorithm is not supported. */ private static String createCnonce() throws HttpException { + log.trace("enter Authenticator.createCnonce()"); + String cnonce; - String digAlg = "MD5"; + final String digAlg = "MD5"; MessageDigest md5Helper; try { md5Helper = MessageDigest.getInstance(digAlg); @@ -460,10 +474,12 @@ * @param uname Username * @param dCreds Hashtable containing header information (uri, realm, * nonce, nc, cnonce, opaque, qop). - * @digest The response tag's value as String. + * @param digest The response tag's value as String. * @return The digest-response as String. */ private static String createDigestHeader(String uname, Hashtable dCreds, String digest) { + log.trace("enter Authenticator.createDigestHeader(String, Hashtable, String)"); + StringBuffer sb = new StringBuffer(); String uri = removeQuotes((String)dCreds.get("uri")); String realm = removeQuotes((String)dCreds.get("realm")); @@ -502,6 +518,8 @@ * str */ private static String removeQuotes(String str) { + log.trace("enter Authenticator.removeQuotes(String)"); + if (str == null) return null; @@ -522,6 +540,7 @@ * @return encoded MD5, or null if encoding failed */ private static String encode( byte[] binaryData ) { + log.trace("enter Authenticator.encode(byte[])"); if (binaryData.length != 16) return null; @@ -555,9 +574,13 @@ * @return The parameters from www-authenticate header as a Hashtable */ private static Hashtable getHTTPDigestCredentials(HttpMethod method) { + log.trace("enter Authenticator.getHTTPDigestCredentials(HttpMethod)"); + String authHeader = method.getResponseHeader("www-authenticate").getValue(); Hashtable ht = new Hashtable(15); - if (authHeader == null) return ht; + if (authHeader == null) { + return ht; + } authHeader = authHeader.substring(7).trim(); int i = 0; int j = authHeader.indexOf(","); @@ -583,6 +606,8 @@ * entry is placed (only if it has "xxx=yyy" format). */ private static void processDigestToken(String token, Hashtable ht) { + log.trace("enter Authenticator.processDigestToken(String, Hashtable)"); + int eqpos = token.indexOf("="); if (eqpos > 0 && eqpos < token.length()-1) Index: java/org/apache/commons/httpclient/Base64.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Base64.java,v retrieving revision 1.9 diff -u -u -r1.9 Base64.java --- java/org/apache/commons/httpclient/Base64.java 10 Jul 2002 05:09:16 -0000 1.9 +++ java/org/apache/commons/httpclient/Base64.java 28 Jul 2002 17:55:10 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/ConnectMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ConnectMethod.java,v retrieving revision 1.1 diff -u -u -r1.1 ConnectMethod.java --- java/org/apache/commons/httpclient/ConnectMethod.java 23 Jul 2002 14:38:31 -0000 1.1 +++ java/org/apache/commons/httpclient/ConnectMethod.java 28 Jul 2002 17:55:11 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -80,6 +80,7 @@ * Create a connect method wrapping the existing method */ public ConnectMethod(HttpMethod method) { + log.trace("enter ConnectMethod(HttpMethod)"); this.method = method; } @@ -87,7 +88,10 @@ return NAME; } - public int execute(HttpState state, HttpConnection connection) throws IOException, HttpException { + public int execute(HttpState state, HttpConnection connection) + throws IOException, HttpException { + + log.trace("enter ConnectMethod.execute(HttpState, HttpConnection)"); int code = super.execute(state, connection); log.debug("CONNECT status code "+ code); if ((code >= 200) && (code < 300)) { @@ -100,7 +104,10 @@ /** * Writes a minimal set of headers to the proxy. */ - protected void writeRequestHeaders(HttpState state, HttpConnection conn) throws HttpException, IOException { + protected void writeRequestHeaders(HttpState state, HttpConnection conn) + throws HttpException, IOException { + log.trace("enter ConnectMethod.writeRequestHeaders(HttpState, HttpConnection)"); + if (method instanceof HttpMethodBase) { ((HttpMethodBase) method).addRequestHeaders(state, conn); } @@ -122,8 +129,13 @@ conn.printLine(line); } - /** the log for output */ - static private final Log log = LogFactory.getLog(ConnectMethod.class); + + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(ConnectMethod.class); + + /** Log for any wire messages. */ + private static final Log wireLog = LogFactory.getLog("httpclient.wirelog"); + /** The wrapped method */ private HttpMethod method; -} \ No newline at end of file +} Index: java/org/apache/commons/httpclient/Cookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v retrieving revision 1.20 diff -u -u -r1.20 Cookie.java --- java/org/apache/commons/httpclient/Cookie.java 21 Jul 2002 04:12:44 -0000 1.20 +++ java/org/apache/commons/httpclient/Cookie.java 28 Jul 2002 17:55:14 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -123,6 +123,7 @@ */ public Cookie(String domain, String name, String value, String path, Date expires, boolean secure) { super(name, value); + log.trace("enter Cookie(String, String, String, String, Date, boolean)"); this.setPath(path); this.setDomain(domain); this.setExpiryDate(expires); @@ -408,6 +409,7 @@ * Two cookies are equal if the name, path and domain match. */ public boolean equals(Object obj) { + log.trace("enter Cookie.equals(Object)"); if ((obj != null) && (obj instanceof Cookie)) { Cookie that = (Cookie) obj; return (null == this.getName() ? null == that.getName() : this.getName().equals(that.getName())) && @@ -447,6 +449,7 @@ * @param date the time at which the request is submitted */ public boolean matches(String domain, int port, String path, boolean secure, Date now) { + log.trace("enter Cookie.matches(Strinng, int, String, boolean, Date"); // FIXME: RFC2109 doesn't consider ports when filtering/matching // cookies. Quoting from Section 2 - Terminology: // The terms request-host and request-URI refer to @@ -484,7 +487,8 @@ * @param path the path to which the request is being submitted */ public boolean matches(String domain, int port, String path, boolean secure) { - return matches(domain,port,path,secure,new Date()); + log.trace("enter Cookie.matches(String, int, String, boolean"); + return matches(domain, port, path, secure, new Date()); } /** @@ -497,6 +501,7 @@ * If no cookies match, returns null. */ public static Header createCookieHeader(String domain, String path, Cookie[] cookies) { + log.trace("enter Cookie.createCookieHeader(String, String, Cookie[])"); return Cookie.createCookieHeader(domain,path,false,cookies); } @@ -510,7 +515,10 @@ * @exception java.lang.IllegalArgumentException if domain or path is null * @deprecated use the version which includes port number and date */ - public static Header createCookieHeader(String domain, String path, boolean secure, Cookie[] cookies) throws IllegalArgumentException { + public static Header createCookieHeader(String domain, String path, boolean secure, Cookie[] cookies) + throws IllegalArgumentException { + log.trace("enter Cookie.createCookieHeader(String, String, boolean, Cookie[])"); + // Make sure domain isn't null here. Path will be validated in subsequent call to createCookieHeader if(domain == null){ throw new IllegalArgumentException("null domain in createCookieHeader."); @@ -538,8 +546,10 @@ * If no cookies match, returns null. * @exception java.lang.IllegalArgumentException if domain or path is null */ - public static Header createCookieHeader(String domain, int port, String path, boolean secure, Cookie[] cookies) throws IllegalArgumentException { - return Cookie.createCookieHeader(domain,port,path,secure,new Date(),cookies); + public static Header createCookieHeader(String domain, int port, String path, boolean secure, Cookie[] cookies) + throws IllegalArgumentException { + log.trace("enter Cookie.createCookieHeader(String, int, String, bookean, Cookie[])"); + return Cookie.createCookieHeader(domain, port, path, secure, new Date(), cookies); } /** @@ -552,7 +562,10 @@ * If no cookies match, returns null. * @exception java.lang.IllegalArgumentException if domain or path is null */ - public static Header createCookieHeader(String domain, int port, String path, boolean secure, Date now, Cookie[] cookies) throws IllegalArgumentException { + public static Header createCookieHeader(String domain, int port, String path, boolean secure, Date now, Cookie[] cookies) + throws IllegalArgumentException { + log.trace("enter Cookie.createCookieHeader(String, int, String, bookean, Date, Cookie[])"); + // Validate the domain and path if(domain == null){ throw new IllegalArgumentException("null domain in createCookieHeader."); @@ -604,6 +617,8 @@ * of RFC2109

*/ public int compare(Object o1, Object o2) { + log.trace("enter Cookie.compare(Object, Object)"); + if (!(o1 instanceof Cookie)) { throw new ClassCastException(o1.getClass().getName()); } @@ -654,7 +669,9 @@ * @throws HttpException if an exception occurs during parsing * @throws java.lang.IllegalArgumentException if domain or path are null */ - public static Cookie[] parse(String domain, int port, String path, Header setCookie) throws HttpException, IllegalArgumentException { + public static Cookie[] parse(String domain, int port, String path, Header setCookie) + throws HttpException, IllegalArgumentException { + log.trace("enter Cookie.parse(String, int, String, Header)"); return Cookie.parse(domain,port,path,false,setCookie); } @@ -670,7 +687,9 @@ * @throws HttpException if an exception occurs during parsing * @throws java.lang.IllegalArgumentException if domain or path are null */ - public static Cookie[] parse(String domain, String path, Header setCookie) throws HttpException, IllegalArgumentException { + public static Cookie[] parse(String domain, String path, Header setCookie) + throws HttpException, IllegalArgumentException { + log.trace("enter Cookie.parse(String, String, Header)"); return Cookie.parse(domain,80,path,false,setCookie); } @@ -686,7 +705,9 @@ * @throws HttpException if an exception occurs during parsing * @throws java.lang.IllegalArgumentException if domain or path are null */ - public static Cookie[] parse(String domain, String path, boolean secure, Header setCookie) throws HttpException { + public static Cookie[] parse(String domain, String path, boolean secure, Header setCookie) + throws HttpException { + log.trace("enter Cookie.parse(String, String, boolean, Header)"); return Cookie.parse(domain,(secure ? 443 : 80),path,secure,setCookie); } @@ -718,7 +739,10 @@ * @throws HttpException if an exception occurs during parsing * @throws java.lang.IllegalArgumentException if domain or path are null */ - public static Cookie[] parse(String domain, int port, String path, boolean secure, Header setCookie) throws HttpException, IllegalArgumentException { + public static Cookie[] parse(String domain, int port, String path, boolean secure, Header setCookie) + throws HttpException, IllegalArgumentException { + log.trace("enter Cookie.parse(String, int, String, boolean, Header)"); + // Validate domain and path if(domain == null){ throw new IllegalArgumentException("domain may not be null."); @@ -1090,8 +1114,8 @@ Locale.US); } - /** org.apache.commons.httpclient.Cookie log. */ - private static final Log log = LogFactory.getLog(Cookie.class.getName()); + /** Log object for this class */ + private static final Log log = LogFactory.getLog(Cookie.class); } Index: java/org/apache/commons/httpclient/Credentials.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Credentials.java,v retrieving revision 1.4 diff -u -u -r1.4 Credentials.java --- java/org/apache/commons/httpclient/Credentials.java 5 Jan 2002 11:15:59 -0000 1.4 +++ java/org/apache/commons/httpclient/Credentials.java 28 Jul 2002 17:55:14 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/Header.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Header.java,v retrieving revision 1.7 diff -u -u -r1.7 Header.java --- java/org/apache/commons/httpclient/Header.java 14 Jul 2002 02:31:39 -0000 1.7 +++ java/org/apache/commons/httpclient/Header.java 28 Jul 2002 17:55:15 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/HeaderElement.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HeaderElement.java,v retrieving revision 1.9 diff -u -u -r1.9 HeaderElement.java --- java/org/apache/commons/httpclient/HeaderElement.java 21 Jul 2002 04:12:44 -0000 1.9 +++ java/org/apache/commons/httpclient/HeaderElement.java 28 Jul 2002 17:55:16 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -149,8 +149,8 @@ // -------------------------------------------------------- Constants - /** org.apache.commons.httpclient.HeaderElement log. */ - static private final Log log = LogFactory.getLog(HeaderElement.class.getName()); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(HeaderElement.class); /** * Map of numeric values to whether or not the @@ -254,8 +254,9 @@ * @throws HttpException if the above syntax rules are violated. */ public final static HeaderElement[] parse(String headerValue) - throws HttpException - { + throws HttpException { + log.trace("enter HeaderElement.parse(String)"); + if (headerValue == null) { return null; } @@ -371,6 +372,8 @@ * otherwise */ private final static boolean hasOddNumberOfQuotationMarks(String string) { + log.trace("enter HeaderElement.hasOddNumberOfQuotationMarks(String)"); + boolean odd = false; int start = -1; while ((start = string.indexOf('"', start+1)) != -1) { @@ -387,14 +390,15 @@ * @param end the end position of the text within the array * @return a {@link NameValuePair} representing the header */ - private final static NameValuePair parsePair(char[] header, int start, - int end) { + private final static NameValuePair parsePair(char[] header, int start, int end) { + log.trace("enter HeaderElement.parsePair(char[], int, int)"); boolean done = false; NameValuePair pair = null; String name = new String(header, start, end - start).trim(); String value = null; + //TODO: This would certainly benefit from a StringBuffer int index = name.indexOf("="); if (index >= 0) { if ((index + 1) < name.length()) { Index: java/org/apache/commons/httpclient/HttpClient.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpClient.java,v retrieving revision 1.52 diff -u -u -r1.52 HttpClient.java --- java/org/apache/commons/httpclient/HttpClient.java 23 Jul 2002 14:38:31 -0000 1.52 +++ java/org/apache/commons/httpclient/HttpClient.java 28 Jul 2002 17:55:17 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -89,7 +89,7 @@ // -------------------------------------------------------------- Constants - /** org.apache.commons.httpclient.HttpClient log. */ + /** Log object for this class. */ private static final Log log = LogFactory.getLog(HttpClient.class); // ----------------------------------------------------------- Constructors @@ -169,6 +169,7 @@ * @see #endSession() */ public void startSession(String host, int port) { + log.trace("enter HttpClient.startSession(String, int)"); startSession(host, port, false); } @@ -183,6 +184,8 @@ * */ public void startSession(String host, int port, boolean https) { + log.trace("enter HttpClient.startSession(String, int, boolean)"); + if (log.isDebugEnabled()) { log.debug("HttpClient.startSession(String,int,boolean): Host:" + host + " Port:" + port + " HTTPS:" + https); @@ -201,6 +204,7 @@ * @see #endSession() */ public void startSession(String host, int port, Credentials creds) { + log.trace("enter HttpClient.startSession(String, int, Credentials)"); startSession(host, port, creds, false); } @@ -216,12 +220,14 @@ * @param https when true, create an HTTPS session * @see #endSession() */ - public void startSession(String host, int port, Credentials creds, - boolean https) { + public void startSession(String host, int port, Credentials creds, boolean https) { + log.trace("enter HttpClient.startSession(String, int, Credentials, boolean)"); + if (log.isDebugEnabled()) { log.debug( - "HttpClient.startSession(String,int,Credentials,boolean): Host:" - + host + " Port:" + port + " Credentials:" + creds + "Starting HttpClient session" + + " Host:" + host + + " Port:" + port + " Credentials:" + creds + " HTTPS:" + https); } getState().setCredentials(null, creds); @@ -243,16 +249,18 @@ * */ public void startSession(URL url) { - if ("https".equalsIgnoreCase(url.getProtocol())) { - startSession(url.getHost(), url.getPort() == -1 ? 443 - : url.getPort(), true); - } else if ("http".equalsIgnoreCase(url.getProtocol())) { - startSession(url.getHost(), url.getPort() == -1 ? 80 - : url.getPort(), false); - } else { - throw new IllegalArgumentException("Protocol " + url.getProtocol() - + " not supported in URL " + url); - } + log.trace("enter HttpClient.startSession(String, int, Credentials, boolean)"); + + if ("https".equalsIgnoreCase(url.getProtocol())) { + startSession(url.getHost(), url.getPort() == -1 ? 443 + : url.getPort(), true); + } else if ("http".equalsIgnoreCase(url.getProtocol())) { + startSession(url.getHost(), url.getPort() == -1 ? 80 + : url.getPort(), false); + } else { + throw new IllegalArgumentException("Protocol " + url.getProtocol() + + " not supported in URL " + url); + } } /** @@ -271,6 +279,7 @@ * */ public void startSession(URL url, Credentials creds) { + log.trace("enter HttpClient.startSession(URL, Credentials)"); getState().setCredentials(null, creds); startSession(url); } @@ -287,8 +296,8 @@ * @see #endSession() * */ - public void startSession(String host, int port, - String proxyhost, int proxyport) { + public void startSession(String host, int port, String proxyhost, int proxyport) { + log.trace("enter HttpClient.startSession(String, int, String, int)"); startSession(host, port, proxyhost, proxyport, false); } @@ -306,11 +315,9 @@ * @see #endSession() * */ - public void startSession(String host, int port, - String proxyhost, int proxyport, - boolean secure) { - connection = new HttpConnection(proxyhost, proxyport, host, port, - secure); + public void startSession(String host, int port, String proxyhost, int proxyport, boolean secure) { + log.trace("enter HttpClient.startSession(String, int, String, int, boolean)"); + connection = new HttpConnection(proxyhost, proxyport, host, port, secure); } /** @@ -324,8 +331,9 @@ * @throws HttpException if a protocol exception occurs * @throws IllegalStateException if the session has not been started */ - public synchronized int executeMethod(HttpMethod method) throws IOException, - HttpException, IllegalStateException { + public synchronized int executeMethod(HttpMethod method) + throws IOException, HttpException, IllegalStateException { + log.trace("enter HttpClient.executeMethod(HttpMethod)"); if (null == method) { throw new NullPointerException("HttpMethod parameter"); @@ -361,7 +369,7 @@ * @throws IOException when i/o errors occur closing the connection */ public void endSession() throws IOException { - log.debug("HttpClient.endSession()"); + log.trace("enter HttpClient.endSession()"); if (null != connection) { connection.close(); connection = null; 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.12 diff -u -u -r1.12 HttpConnection.java --- java/org/apache/commons/httpclient/HttpConnection.java 23 Jul 2002 14:38:31 -0000 1.12 +++ java/org/apache/commons/httpclient/HttpConnection.java 28 Jul 2002 17:55:19 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -302,8 +302,8 @@ * protocol, such as a TCP error. * @throws IllegalStateException if I am not connected */ - public void setSoTimeout(int timeout) throws SocketException, - IllegalStateException { + public void setSoTimeout(int timeout) + throws SocketException, IllegalStateException { log.debug("HttpConnection.setSoTimeout("+ timeout +")"); _so_timeout = timeout; if(_socket != null){ @@ -318,7 +318,8 @@ * @throws IOException when there are errors opening the connection */ public void open() throws IOException { - log.debug("HttpConnection.open()"); + log.trace("enter HttpConnection.open()"); + assertNotOpen(); // ??? is this worth doing? try { if (null == _socket) { @@ -358,8 +359,14 @@ * @throws IOException if an error occured creating the secure socket */ public void tunnelCreated() throws IllegalStateException, IOException { - if (!isSecure() || !isProxied()) throw new IllegalStateException("Connection must be secure and proxied to use this feature"); - if (_usingSecureSocket) throw new IllegalStateException("Already using a secure socket"); + log.trace("enter HttpConnection.tunnelCreated()"); + + if (!isSecure() || !isProxied()) { + throw new IllegalStateException("Connection must be secure and proxied to use this feature"); + } + if (_usingSecureSocket) { + throw new IllegalStateException("Already using a secure socket"); + } if (sslSocketFactory == null) { sslSocketFactory = SSLSocketFactory.getDefault(); @@ -392,9 +399,9 @@ * @return a stream to write the request to */ public OutputStream getRequestOutputStream() throws IOException, IllegalStateException { + log.trace("enter HttpConnection.getRequestOutputStream()"); assertOpen(); - RequestOutputStream out = new RequestOutputStream(_output); - return out; + return new RequestOutputStream(_output); } /** @@ -407,10 +414,12 @@ * @throws IOException if an I/O problem occurs * @return a stream to write the request to */ - public OutputStream getRequestOutputStream(boolean useChunking) throws IOException, IllegalStateException { + public OutputStream getRequestOutputStream(boolean useChunking) + throws IOException, IllegalStateException { + log.trace("enter HttpConnection.getRequestOutputStream(boolean)"); + assertOpen(); - RequestOutputStream out = new RequestOutputStream(_output,useChunking); - return out; + return new RequestOutputStream(_output, useChunking); } /** @@ -429,6 +438,7 @@ */ public InputStream getResponseInputStream(HttpMethod method) throws IOException, IllegalStateException { + log.trace("enter HttpConnection.getRequestOutputStream(HttpMethod)"); assertOpen(); return new ResponseInputStream(_input,method); } @@ -442,27 +452,22 @@ * @throws IllegalStateException if I am not connected * @throws IOException if an I/O problem occurs */ - public void write(byte[] data) throws IOException, IllegalStateException, - HttpRecoverableException { - if(log.isDebugEnabled()){ - log.debug("HttpConnection.write(byte[])"); - } + public void write(byte[] data) + throws IOException, IllegalStateException, HttpRecoverableException { + log.trace("enter HttpConnection.write(byte[])"); + assertOpen(); if(wireLog.isInfoEnabled() && (data.length > 0)) { wireLog.info(">> \"" + new String(data) + "\""); } try { _output.write(data); - } catch(SocketException e){ - if(log.isDebugEnabled()) { - log.debug("HttpConnection: Socket exception while writing data",e); - } - throw new HttpRecoverableException(e.toString()); - } catch(IOException e) { - if(log.isDebugEnabled()) { - log.debug("HttpConnection: Exception while writing data",e); - } - throw e; + } catch(SocketException se){ + log.debug("HttpConnection: Socket exception while writing data", se); + throw new HttpRecoverableException(se.toString()); + } catch(IOException ioe) { + log.debug("HttpConnection: Exception while writing data", ioe); + throw ioe; } } @@ -477,6 +482,7 @@ * @param len the number of bytes to write. */ public void write(byte[] data, int off, int len) throws IOException { + log.trace("enter HttpConnection.write(byte[], int, int)"); _output.write(data, off, len); } @@ -485,16 +491,14 @@ * output stream. * * @param data the bytes to be written - * @throws HttpRecoverableException when socket exceptions occur writing - * data + * @throws HttpRecoverableException when socket exceptions occur writing data * @throws IllegalStateException if I am not connected * @throws IOException if an I/O problem occurs */ - public void writeLine(byte[] data) throws IOException, - IllegalStateException, HttpRecoverableException { - if(log.isDebugEnabled()){ - log.debug("HttpConnection.writeLine(byte[])"); - } + public void writeLine(byte[] data) + throws IOException, IllegalStateException, HttpRecoverableException { + log.trace("enter HttpConnection.writeLine(byte[])"); + assertOpen(); if(wireLog.isInfoEnabled() && (data.length > 0)) { wireLog.info(">> \"" + new String(data) + "\""); @@ -520,21 +524,19 @@ * @throws IllegalStateException if I am not connected * @throws IOException if an I/O problem occurs */ - public void writeLine() throws IOException, IllegalStateException, - HttpRecoverableException { - if(log.isDebugEnabled()){ - log.debug("HttpConnection.writeLine()"); - } + public void writeLine() + throws IOException, IllegalStateException, HttpRecoverableException { + log.trace("enter HttpConnection.writeLine()"); + wireLog.info(">> \\r\\n"); try{ _output.write(CRLF); - } catch(SocketException e){ - if(log.isDebugEnabled()) { - log.debug("HttpConnection: Socket exception while writing data",e); - } - throw new HttpRecoverableException(e.toString()); - } catch(IOException e){ - throw e; + } catch(SocketException se){ + log.warn("HttpConnection: Socket exception while writing data", se); + throw new HttpRecoverableException(se.toString()); + } catch(IOException ioe){ + log.warn("HttpConnection: IO exception while writing data", ioe); + throw ioe; } } @@ -547,8 +549,9 @@ * @throws IllegalStateException if I am not connected * @throws IOException if an I/O problem occurs */ - public void print(String data) throws IOException, IllegalStateException, - HttpRecoverableException { + public void print(String data) + throws IOException, IllegalStateException, HttpRecoverableException { + log.trace("enter HttpConnection.print(String)"); write(data.getBytes()); } @@ -562,8 +565,9 @@ * @throws IllegalStateException if I am not connected * @throws IOException if an I/O problem occurs */ - public void printLine(String data) throws IOException, - IllegalStateException, HttpRecoverableException { + public void printLine(String data) + throws IOException, IllegalStateException, HttpRecoverableException { + log.trace("enter HttpConnection.printLine(String)"); writeLine(data.getBytes()); } @@ -577,6 +581,7 @@ */ public void printLine() throws IOException, IllegalStateException, HttpRecoverableException { + log.trace("enter HttpConnection.printLine()"); writeLine(); } @@ -587,8 +592,10 @@ * @throws IOException if an I/O problem occurs * @return a line from the response */ - public String readLine() throws IOException, IllegalStateException { - log.debug("HttpConnection.readLine()"); + public String readLine() + throws IOException, IllegalStateException { + log.trace("enter HttpConnection.readLine()"); + assertOpen(); StringBuffer buf = new StringBuffer(); for(;;) { @@ -618,7 +625,8 @@ * Shutdown my {@link Socket}'s output, via {@link Socket#shutdownOutput}. */ public void shutdownOutput() { - log.debug("HttpConnection.shutdownOutput()"); + log.trace("enter HttpConnection.shutdownOutput()"); + try { // Socket.shutdownOutput is a JDK 1.3 // method. We'll use reflection in case @@ -628,7 +636,8 @@ ("shutdownOutput", paramsClasses); Object[] params = new Object[0]; shutdownOutput.invoke(_socket, params); - } catch (Exception e) { + } catch (Exception ex) { + log.debug("Unexpected Exception caught", ex); // Ignore, and hope everything goes right } // close output stream? @@ -638,7 +647,7 @@ * Close my socket and streams. */ public void close() { - log.debug("HttpConnection.close()"); + log.trace("enter HttpConnection.close()"); closeSocketAndStreams(); } @@ -649,24 +658,27 @@ * Close everything out. */ protected void closeSocketAndStreams() { - log.debug("HttpConnection.closeSocketAndStreams()"); + log.trace("enter HttpConnection.closeSockedAndStreams()"); try { _input.close(); - } catch(Exception e) { + } catch(Exception ex) { + log.debug("Exception caught when closing input", ex); // ignored } _input = null; try { _output.close(); - } catch(Exception e) { + } catch(Exception ex) { + log.debug("Exception caught when closing output", ex); // ignored } _output = null; try { _socket.close(); - } catch(Exception e) { + } catch(Exception ex) { + log.debug("Exception caught when closing socket", ex); // ignored } _socket = null; @@ -680,7 +692,8 @@ * * @throws IllegalStateException if connected */ - protected void assertNotOpen() throws IllegalStateException { + protected void assertNotOpen() + throws IllegalStateException { if(_open) { throw new IllegalStateException("Connection is open"); } @@ -691,7 +704,8 @@ * * @throws IllegalStateException if not connected */ - protected void assertOpen() throws IllegalStateException { + protected void assertOpen() + throws IllegalStateException { if(!_open) { throw new IllegalStateException("Connection is not open"); } @@ -699,10 +713,10 @@ // ------------------------------------------------------------- Attributes - /** org.apache.commons.httpclient.HttpConnection log. */ - static private final Log log = LogFactory.getLog(HttpConnection.class.getName()); - /** httpclient.wire log. */ - static private final Log wireLog = LogFactory.getLog("httpclient.wire"); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(HttpConnection.class); + /** Log for any wire messages. */ + private static final Log wireLog = LogFactory.getLog("httpclient.wire"); /** My host. */ private String _host = null; /** My port. */ Index: java/org/apache/commons/httpclient/HttpConnectionManager.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpConnectionManager.java,v retrieving revision 1.8 diff -u -u -r1.8 HttpConnectionManager.java --- java/org/apache/commons/httpclient/HttpConnectionManager.java 23 Jul 2002 14:38:31 -0000 1.8 +++ java/org/apache/commons/httpclient/HttpConnectionManager.java 28 Jul 2002 17:55:20 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -79,8 +79,8 @@ public class HttpConnectionManager { // -------------------------------------------------------- Class Variables - private static final Log log = LogFactory.getLog( - HttpConnectionManager.class); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(HttpConnectionManager.class); // ----------------------------------------------------- Instance Variables private HashMap mapHosts = new HashMap(); @@ -92,8 +92,7 @@ /** * No-args constructor */ - public HttpConnectionManager() - { + public HttpConnectionManager() { } /** @@ -101,8 +100,7 @@ * * @param proxyHost - the proxy host name */ - public void setProxyHost(String proxyHost) - { + public void setProxyHost(String proxyHost) { this.proxyHost = proxyHost; } @@ -111,8 +109,7 @@ * * @return the proxy host name */ - public String getProxyHost() - { + public String getProxyHost() { return proxyHost; } @@ -121,8 +118,7 @@ * * @param proxyPort - the proxy port number */ - public void setProxyPort(int proxyPort) - { + public void setProxyPort(int proxyPort) { this.proxyPort = proxyPort; } @@ -131,8 +127,7 @@ * * @return the proxy port number */ - public int getProxyPort() - { + public int getProxyPort() { return proxyPort; } @@ -142,8 +137,7 @@ * * @param maxConnections - number of connections allowed for each host:port */ - public void setMaxConnectionsPerHost(int maxConnections) - { + public void setMaxConnectionsPerHost(int maxConnections) { this.maxConnections = maxConnections; } @@ -152,8 +146,7 @@ * * @return The maximum number of connections allowed for a given host:port. */ - public int getMaxConnectionsPerHost() - { + public int getMaxConnectionsPerHost() { return maxConnections; } @@ -168,9 +161,8 @@ * @exception java.net.MalformedURLException * @exception org.apache.commons.HttpException - If no connection becomes availble before the timeout expires */ - public HttpConnection getConnection(String sURL) throws HttpException, - MalformedURLException - { + public HttpConnection getConnection(String sURL) + throws HttpException, MalformedURLException { return getConnection(sURL, 0); } @@ -186,6 +178,8 @@ * @return the port for the specified port and protocol. */ private static int getPort(String protocol, int port) { + log.trace("HttpConnectionManager.getPort(String, port)"); + // default to provided port int portForProtocol = port; if (portForProtocol == -1) { @@ -215,8 +209,9 @@ * availble before the timeout expires */ public HttpConnection getConnection(String sURL, long timeout) - throws HttpException, MalformedURLException - { + throws HttpException, MalformedURLException { + log.trace("enter HttpConnectionManager.getConnection(String, long)"); + // FIXME: This method is too big if (sURL == null) { throw new MalformedURLException("URL is null"); @@ -269,6 +264,8 @@ * @return a pool (list) of connections available for the given key */ private LinkedList getConnections(String hostAndPort) { + log.trace("enter HttpConnectionManager.getConnections(String)"); + // Look for a list of connections for the given host:port LinkedList listConnections = null; synchronized (mapHosts) { @@ -290,8 +287,10 @@ * @return the number of connections in use for the given key */ public Integer getConnectionsInUse(String hostAndPort) { + log.trace("enter HttpConnectionManager.getConnectionsInUse(String)"); // FIXME: Shouldn't this be synchronized on mapNumConnections? or // mapHosts? + Integer numConnections = (Integer)mapNumConnections.get(hostAndPort); if (numConnections == null) { log.error("HttpConnectionManager.getConnection: " @@ -308,6 +307,8 @@ */ private HttpConnection waitForConnection(LinkedList pool, long timeout) throws HttpException { + log.trace("enter HttpConnectionManager.waitForConnection(LinkedList, long)"); + // No connections available, so wait // Start the timeout thread TimeoutThread threadTimeout = new TimeoutThread(); @@ -340,8 +341,9 @@ * * @param conn - The HttpConnection to make available. */ - public void releaseConnection(HttpConnection conn) - { + public void releaseConnection(HttpConnection conn) { + log.trace("enter HttpConnectionManager.releaseConnection(HttpConnection)"); + String host = conn.getHost(); int port = conn.getPort(); String key = host + ":" + port; @@ -377,8 +379,8 @@ * an outside mechanism to interrupt the waiting thread after the specified * timeout interval. */ - private static class TimeoutThread extends Thread - { + private static class TimeoutThread extends Thread { + private long timeout = 0; private Thread thrdWakeup = null; @@ -402,8 +404,8 @@ return thrdWakeup; } - public void run() - { + public void run() { + log.trace("TimeoutThread.run()"); if(timeout == 0){ return; } @@ -415,6 +417,7 @@ sleep(timeout); thrdWakeup.interrupt(); }catch(InterruptedException e){ + log.debug("InterruptedException caught as expected"); // This is expected } } 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.5 diff -u -u -r1.5 HttpException.java --- java/org/apache/commons/httpclient/HttpException.java 5 Jan 2002 11:16:00 -0000 1.5 +++ java/org/apache/commons/httpclient/HttpException.java 28 Jul 2002 17:55:20 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/HttpMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethod.java,v retrieving revision 1.13 diff -u -u -r1.13 HttpMethod.java --- java/org/apache/commons/httpclient/HttpMethod.java 21 Jul 2002 04:12:45 -0000 1.13 +++ java/org/apache/commons/httpclient/HttpMethod.java 28 Jul 2002 17:55:21 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/HttpMethodBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v retrieving revision 1.37 diff -u -u -r1.37 HttpMethodBase.java --- java/org/apache/commons/httpclient/HttpMethodBase.java 28 Jul 2002 06:24:51 -0000 1.37 +++ java/org/apache/commons/httpclient/HttpMethodBase.java 28 Jul 2002 17:55:25 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -170,8 +170,7 @@ * NOTE: StrictMode is currently experimental and its functionlaity may change in the future. * */ - public void setStrictMode(boolean strictMode) - { + public void setStrictMode(boolean strictMode) { this.strictMode = strictMode; } @@ -182,8 +181,7 @@ * * @return true if strict mode is enabled. */ - public boolean isStrictMode() - { + public boolean isStrictMode() { return strictMode; } @@ -249,7 +247,7 @@ // semantics of the message, by appending each subsequent field-value // to the first, each separated by a comma." // - HTTP/1.0 (4.3) - log.debug("HttpMethodBase.addRequestHeader(Header)"); + log.trace("HttpMethodBase.addRequestHeader(Header)"); if (header == null){ log.debug("null header value ignored"); @@ -316,6 +314,8 @@ * to add as query string parameterss */ public void setQueryString(NameValuePair[] params) { + log.trace("enter HttpMethodBase.setQueryString(NameValuePair[])"); + StringBuffer buf = new StringBuffer(); boolean needAmp = false; for(int i=0;i-1 */ - public int execute(HttpState state, HttpConnection connection) throws HttpException, IOException { + public int execute(HttpState state, HttpConnection connection) + throws HttpException, IOException { // FIXME: This method is too large - if (log.isDebugEnabled()) { - log.debug("enter HttpMethodBase.execute(HttpState, HttpConnection)"); - } + log.trace("enter HttpMethodBase.execute(HttpState, HttpConnection)"); if (null == state) { throw new NullPointerException("HttpState parameter"); @@ -747,10 +746,10 @@ * @param state the client state * @param conn the {@link HttpConnection} to write the request to */ - protected void writeRequest(HttpState state, HttpConnection conn) throws IOException, HttpException { - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.writeRequest(HttpState,HttpConnection)"); - } + protected void writeRequest(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.writeRequest(HttpState, HttpConnection)"); + writeRequestLine(state,conn); writeRequestHeaders(state,conn); conn.writeLine(); // close head @@ -769,11 +768,12 @@ * @param state the client state * @param conn the {@link HttpConnection} to write to */ - protected void writeRequestLine(HttpState state, HttpConnection conn) throws IOException, HttpException { - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.writeRequestLine(HttpState,HttpConnection)"); - } - String requestLine = HttpMethodBase.generateRequestLine(conn, getName(),getPath(),getQueryString(),(http11 ? "HTTP/1.1" : "HTTP/1.0")); + protected void writeRequestLine(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection)"); + + String requestLine = HttpMethodBase.generateRequestLine(conn, getName(), getPath(), + getQueryString(),(http11 ? "HTTP/1.1" : "HTTP/1.0")); conn.print(requestLine); } @@ -793,10 +793,10 @@ * @param state the client state * @param conn the {@link HttpConnection} to write to */ - protected void writeRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)"); - } + protected void writeRequestHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.writeRequestHeaders(HttpState, HttpConnection)"); + addRequestHeaders(state,conn); Iterator it = requestHeaders.values().iterator(); while(it.hasNext()) { @@ -824,7 +824,10 @@ * @param state the client state * @param conn the {@link HttpConnection} the headers will eventually be written to */ - protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addRequestHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addRequestHeaders(HttpState, HttpConnection)"); + addUserAgentRequestHeader(state,conn); addHostRequestHeader(state,conn); addCookieRequestHeader(state,conn); @@ -838,7 +841,10 @@ * as long as no User-Agent request header * already exists. */ - protected void addUserAgentRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addUserAgentRequestHeader(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)"); + if (!requestHeaders.containsKey("user-agent")) { setRequestHeader(HttpMethodBase.USER_AGENT); } @@ -849,7 +855,10 @@ * as long as no Host request header * already exists. */ - protected void addHostRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addHostRequestHeader(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)"); + // Per 19.6.1.1 of RFC 2616, it is legal for HTTP/1.0 based // applications to send the Host request-header. // TODO: Add the ability to disable the sending of this header for HTTP/1.0 requests. @@ -873,8 +882,12 @@ /** * Adds a Cookie request containing the matching {@link Cookie}s. */ - protected void addCookieRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - Header cookieHeader = Cookie.createCookieHeader(conn.getHost(), conn.getPort(), getPath(), conn.isSecure(), new Date(), state.getCookies()); + protected void addCookieRequestHeader(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addCookieRequestHeaders(HttpState, HttpConnection)"); + + Header cookieHeader = Cookie.createCookieHeader(conn.getHost(), conn.getPort(), + getPath(), conn.isSecure(), new Date(), state.getCookies()); if(null != cookieHeader) { setRequestHeader(cookieHeader); } @@ -885,7 +898,10 @@ * as long as no Authorization request header * already exists. */ - protected void addAuthorizationRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addAuthorizationRequestHeader(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addAuthorizationRequestHeader(HttpState, HttpConnection)"); + // add authorization header, if needed if (!requestHeaders.containsKey(Authenticator.WWW_AUTH_RESP.toLowerCase())) { Header wwwAuthenticateHeader = (Header)(responseHeaders.get(Authenticator.WWW_AUTH.toLowerCase())); @@ -904,8 +920,11 @@ * as long as no Proxy-Authorization request header * already exists. */ - protected void addProxyAuthorizationRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - // add authorization header, if needed + protected void addProxyAuthorizationRequestHeader(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addProxyAuthorizationRequestHeader(HttpState, HttpConnection)"); + + // add proxy authorization header, if needed if (!requestHeaders.containsKey(Authenticator.PROXY_AUTH_RESP.toLowerCase())) { Header wwwAuthenticateHeader = (Header)(responseHeaders.get(Authenticator.PROXY_AUTH.toLowerCase())); if (null != wwwAuthenticateHeader) { @@ -924,7 +943,10 @@ * as long as no Content-Length request header * already exists. */ - protected void addContentLengthRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addContentLengthRequestHeader(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.addProxyAuthorizationRequestHeader(HttpState, HttpConnection)"); + // add content length or chunking int len = getRequestContentLength(); if (!requestHeaders.containsKey("content-length")) { @@ -969,7 +991,8 @@ * This implementation writes nothing and returns true. * @return true */ - protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected boolean writeRequestBody(HttpState state, HttpConnection conn) + throws IOException, HttpException { return true; } @@ -1010,10 +1033,10 @@ * @param state the client state * @param conn the {@link HttpConnection} to read the response from */ - protected void readResponse(HttpState state, HttpConnection conn) throws IOException, HttpException { - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.readResponse(HttpState,HttpConnection)"); - } + protected void readResponse(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.debug("enter HttpMethodBase.readResponse(HttpState, HttpConnection)"); + readStatusLine(state,conn); processStatusLine(state,conn); readResponseHeaders(state,conn); @@ -1036,10 +1059,10 @@ * @param state the client state * @param conn the {@link HttpConnection} to read the response from */ - protected void readStatusLine(HttpState state, HttpConnection conn) throws IOException, HttpException { - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.readStatusLine(HttpState,HttpConnection)"); - } + protected void readStatusLine(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.readStatusLine(HttpState, HttpConnection)"); + statusCode = -1; statusText = null; @@ -1116,16 +1139,15 @@ * @param state the client state * @param conn the {@link HttpConnection} to read the response from */ - protected void readResponseHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void readResponseHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { // "It must be possible to combine the multiple header fields into // one "field-name: field-value" pair, without changing the // semantics of the message, by appending each subsequent field-value // to the first, each separated by a comma." // - HTTP/1.0 (4.3) - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.readResponseHeaders(HttpState,HttpConnection)"); - } + log.trace("enter HttpMethodBase.readResponseHeaders(HttpState, HttpConnection)"); responseHeaders.clear(); String name = null; @@ -1206,6 +1228,8 @@ * @param conn the {@link HttpConnection} to read the response from */ protected void processResponseHeaders(HttpState state, HttpConnection conn) { + log.trace("enter HttpMethodBase.processResponseHeaders(HttpState, HttpConnection)"); + // add cookies, if any // should we set cookies? Header setCookieHeader = getResponseHeader("set-cookie2"); @@ -1217,8 +1241,8 @@ try { Cookie[] cookies = Cookie.parse(conn.getHost(), conn.getPort(), getPath(), conn.isSecure(), setCookieHeader); state.addCookies(cookies); - } catch (Exception e) { - log.error("processResponseHeaders(HttpState,HttpConnection)",e); + } catch (Exception ex) { + log.error("Exception caught when processing cookies", ex); } } } @@ -1241,7 +1265,10 @@ * @param state the client state * @param conn the {@link HttpConnection} to read the response from */ - protected void readResponseBody(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void readResponseBody(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)"); + ByteArrayOutputStream out = new ByteArrayOutputStream(); readResponseBody(state, conn, out); @@ -1267,10 +1294,9 @@ * @param conn the {@link HttpConnection} to read the response from * @param out OutputStream to write the response body to */ - protected void readResponseBody(HttpState state, HttpConnection conn, OutputStream out) throws IOException { - if (log.isDebugEnabled()) { - log.debug("HttpMethodBase.readResponseBody(HttpState,HttpConnection)"); - } + protected void readResponseBody(HttpState state, HttpConnection conn, OutputStream out) + throws IOException { + log.trace("enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)"); responseBody = null; int expectedLength = 0; @@ -1351,6 +1377,8 @@ * once this method has been called. */ public void recycle() { + log.trace("enter HttpMethodBase.recycle()"); + path = null; followRedirects = false; queryString = null; @@ -1409,6 +1437,8 @@ * the specified attributes. */ protected static String generateRequestLine(HttpConnection connection, String name, String reqPath, String qString, String protocol) { + log.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, String, String, String, String)"); + StringBuffer buf = new StringBuffer(); buf.append(null == reqPath ? "/" : URIUtil.encode(reqPath,URIUtil.pathSafe())); if (null != qString) { @@ -1450,8 +1480,9 @@ * @param status - the HTTP status code * @return true if the message may contain a body, false if it can not contain a message body */ - private static boolean canResponseHaveBody(int status) - { + private static boolean canResponseHaveBody(int status) { + log.trace("enter HttpMethodBase.canResponseHaveBody(int)"); + boolean result = true; if((status >= 100 && status <= 199) || // 1XX @@ -1471,6 +1502,8 @@ * */ private static boolean isIpAddress(String value) { + log.trace("enter HttpMethodBase.isIpAddress(String)"); + value = value.trim(); // prevent input values of 127.0.0.1. or .127.0.0.1, etc. @@ -1528,10 +1561,10 @@ // -------------------------------------------------------------- Constants - /** org.apache.commons.httpclient.HttpMethod log. */ - private static final Log log = LogFactory.getLog(HttpMethod.class.getName()); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(HttpMethod.class); - /** httpclient.wire log. */ + /** Log for any wire messages. */ private static final Log wireLog = LogFactory.getLog("httpclient.wire"); /** User-Agent: Jakarta HTTP Client/1.0 header. */ Index: java/org/apache/commons/httpclient/HttpMultiClient.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMultiClient.java,v retrieving revision 1.12 diff -u -u -r1.12 HttpMultiClient.java --- java/org/apache/commons/httpclient/HttpMultiClient.java 28 Jul 2002 06:23:06 -0000 1.12 +++ java/org/apache/commons/httpclient/HttpMultiClient.java 28 Jul 2002 17:55:26 -0000 @@ -84,7 +84,7 @@ // -------------------------------------------------------- Class Variables - /** logging output */ + /** Log object for this class. */ private static final Log log = LogFactory.getLog(HttpMultiClient.class); // ----------------------------------------------------- Instance Variables @@ -285,8 +285,9 @@ * @throws HttpException if a protocol exception occurs * */ - public int executeMethod(HttpUrlMethod method) throws IOException, - HttpException { + public int executeMethod(HttpUrlMethod method) + throws IOException, HttpException { + log.trace("enter executeMethod(HttpUrlMethod)"); if (null == method) { throw new NullPointerException("method parameter"); 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.1 diff -u -u -r1.1 HttpRecoverableException.java --- java/org/apache/commons/httpclient/HttpRecoverableException.java 22 Feb 2002 19:24:23 -0000 1.1 +++ java/org/apache/commons/httpclient/HttpRecoverableException.java 28 Jul 2002 17:55:26 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/HttpSharedState.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpSharedState.java,v retrieving revision 1.3 diff -u -u -r1.3 HttpSharedState.java --- java/org/apache/commons/httpclient/HttpSharedState.java 28 Jul 2002 11:42:05 -0000 1.3 +++ java/org/apache/commons/httpclient/HttpSharedState.java 28 Jul 2002 17:55:26 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/HttpState.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpState.java,v retrieving revision 1.8 diff -u -u -r1.8 HttpState.java --- java/org/apache/commons/httpclient/HttpState.java 21 Jul 2002 04:12:45 -0000 1.8 +++ java/org/apache/commons/httpclient/HttpState.java 28 Jul 2002 17:55:27 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -67,6 +67,9 @@ import java.util.HashMap; import java.util.Iterator; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** *

* A container for HTTP attributes that may persist from request @@ -97,6 +100,11 @@ */ private ArrayList cookies = new ArrayList(); + // -------------------------------------------------------- Class Variables + + /** Log object for this class. */ + public static final Log log = LogFactory.getLog(HttpState.class); + // ------------------------------------------------------------- Properties /** @@ -106,6 +114,8 @@ * @param cookie the {@link Cookie} to add */ public void addCookie(Cookie cookie) { + log.trace("enter HttpState.addCookie(Cookie)"); + if (cookie != null) { // first remove any old cookie that is equivalent for (Iterator it = cookies.iterator();it.hasNext(); ) { @@ -128,6 +138,8 @@ * @param newcookies the {@link Cookie}s to add */ public void addCookies(Cookie[] newcookies) { + log.trace("enter HttpState.addCookies(Cookie[])"); + if (newcookies != null) { for (int i = 0; i < newcookies.length; i++) { this.addCookie(newcookies[i]); @@ -140,6 +152,7 @@ * @return an array of my {@link Cookie}s. */ public Cookie[] getCookies() { + log.trace("enter HttpState.getCookies()"); return (Cookie[])(cookies.toArray(new Cookie[cookies.size()])); } @@ -155,6 +168,8 @@ * @see Cookie#matches */ public Cookie[] getCookies(String domain, int port, String path, boolean secure, Date now) { + log.trace("enter HttpState.getCookies(String, int, String, boolean, Date)"); + ArrayList list = new ArrayList(cookies.size()); for(int i=0,m=cookies.size();iConstants enumerating the HTTP status codes.

* @version $Id: HttpStatus.java,v 1.6 2002/03/04 03:24:50 marcsaeg Exp $ @@ -71,11 +74,14 @@ public class HttpStatus { - // -------------------------------------------------------------- Variables + // -------------------------------------------------------- Class Variables /** Reason phrases (as Strings), by status code (as Integer). */ private static Hashtable mapStatusCodes = new Hashtable(); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(HttpStatus.class); + // --------------------------------------------------------- Public Methods @@ -87,10 +93,11 @@ * @return the reason phrase associated with the given status code */ public static String getStatusText(int nHttpStatusCode) { - Integer intKey = new Integer(nHttpStatusCode); + log.trace("enter HttpStatus.getStatusText(int)"); + Integer intKey = new Integer(nHttpStatusCode); if (!mapStatusCodes.containsKey(intKey)) { - // No information + log.warn("No status text available for status code " + nHttpStatusCode); return null; } else { Index: java/org/apache/commons/httpclient/HttpUrlMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpUrlMethod.java,v retrieving revision 1.2 diff -u -u -r1.2 HttpUrlMethod.java --- java/org/apache/commons/httpclient/HttpUrlMethod.java 28 Mar 2002 03:53:13 -0000 1.2 +++ java/org/apache/commons/httpclient/HttpUrlMethod.java 28 Jul 2002 17:55:29 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/NameValuePair.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NameValuePair.java,v retrieving revision 1.7 diff -u -u -r1.7 NameValuePair.java --- java/org/apache/commons/httpclient/NameValuePair.java 5 Jan 2002 11:16:00 -0000 1.7 +++ java/org/apache/commons/httpclient/NameValuePair.java 28 Jul 2002 17:55:29 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/RequestOutputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/RequestOutputStream.java,v retrieving revision 1.10 diff -u -u -r1.10 RequestOutputStream.java --- java/org/apache/commons/httpclient/RequestOutputStream.java 21 Jul 2002 04:12:45 -0000 1.10 +++ java/org/apache/commons/httpclient/RequestOutputStream.java 28 Jul 2002 17:55:30 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -114,6 +114,10 @@ // ------------------------------------------------------- Static Variables + /** Log object for this class. */ + static private final Log log = LogFactory.getLog(RequestOutputStream.class); + + /** Log for any wire messages. */ static private final Log wireLog = LogFactory.getLog("httpclient.wire"); // ----------------------------------------------------- Instance Variables @@ -195,6 +199,8 @@ * @exception IOException if an input or output exception occurred */ public void print(String s) throws IOException { + log.trace("enter RequestOutputStream.print(String)"); + if (s == null) { s = "null"; } @@ -236,6 +242,8 @@ * @exception IOException if an input/output error occurs */ public void write(int b) throws IOException { + + //TODO: If using chunking, the chunks are one byte long! if (useChunking) { stream.write(one, 0, one.length); stream.write(crlf, 0, crlf.length); @@ -257,6 +265,8 @@ * Write the specified byte array. */ public void write(byte[] b, int off, int len) throws IOException { + log.trace("enter RequestOutputStream.write(byte[], int, int)"); + if (useChunking) { byte chunkHeader[] = (Integer.toHexString(len) + "\r\n").getBytes(); @@ -280,21 +290,23 @@ * any further output data to throw an IOException. */ public void close() throws IOException { + log.trace("enter RequestOutputStream.close()"); if (this.closed == false) { try { - if (useChunking) { - // Write the final chunk. - stream.write(zero, 0, zero.length); - stream.write(crlf, 0, crlf.length); - stream.write(endChunk, 0, endChunk.length); - if(wireLog.isInfoEnabled()) { - wireLog.info(">> byte 0 \\r\\n\\r\\n (final chunk)"); - } - } - super.close(); - } catch (java.io.IOException ex) { - throw ex; + if (useChunking) { + // Write the final chunk. + stream.write(zero, 0, zero.length); + stream.write(crlf, 0, crlf.length); + stream.write(endChunk, 0, endChunk.length); + if(wireLog.isInfoEnabled()) { + wireLog.info(">> byte 0 \\r\\n\\r\\n (final chunk)"); + } + } + super.close(); + } catch (IOException ioe) { + log.debug("Unexpected exception caught when closing output stream", ioe); + throw ioe; } finally { this.closed = true; } Index: java/org/apache/commons/httpclient/ResponseInputStream.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/ResponseInputStream.java,v retrieving revision 1.15 diff -u -u -r1.15 ResponseInputStream.java --- java/org/apache/commons/httpclient/ResponseInputStream.java 21 Jul 2002 04:12:45 -0000 1.15 +++ java/org/apache/commons/httpclient/ResponseInputStream.java 28 Jul 2002 17:55:31 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -65,6 +65,8 @@ import java.io.IOException; import java.io.InputStream; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; /** *

{@link InputStream} wrapper supporting the chunked transfer encoding.

* @@ -78,6 +80,15 @@ */ public class ResponseInputStream extends InputStream { + // -------------------------------------------------------- Class Variables + + /** Log object for this class. */ + public static final Log log = LogFactory.getLog(ResponseInputStream.class); + + /** Log for wire messages. */ + public static final Log wireLog = LogFactory.getLog("httpclient.wire"); + + // ----------------------------------------------------------- Constructors /** @@ -88,6 +99,8 @@ * */ public ResponseInputStream(InputStream stream, boolean chunked, int contentLength) { + log.trace("enter ResponseInputStream(InputStream, boolean, int)"); + if (null == stream) { throw new NullPointerException("InputStream parameter is null"); } @@ -107,6 +120,7 @@ */ public ResponseInputStream(InputStream stream, HttpMethod method) { super(); + log.trace("enter ResponseInputStream(InputStream, HttpMethod)"); if (null == stream) { throw new NullPointerException("InputStream parameter is null"); @@ -198,15 +212,16 @@ * If a content length has been set but not all of the bytes have yet been * consumed, the remaining bytes will be swallowed. */ - public void close() - throws IOException { -/* + public void close() throws IOException { + log.trace("enter ResponseInputStream.close()"); + /* // Xerces appears to doubly-close the input stream... if(closed) { throw new IOException("Stream is already closed"); } -*/ + */ + //TODO: This close code is not very robust if (!closed) { try { if (chunk) { @@ -248,7 +263,9 @@ * * @exception IOException if an input/output error occurs */ - public int read(byte b[], int off, int len) throws IOException { + public int read(byte b[], int off, int len) + throws IOException { + log.trace("enter ResponseInputStream.read(byte, int, int)"); int avail = length - pos; if ((avail == 0) && (!fillBuffer())) @@ -269,7 +286,6 @@ System.arraycopy(buffer, pos, b, off, toCopy); pos += toCopy; return toCopy; - } /** @@ -279,7 +295,8 @@ * @exception IOException if an input/output error occurs */ public int read() - throws IOException { + throws IOException { + log.trace("enter ResponseInputStream.read()"); if (pos == length) { if (!fillBuffer()) @@ -297,6 +314,7 @@ * Fill the chunk buffer. */ private boolean fillBuffer() throws IOException { + log.trace("enter ResponseInputStream.fillBuffer()"); // Has this stream been closed? if (closed) @@ -400,8 +418,10 @@ * @exception IOException if an input or output exception has occurred */ private String readLineFromStream() - throws IOException { + throws IOException { + log.trace("enter ResponseInputStream.ReadLineFromStream()"); + //TODO: Reformat this code StringBuffer sb = new StringBuffer(); while (true) { int ch = stream.read(); Index: java/org/apache/commons/httpclient/URIUtil.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URIUtil.java,v retrieving revision 1.8 diff -u -u -r1.8 URIUtil.java --- java/org/apache/commons/httpclient/URIUtil.java 22 Jul 2002 15:35:12 -0000 1.8 +++ java/org/apache/commons/httpclient/URIUtil.java 28 Jul 2002 17:55:33 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/UsernamePasswordCredentials.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/UsernamePasswordCredentials.java,v retrieving revision 1.4 diff -u -u -r1.4 UsernamePasswordCredentials.java --- java/org/apache/commons/httpclient/UsernamePasswordCredentials.java 5 Jan 2002 11:16:00 -0000 1.4 +++ java/org/apache/commons/httpclient/UsernamePasswordCredentials.java 28 Jul 2002 17:55:33 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/methods/DeleteMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/DeleteMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 DeleteMethod.java --- java/org/apache/commons/httpclient/methods/DeleteMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/DeleteMethod.java 28 Jul 2002 17:55:34 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/methods/GetMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java,v retrieving revision 1.12 diff -u -u -r1.12 GetMethod.java --- java/org/apache/commons/httpclient/methods/GetMethod.java 23 Jul 2002 14:38:31 -0000 1.12 +++ java/org/apache/commons/httpclient/methods/GetMethod.java 28 Jul 2002 17:55:34 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -91,10 +91,10 @@ // -------------------------------------------------------------- Constants - /** org.apache.commons.httpclient.methods.GetMethod log. */ - private static final Log log = LogFactory.getLog(GetMethod.class.getName()); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(GetMethod.class); - /** httpclient.wire log. */ + /** Log for any wire messages. */ private static final Log wireLog = LogFactory.getLog("httpclient.wire"); /** Temporary directory. */ @@ -117,6 +117,7 @@ */ public GetMethod(String path) { super(path); + log.trace("enter GetMethod(String)"); setFollowRedirects(true); } @@ -128,6 +129,7 @@ */ public GetMethod(String path, String tempDir) { super(path); + log.trace("enter GetMethod(String, String)"); setUseDisk(true); setTempDir(tempDir); setFollowRedirects(true); @@ -141,6 +143,7 @@ */ public GetMethod(String path, String tempDir, String tempFile) { super(path); + log.trace("enter GetMethod(String, String, String)"); setUseDisk(true); setTempDir(tempDir); setTempFile(tempFile); @@ -154,6 +157,7 @@ */ public GetMethod(String path, File fileData) { this(path); + log.trace("enter GetMethod(String, File)"); useDisk = true; this.fileData = fileData; setFollowRedirects(true); @@ -285,6 +289,8 @@ // override recycle to reset redirects default public void recycle() { + log.trace("enter GetMethod.recycle()"); + super.recycle(); this.memoryData = null; this.fileData = null; @@ -297,6 +303,8 @@ * Otherwise return null. */ public byte[] getResponseBody() { + log.trace("enter GetMethod.getResponseBody()"); + checkUsed(); if(useDisk) { try { @@ -327,6 +335,8 @@ * Otherwise return null. */ public String getResponseBodyAsString() { + log.trace("enter GetMethod.getResponseBodyAsString()"); + byte[] data = getResponseBody(); if(null == data) { return null; @@ -341,7 +351,10 @@ * as an {@link InputStream}. * Otherwise return null. */ - public InputStream getResponseBodyAsStream() throws IOException { + public InputStream getResponseBodyAsStream() + throws IOException { + log.trace("enter GetMethod.getResponseBodyAsStream()"); + checkUsed(); if (useDisk) { return new FileInputStream(fileData); @@ -361,8 +374,10 @@ * Overrides method in {@link HttpMethodBase} to * write data to the appropriate buffer. */ - protected void readResponseBody(HttpState state, HttpConnection conn) throws IOException { - log.debug("GetMethod.readResponseBody(HttpState,HttpConnection)"); + protected void readResponseBody(HttpState state, HttpConnection conn) + throws IOException { + log.trace("enter GetMethod.readResponseBody(HttpState, HttpConnection)"); + OutputStream out = null; if (useDisk) { if (fileData == null) { Index: java/org/apache/commons/httpclient/methods/HeadMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java,v retrieving revision 1.8 diff -u -u -r1.8 HeadMethod.java --- java/org/apache/commons/httpclient/methods/HeadMethod.java 21 Jul 2002 04:12:46 -0000 1.8 +++ java/org/apache/commons/httpclient/methods/HeadMethod.java 28 Jul 2002 17:55:35 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -66,6 +66,7 @@ import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpState; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -128,14 +129,15 @@ * presence of a Content-Length or * Transfer-Encoding header. */ - protected void readResponseBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.debug("HeadMethod.readResponseBody(HttpState,HttpConnection)"); + protected void readResponseBody(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter HeadMethod.readResponseBody(HttpState, HttpConnection)"); return; // despite the possible presence of a content-length header, HEAD returns no response body } - // -------------------------------------------------------------- Constants + // -------------------------------------------------------------- Class Variables - /** org.apache.commons.httpclient.methods.HeadMethod log. */ - private static final Log log = LogFactory.getLog(HeadMethod.class.getName()); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(HeadMethod.class); } Index: java/org/apache/commons/httpclient/methods/OptionsMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/OptionsMethod.java,v retrieving revision 1.6 diff -u -u -r1.6 OptionsMethod.java --- java/org/apache/commons/httpclient/methods/OptionsMethod.java 21 Jul 2002 04:12:46 -0000 1.6 +++ java/org/apache/commons/httpclient/methods/OptionsMethod.java 28 Jul 2002 17:55:35 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -67,6 +67,8 @@ import org.apache.commons.httpclient.HttpMethodBase; import org.apache.commons.httpclient.HttpState; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; import java.util.Enumeration; import java.util.StringTokenizer; import java.util.Vector; @@ -81,8 +83,10 @@ extends HttpMethodBase { - // -------------------------------------------------------------- Constants + // --------------------------------------------------------- Class Variables + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(OptionsMethod.class); // ----------------------------------------------------------- Constructors @@ -139,6 +143,8 @@ // ----------------------------------------------------- HttpMethod Methods protected void processResponseHeaders(HttpState state, HttpConnection conn) { + log.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)"); + Header allowHeader = getResponseHeader("allow"); if (allowHeader != null) { String allowHeaderValue = allowHeader.getValue(); Index: java/org/apache/commons/httpclient/methods/PostMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java,v retrieving revision 1.14 diff -u -u -r1.14 PostMethod.java --- java/org/apache/commons/httpclient/methods/PostMethod.java 24 Jul 2002 03:00:11 -0000 1.14 +++ java/org/apache/commons/httpclient/methods/PostMethod.java 28 Jul 2002 17:55:37 -0000 @@ -184,6 +184,7 @@ * to clear my request body. */ public void recycle() { + log.trace("enter PostMethod.recycle()"); super.recycle(); requestBody = null; requestContentLength = CONTENT_LENGTH_AUTO; @@ -199,6 +200,8 @@ * @deprecated use #removeParameter followed by #setParameter */ public void setParameter(String parameterName, String parameterValue) { + log.trace("enter PostMethod.setParameter(String, String)"); + if(null != requestBody) { throw new IllegalStateException("Request body already generated."); } @@ -224,6 +227,8 @@ * */ public void setRequestContentLength(int length) { + log.trace("enter PostMethod.setRequestContentLength(int)"); + if ((length == CONTENT_LENGTH_CHUNKED) && !isHttp11()) { throw new RuntimeException("Chunked transfer encoding not allowed for HTTP/1.0"); } @@ -239,6 +244,8 @@ * @throws IllegalArgumentException if either argument is null */ public void addParameter(String paramName, String paramValue) { + log.trace("enter PostMethod.addParameter(String, String)"); + if(null != requestBody) { throw new IllegalStateException("Request body already generated."); } @@ -260,6 +267,8 @@ * @since 2.0 */ public void addParameter(NameValuePair param) { + log.trace("enter PostMethod.addParameter(NameValuePair)"); + if(null != requestBody) { throw new IllegalStateException("Request body already generated."); } @@ -280,6 +289,8 @@ * @since 2.0 */ public void addParameters(NameValuePair[] parameters) { + log.trace("enter PostMethod.addParameters(NameValuePair[])"); + if(null != requestBody) { throw new IllegalStateException("Request body already generated."); } @@ -304,6 +315,8 @@ * @since 2.0 */ public NameValuePair getParameter(String paramName){ + log.trace("enter PostMethod.getParameter(String)"); + if (paramName == null){ return null; } @@ -331,6 +344,8 @@ * @since 2.0 */ public NameValuePair[] getParameters(){ + log.trace("enter PostMethod.getParameters()"); + int numPairs = parameters.size(); Object[] objectArr= parameters.toArray(); NameValuePair[] nvPairArr = new NameValuePair[numPairs]; @@ -351,6 +366,8 @@ * @throws IllegalStateException if my request body has already been generated. */ public boolean removeParameter(String paramName) { + log.trace("enter PostMethod.removeParameter(String)"); + if(null != requestBody) { throw new IllegalStateException("Request body already generated."); } @@ -380,6 +397,8 @@ * @throws IllegalStateException if my request body has already been generated. */ public boolean removeParameter(String paramName, String paramValue) { + log.trace("enter PostMethod.removeParameter(String, String)"); + if(null != requestBody) { throw new IllegalStateException("Request body already generated."); } @@ -408,6 +427,8 @@ * encoding. Use setRequestBody(InputStream) instead. */ public void setRequestBody(String body) { + log.trace("enter PostMethod.setRequestBody(String)"); + if(!parameters.isEmpty()) { throw new IllegalStateException("Request parameters have already been added."); } @@ -415,6 +436,8 @@ } public void setRequestBody(InputStream body) { + log.trace("enter PostMethod.getRequestBody(InputStream)"); + if(!parameters.isEmpty()) { throw new IllegalStateException("Request parameters have already been added."); } @@ -429,6 +452,8 @@ * @since 2.0 */ public InputStream getRequestBody() { + log.trace("enter PostMethod.getRequestBody()"); + if (requestBody != null) { return requestBody; } else if (!parameters.isEmpty()) { @@ -442,6 +467,8 @@ *@return the request body as a string */ public String getRequestBodyAsString() throws IOException{ + log.trace("enter PostMethod.getRequestBodyAsString()"); + StringBuffer buffer = new StringBuffer(); InputStream requestBody = getRequestBody(); int data = requestBody.read(); @@ -454,10 +481,12 @@ /** - * Override method of {@link org.apache.commons.httpclient.HttpMethodBase} to also add Content-Type header + * Override method of {@link org.apache.commons.httpclient.HttpMethodBase} to + * also add Content-Type header * when appropriate. */ - protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addRequestHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { super.addRequestHeaders(state,conn); if(!parameters.isEmpty()) { //there are some parameters, so set the contentType header setRequestHeader(CONTENT_TYPE); @@ -476,8 +505,10 @@ * * @return always returns true */ - protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.debug("PostMethod.writeRequestBody(HttpState,HttpConnection)"); + protected boolean writeRequestBody(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter PostMethod.writeRequestBody(HttpState, HttpConnection)"); + if(null == requestBody) { requestBody = generateRequestBody(parameters); } @@ -516,6 +547,8 @@ @return number of bytes in the request body */ protected int getRequestContentLength() { + log.trace("enter PostMethod.getRequestContentLength()"); + if(null == requestBody) { requestBody = generateRequestBody(parameters); bufferContent(); @@ -535,6 +568,8 @@ * If the method was called earlier it returns immediately. */ private void bufferContent() { + log.trace("enter PostMethod.bufferContent()"); + if (buffer != null) return; try { buffer = new ByteArrayOutputStream(); @@ -563,6 +598,8 @@ * @return urlencoded string */ static InputStream generateRequestBody(List params) { + log.trace("enter PostMethod.generateRequestBody(List)"); + Iterator it = params.iterator(); StringBuffer sb = new StringBuffer(); while(it.hasNext()) { @@ -588,8 +625,8 @@ // -------------------------------------------------------------- Constants - /** org.apache.commons.httpclient.methods.PostMethod log. */ - private static final Log log = LogFactory.getLog(PostMethod.class.getName()); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(PostMethod.class); /** The Content-Type header for www-form-urlcoded. */ static final Header CONTENT_TYPE = new Header ("Content-Type","application/x-www-form-urlencoded"); Index: java/org/apache/commons/httpclient/methods/PutMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java,v retrieving revision 1.11 diff -u -u -r1.11 PutMethod.java --- java/org/apache/commons/httpclient/methods/PutMethod.java 23 Jul 2002 14:38:31 -0000 1.11 +++ java/org/apache/commons/httpclient/methods/PutMethod.java 28 Jul 2002 17:55:38 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -85,8 +85,7 @@ * * @author Remy Maucherat */ -public class PutMethod - extends HttpMethodBase { +public class PutMethod extends HttpMethodBase { // ----------------------------------------------------------- Constructors @@ -179,7 +178,10 @@ * memory. To upload large entities, it is recommended to first buffer the * data into a temporary file, and then send that file. */ - public void setRequestBody(InputStream is) throws IOException { + public void setRequestBody(InputStream is) + throws IOException { + log.trace("enter PutMethod.setRequestBody(InputStream)"); + checkNotUsed(); byte[] buffer = new byte[4096]; ByteArrayOutputStream os = new ByteArrayOutputStream(); @@ -203,7 +205,10 @@ * not already been set, in addition to the "standard" * set of headers. */ - protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected void addRequestHeaders(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter PutMethod.addRequestHeaders(HttpState, HttpConnection)"); + super.addRequestHeaders(state,conn); // Send expectation header if(isHttp11() && null == getRequestHeader("expect")) { @@ -217,7 +222,10 @@ * the 100 Continue status has not be * read. */ - protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { + protected boolean writeRequestBody(HttpState state, HttpConnection conn) + throws IOException, HttpException { + log.trace("enter PutMethod.writeRequestBody(HttpState, HttpConnection)"); + if(null != getRequestHeader("expect") && getStatusCode() != HttpStatus.SC_CONTINUE) { return false; } @@ -253,6 +261,8 @@ * to return the appropriate content length. */ protected int getRequestContentLength() { + log.trace("enter PutMethod.getRequestContentLength()"); + if(null != data) { return data.length; } else if(null != file && file.exists()) { @@ -273,6 +283,6 @@ file = null; } - /** org.apache.commons.httpclient.methods.PutMethod log. */ - private static final Log log = LogFactory.getLog(PutMethod.class.getName()); + /** Log object for this class. */ + private static final Log log = LogFactory.getLog(PutMethod.class); } Index: java/org/apache/commons/httpclient/methods/UrlDeleteMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlDeleteMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 UrlDeleteMethod.java --- java/org/apache/commons/httpclient/methods/UrlDeleteMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/UrlDeleteMethod.java 28 Jul 2002 17:55:38 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -74,6 +74,7 @@ */ public class UrlDeleteMethod extends DeleteMethod implements HttpUrlMethod { + // ----------------------------------------------------- Instance Variables private String url; @@ -101,8 +102,7 @@ * * @param url - the URL for this request. */ - public void setUrl(String url) throws MalformedURLException - { + public void setUrl(String url) throws MalformedURLException { setPath(URIUtil.getPath(url)); this.url = url; String query = URIUtil.getQueryString(url); @@ -112,10 +112,9 @@ } /** - * + * Gets the Url. */ - public String getUrl() - { + public String getUrl() { return url; } Index: java/org/apache/commons/httpclient/methods/UrlGetMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlGetMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 UrlGetMethod.java --- java/org/apache/commons/httpclient/methods/UrlGetMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/UrlGetMethod.java 28 Jul 2002 17:55:38 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/methods/UrlHeadMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlHeadMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 UrlHeadMethod.java --- java/org/apache/commons/httpclient/methods/UrlHeadMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/UrlHeadMethod.java 28 Jul 2002 17:55:39 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/methods/UrlOptionsMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlOptionsMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 UrlOptionsMethod.java --- java/org/apache/commons/httpclient/methods/UrlOptionsMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/UrlOptionsMethod.java 28 Jul 2002 17:55:39 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/methods/UrlPostMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPostMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 UrlPostMethod.java --- java/org/apache/commons/httpclient/methods/UrlPostMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/UrlPostMethod.java 28 Jul 2002 17:55:39 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without Index: java/org/apache/commons/httpclient/methods/UrlPutMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/UrlPutMethod.java,v retrieving revision 1.5 diff -u -u -r1.5 UrlPutMethod.java --- java/org/apache/commons/httpclient/methods/UrlPutMethod.java 21 Jul 2002 04:12:46 -0000 1.5 +++ java/org/apache/commons/httpclient/methods/UrlPutMethod.java 28 Jul 2002 17:55:40 -0000 @@ -6,7 +6,7 @@ * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without