Index: httpclient/src/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.102 diff -u -r1.102 HttpMethodBase.java --- httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java 28 Jan 2003 04:40:21 -0000 1.102 +++ httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java 28 Jan 2003 20:28:47 -0000 @@ -161,20 +161,21 @@ * @author Eric Johnson * @author Michael Becke * @author Oleg Kalnichevski + * @author Mike Bowler */ public abstract class HttpMethodBase implements HttpMethod { // ------------------------------------------ Static variables/initializers /** Maximum number of redirects and authentications that will be followed */ - private static int maxForwards = 100; + private static final int MAX_FORWARDS = 100; // -------------------------------------------------------------- Constants /** Log object for this class. */ - private static final Log log = LogFactory.getLog(HttpMethod.class); + private static final Log LOG = LogFactory.getLog(HttpMethod.class); /** Log for any wire messages. */ - private static final Log wireLog = LogFactory.getLog("httpclient.wire"); + private static final Log WIRE_LOG = LogFactory.getLog("httpclient.wire"); /** The User-Agent header sent on every request. */ protected static final Header USER_AGENT; @@ -251,8 +252,10 @@ */ private int maxRetries = 3; + /** true if we are currently executing */ private boolean inExecute = false; + /** true if we are finished with the connection */ private boolean doneWithConnection = false; // ----------------------------------------------------------- Constructors @@ -271,12 +274,13 @@ * @throws IllegalArgumentException when URI is invalid * @throws IllegalStateException when protocol of the absolute URI is not recognised */ - public HttpMethodBase(String uri) { + public HttpMethodBase(String uri) + throws IllegalArgumentException, IllegalStateException { try { // create a URI and allow for null/empty uri values - if (uri == null || uri.equals( "" )) { + if (uri == null || uri.equals("")) { uri = "/"; } @@ -290,7 +294,7 @@ } // only set the host if specified by the URI - if ( parsedURI.isAbsoluteURI() ) { + if (parsedURI.isAbsoluteURI()) { hostConfiguration = new HostConfiguration(); hostConfiguration.setHost( parsedURI.getHost(), @@ -306,11 +310,11 @@ ? "/" : parsedURI.getPath() ); - setQueryString( parsedURI.getEscapedQuery() ); + setQueryString(parsedURI.getEscapedQuery()); - } catch ( URIException e ) { - throw new IllegalArgumentException( - "Invalid uri '" + uri + "': " + e.getMessage() + } catch (URIException e) { + throw new IllegalArgumentException("Invalid uri '" + + uri + "': " + e.getMessage() ); } } @@ -326,11 +330,14 @@ public abstract String getName(); /** + * Return the URI + * @return The URI + * @throws URIException If the URI cannot be created. * @see org.apache.commons.httpclient.HttpMethod#getURI() */ public URI getURI() throws URIException { - if ( hostConfiguration == null ) { + if (hostConfiguration == null) { // just use a relative URI, the host hasn't been set URI tmpUri = new URI(null, null, path, null, null); tmpUri.setEscapedQuery(queryString); @@ -339,7 +346,7 @@ // we only want to include the port if it's not the default int port = hostConfiguration.getPort(); - if ( port == hostConfiguration.getProtocol().getDefaultPort() ) { + if (port == hostConfiguration.getProtocol().getDefaultPort()) { port = -1; } @@ -441,10 +448,10 @@ * @param header the header to add to the request */ public void addRequestHeader(Header header) { - log.trace("HttpMethodBase.addRequestHeader(Header)"); + LOG.trace("HttpMethodBase.addRequestHeader(Header)"); if (header == null) { - log.debug("null header value ignored"); + LOG.debug("null header value ignored"); } else { addRequestHeader(header.getName(), header.getValue()); } @@ -452,9 +459,12 @@ /** * adds a response footer to the internal list + * @param footer The new footer to add. */ public void addResponseFooter(Header footer) { - if (responseFooters == null) responseFooters = new HashMap(); + if (responseFooters == null) { + responseFooters = new HashMap(); + } responseFooters.put(footer.getName().toLowerCase(), footer); } @@ -487,7 +497,7 @@ * parameterss */ public void setQueryString(NameValuePair[] params) { - log.trace("enter HttpMethodBase.setQueryString(NameValuePair[])"); + LOG.trace("enter HttpMethodBase.setQueryString(NameValuePair[])"); StringBuffer buf = new StringBuffer(); boolean needAmp = false; for (int i = 0; i < params.length; i++) { @@ -501,7 +511,7 @@ try { queryName = URIUtil.encodeWithinQuery(params[i].getName()); } catch (URIException urie) { - log.error("encoding error within query name", urie); + LOG.error("encoding error within query name", urie); queryName = params[i].getName(); } buf.append(queryName).append("="); @@ -511,7 +521,7 @@ queryValue = URIUtil.encodeWithinQuery(params[i].getValue()); } catch (URIException urie) { - log.error("encoding error within query value", urie); + LOG.error("encoding error within query value", urie); queryValue = params[i].getValue(); } buf.append(queryValue); @@ -631,8 +641,9 @@ } /** - * Return my response body, if any, as a byte array. - * Otherwise return null. + * Return my response body, if any, as a byte array. Otherwise return + * null. + * @return The response body as a byte array. */ public byte[] getResponseBody() { if (responseBody == null) { @@ -648,9 +659,9 @@ os.close(); responseBody = os.toByteArray(); setResponseStream(null); - log.debug("buffering response body"); - } catch(IOException e) { - log.error("getResponseBody failed", e); + LOG.debug("buffering response body"); + } catch (IOException e) { + LOG.error("getResponseBody failed", e); responseBody = null; } } @@ -671,7 +682,7 @@ } if (responseBody != null) { InputStream byteResponseStream = new ByteArrayInputStream(responseBody); - log.debug("re-creating response stream from byte array"); + LOG.debug("re-creating response stream from byte array"); return byteResponseStream; } return null; @@ -686,18 +697,16 @@ * @return my response body, if any, as a {@link String}. Otherwise return * null. */ - public String getResponseBodyAsString() - { - byte[] rawdata = null; + public String getResponseBodyAsString() { + byte[] rawdata = null; if (responseAvailable()) { rawdata = getResponseBody(); } if (rawdata != null) { - return HttpConstants.getContentString(rawdata, getResponseCharSet()); + return HttpConstants.getContentString(rawdata, getResponseCharSet()); + } else { + return null; } - else { - return null; - } } @@ -709,7 +718,7 @@ if (responseFooters == null) { return null; } - return (Header[])(responseFooters.values().toArray( + return (Header[]) (responseFooters.values().toArray( new Header[responseFooters.size()])); } @@ -726,11 +735,14 @@ if (responseFooters == null) { return null; } - return (footerName == null) ? null : - (Header)(responseFooters.get(footerName.toLowerCase())); + return (footerName == null) ? null + : (Header) (responseFooters.get(footerName.toLowerCase())); } - + /** + * Set the response stream. + * @param responseStream The new response stream. + */ protected void setResponseStream(InputStream responseStream) { this.responseStream = responseStream; } @@ -793,33 +805,46 @@ setRequestHeader(header); } + /** + * Return true if we should close the connection now. The connection will + * only be left open if we are using HTTP1.1 + * @return boolean true if we should close the connection. + */ protected boolean shouldCloseConnection() { if (!http11) { - if (getName().equals(ConnectMethod.NAME) && - (statusLine.getStatusCode() == HttpStatus.SC_OK)) { - log.debug("Will leave connection open for tunneling"); + if (getName().equals(ConnectMethod.NAME) + && (statusLine.getStatusCode() == HttpStatus.SC_OK)) { + LOG.debug("Will leave connection open for tunneling"); return false; } else { - log.debug("Should close connection since using HTTP/1.0, " + - "ConnectMethod and status is OK"); + LOG.debug("Should close connection since using HTTP/1.0, " + + "ConnectMethod and status is OK"); return true; } } else { Header connectionHeader = getResponseHeader("connection"); if (null != connectionHeader && "close".equalsIgnoreCase(connectionHeader.getValue())) { - log.debug("Should close connection since \"Connection: close\" header found."); + LOG.debug("Should close connection since \"Connection: close\" header found."); return true; } } return false; } - + + + /** + * Return true if a retry is needed. + * @param statusCode The status code + * @param state The state. + * @param conn The connection + * @return boolean true if a retry is needed. + */ private boolean isRetryNeeded(int statusCode, HttpState state, HttpConnection conn) { switch (statusCode) { case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED: - log.debug("Authorization required"); + LOG.debug("Authorization required"); if (doAuthentication) { //process authentication response //if the authentication is successful, return the statusCode //otherwise, drop through the switch and try again. @@ -834,9 +859,9 @@ case HttpStatus.SC_MOVED_TEMPORARILY: case HttpStatus.SC_MOVED_PERMANENTLY: case HttpStatus.SC_TEMPORARY_REDIRECT: - log.debug("Redirect required"); + LOG.debug("Redirect required"); - if (! processRedirectResponse(conn)) { + if (!processRedirectResponse(conn)) { return false; } break; @@ -849,6 +874,14 @@ return true; } + /** + * TODO: Determine what the intent of this method is. It appears to be + * checking validity of the method. + * + * @param state The state. + * @param conn The connection. + * @throws HttpException If the method isn't valid. + */ private void checkExecuteConditions(HttpState state, HttpConnection conn) throws HttpException { @@ -894,8 +927,10 @@ * @throws NullPointerException if the state is null */ public int execute(HttpState state, HttpConnection conn) - throws HttpException, IOException, NullPointerException { - log.trace("enter HttpMethodBase.execute(HttpState, HttpConnection)"); + throws HttpException, HttpRecoverableException, + IOException, NullPointerException { + + LOG.trace("enter HttpMethodBase.execute(HttpState, HttpConnection)"); checkExecuteConditions(state, conn); inExecute = true; @@ -914,13 +949,13 @@ proxyRealms = new HashSet(); int forwardCount = 0; //protect from an infinite loop - while (forwardCount++ < maxForwards) { + while (forwardCount++ < MAX_FORWARDS) { // on every retry, reset this state information. responseConnection = conn; conn.setLastResponseInputStream(null); - if (log.isDebugEnabled()) { - log.debug("Execute loop try " + forwardCount); + if (LOG.isDebugEnabled()) { + LOG.debug("Execute loop try " + forwardCount); } //write the request and read the response, will retry @@ -953,12 +988,12 @@ } //end of retry loop - if (forwardCount >= maxForwards) { - log.error("Narrowly avoided an infinite loop in execute"); - throw new HttpRecoverableException("Maximum redirects ("+ maxForwards +") exceeded"); + if (forwardCount >= MAX_FORWARDS) { + LOG.error("Narrowly avoided an infinite loop in execute"); + throw new HttpRecoverableException("Maximum redirects (" + + MAX_FORWARDS + ") exceeded"); } - } - finally { + } finally { inExecute = false; // If the response has been fully processed, return the connection // to the pool. Use this flag, rather than other tests (like @@ -973,10 +1008,15 @@ return statusLine.getStatusCode(); } + /** + * Process the redirect response. + * @param conn The connection to use. + * @return boolean true if the redirect was successful. + */ private boolean processRedirectResponse(HttpConnection conn) { if (!getFollowRedirects()) { - log.info("Redirect requested but followRedirects is " + LOG.info("Redirect requested but followRedirects is " + "disabled"); return false; } @@ -985,13 +1025,13 @@ Header locationHeader = getResponseHeader("location"); if (locationHeader == null) { // got a redirect response, but no location header - log.error("Received redirect response " + getStatusCode() + LOG.error("Received redirect response " + getStatusCode() + " but no location header"); return false; } String location = locationHeader.getValue(); - if (log.isDebugEnabled()) { - log.debug("Redirect requested to location '" + location + if (LOG.isDebugEnabled()) { + LOG.debug("Redirect requested to location '" + location + "'"); } @@ -1006,15 +1046,15 @@ redirectUrl = new URL(location); } catch (MalformedURLException e) { if (isStrictMode()) { - log.warn("Redirected location '" + location + - "' is not acceptable in strict mode"); + LOG.warn("Redirected location '" + location + + "' is not acceptable in strict mode"); return false; } else { //location is incomplete, use current values for defaults try { - log.debug("Redirect URL is not absolute - parsing as relative"); + LOG.debug("Redirect URL is not absolute - parsing as relative"); redirectUrl = new URL(currentUrl, location); } catch (MalformedURLException ex) { - log.warn("Redirected location '" + location + LOG.warn("Redirected location '" + location + "' is malformed"); return false; } @@ -1022,22 +1062,22 @@ } //check for redirect to a different protocol, host or port - try{ + try { checkValidRedirect(currentUrl, redirectUrl); } catch (HttpException ex) { //LOG the error and let the client handle the redirect - log.warn(ex.getMessage()); + LOG.warn(ex.getMessage()); return false; } //update the current location with the redirect location. //avoiding use of URL.getPath() and URL.getQuery() to keep //jdk1.2 comliance. - setPath( URIUtil.getPath( redirectUrl.toString() ) ); - setQueryString( URIUtil.getQuery( redirectUrl.toString() ) ); + setPath(URIUtil.getPath(redirectUrl.toString())); + setQueryString(URIUtil.getQuery(redirectUrl.toString())); - if (log.isDebugEnabled()) { - log.debug("Redirecting from '" + currentUrl.toExternalForm() + if (LOG.isDebugEnabled()) { + LOG.debug("Redirecting from '" + currentUrl.toExternalForm() + "' to '" + redirectUrl.toExternalForm()); } @@ -1057,18 +1097,18 @@ */ private static void checkValidRedirect(URL currentUrl, URL redirectUrl) throws HttpException { - log.trace("enter HttpMethodBase.checkValidRedirect(HttpConnection, URL)"); + LOG.trace("enter HttpMethodBase.checkValidRedirect(HttpConnection, URL)"); String oldProtocol = currentUrl.getProtocol(); String newProtocol = redirectUrl.getProtocol(); - if (! oldProtocol.equals(newProtocol)) { + if (!oldProtocol.equals(newProtocol)) { throw new HttpException("Redirect from protocol " + oldProtocol + " to " + newProtocol + " is not supported"); } String oldHost = currentUrl.getHost(); String newHost = redirectUrl.getHost(); - if (! oldHost.equalsIgnoreCase(newHost)) { + if (!oldHost.equalsIgnoreCase(newHost)) { throw new HttpException("Redirect from host " + oldHost + " to " + newHost + " is not supported"); } @@ -1100,10 +1140,9 @@ */ private static int getDefaultPort(String protocol) { String proto = protocol.toLowerCase().trim(); - if (proto.equals("http")){ + if (proto.equals("http")) { return 80; - } - else if (proto.equals("https")){ + } else if (proto.equals("https")) { return 443; } return -1; @@ -1124,7 +1163,7 @@ * variables will be reset once this method has been called. */ public void recycle() { - log.trace("enter HttpMethodBase.recycle()"); + LOG.trace("enter HttpMethodBase.recycle()"); releaseConnection(); @@ -1220,7 +1259,7 @@ protected void addAuthorizationRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.addAuthorizationRequestHeader(" + LOG.trace("enter HttpMethodBase.addAuthorizationRequestHeader(" + "HttpState, HttpConnection)"); // add authorization header, if needed @@ -1252,7 +1291,7 @@ protected void addContentLengthRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.addContentLengthRequestHeader(" + LOG.trace("enter HttpMethodBase.addContentLengthRequestHeader(" + "HttpState, HttpConnection)"); // add content length or chunking @@ -1277,19 +1316,15 @@ * @throws HttpException when a recoverable error occurs */ protected void addCookieRequestHeader(HttpState state, HttpConnection conn) - throws IOException, HttpException { - log.trace("enter HttpMethodBase.addCookieRequestHeader(HttpState, " + throws IOException, HttpException { + + LOG.trace("enter HttpMethodBase.addCookieRequestHeader(HttpState, " + "HttpConnection)"); CookieSpec matcher = CookiePolicy.getSpecByPolicy(state.getCookiePolicy()); - Cookie[] cookies = matcher.match( - conn.getHost(), - conn.getPort(), - getPath(), - conn.isSecure(), - state.getCookies()); - if ((cookies != null) && (cookies.length > 0)) - { + Cookie[] cookies = matcher.match(conn.getHost(), conn.getPort(), + getPath(), conn.isSecure(), state.getCookies()); + if ((cookies != null) && (cookies.length > 0)) { setRequestHeader(matcher.formatCookieHeader(cookies)); } } @@ -1307,7 +1342,7 @@ */ protected void addHostRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.addHostRequestHeader(HttpState, " + LOG.trace("enter HttpMethodBase.addHostRequestHeader(HttpState, " + "HttpConnection)"); // Per 19.6.1.1 of RFC 2616, it is legal for HTTP/1.0 based @@ -1318,7 +1353,7 @@ int port = conn.getPort(); if (getRequestHeader("host") != null) { - log.debug( + LOG.debug( "Request to add Host header ignored: header already added"); return; } @@ -1331,12 +1366,12 @@ // send blank, I interpret this as a small misstatement in the RFC, where // they meant to say "internet host". So IP numbers get sent as host // entries too. -- Eric Johnson 12/13/2002 - if (log.isDebugEnabled()) { - log.debug("Adding Host request header"); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding Host request header"); } //appends the port only if not using the default port for the protocol - if ( conn.getProtocol().getDefaultPort() != port ) { + if (conn.getProtocol().getDefaultPort() != port) { host += (":" + port); } @@ -1357,7 +1392,7 @@ protected void addProxyAuthorizationRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.addProxyAuthorizationRequestHeader(" + LOG.trace("enter HttpMethodBase.addProxyAuthorizationRequestHeader(" + "HttpState, HttpConnection)"); // add proxy authorization header, if needed @@ -1400,7 +1435,7 @@ */ protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.addRequestHeaders(HttpState, " + LOG.trace("enter HttpMethodBase.addRequestHeaders(HttpState, " + "HttpConnection)"); addUserAgentRequestHeader(state, conn); @@ -1424,7 +1459,7 @@ protected void addUserAgentRequestHeader(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, " + LOG.trace("enter HttpMethodBase.addUserAgentRequestHeaders(HttpState, " + "HttpConnection)"); if (getRequestHeader("user-agent") == null) { @@ -1470,7 +1505,7 @@ */ protected static String generateRequestLine(HttpConnection connection, String name, String requestPath, String query, String protocol) { - log.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, " + LOG.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, " + "String, String, String, String)"); StringBuffer buf = new StringBuffer(); @@ -1478,7 +1513,7 @@ try { path = (requestPath == null) ? "/" : URIUtil.encodePath(requestPath); } catch (URIException urie) { - log.error("URI path encoding error"); + LOG.error("URI path encoding error"); path = requestPath; } buf.append(path); @@ -1557,7 +1592,7 @@ */ protected void processResponseHeaders(HttpState state, HttpConnection conn) { - log.trace("enter HttpMethodBase.processResponseHeaders(HttpState, " + LOG.trace("enter HttpMethodBase.processResponseHeaders(HttpState, " + "HttpConnection)"); // add cookies, if any @@ -1567,7 +1602,9 @@ setCookieHeader = getResponseHeader("set-cookie"); } - if (setCookieHeader == null) return; + if (setCookieHeader == null) { + return; + } try { CookieSpec parser = CookiePolicy.getSpecByPolicy(state.getCookiePolicy()); @@ -1577,8 +1614,7 @@ getPath(), conn.isSecure(), setCookieHeader); - for (int i = 0; i < cookies.length; i++) - { + for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; parser.validate( conn.getHost(), @@ -1586,15 +1622,18 @@ getPath(), conn.isSecure(), cookie); - if (log.isDebugEnabled()) { - log.debug("Cookie accepted: \"" + parser.formatCookie(cookie) + "\""); + if (LOG.isDebugEnabled()) { + LOG.debug("Cookie accepted: \"" + + parser.formatCookie(cookie) + "\""); } state.addCookie(cookie); } } catch (HttpException e) { - if (log.isWarnEnabled()) { - log.warn("Cookie rejected: \"" + setCookieHeader.getValue() + "\". " + e.getMessage()); + if (LOG.isWarnEnabled()) { + LOG.warn("Cookie rejected: \"" + + setCookieHeader.getValue() + + "\". " + e.getMessage()); } } } @@ -1667,7 +1706,7 @@ */ protected void readResponse(HttpState state, HttpConnection conn) throws HttpException { - log.trace( + LOG.trace( "enter HttpMethodBase.readResponse(HttpState, HttpConnection)"); try { readStatusLine(state, conn); @@ -1676,7 +1715,7 @@ processResponseHeaders(state, conn); readResponseBody(state, conn); processResponseBody(state, conn); - } catch(IOException e) { + } catch (IOException e) { throw new HttpRecoverableException(e.toString()); } } @@ -1706,17 +1745,16 @@ */ protected void readResponseBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace( + LOG.trace( "enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)"); // assume we are not done with the connection if we get a stream doneWithConnection = false; - InputStream stream = _readResponseBody(conn); + InputStream stream = readResponseBody(conn); if (stream == null) { // done using the connection! responseBodyConsumed(); - } - else { + } else { conn.setLastResponseInputStream(stream); setResponseStream(stream); } @@ -1736,16 +1774,18 @@ * * @param conn the {@link HttpConnection} to read the response from * @return InputStream to read the response body from + * @throws IOException if an IO problem occurs. */ - private InputStream _readResponseBody(HttpConnection conn) - throws IOException { - log.trace("enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)"); + private InputStream readResponseBody(HttpConnection conn) + throws IOException { + + LOG.trace("enter HttpMethodBase.readResponseBody(HttpState, HttpConnection)"); responseBody = null; // is this desired? Header lengthHeader = getResponseHeader("Content-Length"); Header transferEncodingHeader = getResponseHeader("Transfer-Encoding"); InputStream is = conn.getResponseInputStream(); - if (wireLog.isDebugEnabled()) { + if (WIRE_LOG.isDebugEnabled()) { is = new WireLogInputStream(is); } InputStream result = null; @@ -1762,7 +1802,7 @@ HeaderElement[] lengthElements = lengthHeader.getValues(); String lengthValue = null; - if ( lengthElements.length > 1 ) { + if (lengthElements.length > 1) { // looks like the content length header was duplicated. if so // they won't be key=value pairs so we just want to get // the name not the value (which should be null) @@ -1777,7 +1817,7 @@ // FIXME: what if the content length is 0, perhaps we should // just return an empty stream in that case result = new ContentLengthInputStream(is, expectedLength); - } catch(NumberFormatException e) { + } catch (NumberFormatException e) { throw new HttpException( "Unable to parse server response content length: '" + lengthValue + "'" @@ -1785,8 +1825,8 @@ } - } else if(canResponseHaveBody(statusLine.getStatusCode()) - && !getName().equals(ConnectMethod.NAME)){ + } else if (canResponseHaveBody(statusLine.getStatusCode()) + && !getName().equals(ConnectMethod.NAME)) { result = is; } @@ -1794,7 +1834,7 @@ // close the underlying stream as soon as it is consumed, and notify // the watcher that the stream has been consumed. if (result != null) { - result = new AutoCloseInputStream(result, m_responseWatcher); + result = new AutoCloseInputStream(result, responseWatcher); } return result; @@ -1826,7 +1866,7 @@ */ protected void readResponseHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.readResponseHeaders(HttpState," + LOG.trace("enter HttpMethodBase.readResponseHeaders(HttpState," + "HttpConnection)"); responseHeaders.clear(); @@ -1904,7 +1944,7 @@ */ protected void readStatusLine(HttpState state, HttpConnection conn) throws IOException, HttpRecoverableException, HttpException { - log.trace( + LOG.trace( "enter HttpMethodBase.readStatusLine(HttpState, HttpConnection)"); //read out the HTTP status string @@ -1925,9 +1965,9 @@ //check for a valid HTTP-Version String httpVersion = statusLine.getHttpVersion(); - if (httpVersion.equals("HTTP/1.0")){ + if (httpVersion.equals("HTTP/1.0")) { http11 = false; - } else if (httpVersion.equals("HTTP/1.1")){ + } else if (httpVersion.equals("HTTP/1.1")) { http11 = true; } else { throw new HttpException("Unrecognized server protocol: '" @@ -1978,7 +2018,7 @@ */ protected void writeRequest(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace( + LOG.trace( "enter HttpMethodBase.writeRequest(HttpState, HttpConnection)"); writeRequestLine(state, conn); writeRequestHeaders(state, conn); @@ -2040,7 +2080,7 @@ */ protected void writeRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter HttpMethodBase.writeRequestHeaders(HttpState," + LOG.trace("enter HttpMethodBase.writeRequestHeaders(HttpState," + "HttpConnection)"); addRequestHeaders(state, conn); Iterator it = requestHeaders.values().iterator(); @@ -2066,7 +2106,7 @@ */ protected void writeRequestLine(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace( + LOG.trace( "enter HttpMethodBase.writeRequestLine(HttpState, HttpConnection)"); String requestLine = getRequestLine(conn); conn.print(requestLine); @@ -2076,6 +2116,9 @@ * Gets the request line that was sent to the http server. * Consider making this public. Consider creating a new class * RequestLine for this purpose. + * + * @param conn The http connection + * @return The request line. */ private String getRequestLine(HttpConnection conn) { return HttpMethodBase.generateRequestLine(conn, getName(), @@ -2101,7 +2144,7 @@ * @return boolean - true if value is valid, otherwise false */ private static boolean isIpAddress(String value) { - log.trace("enter HttpMethodBase.isIpAddress(String)"); + LOG.trace("enter HttpMethodBase.isIpAddress(String)"); value = value.trim(); @@ -2179,7 +2222,7 @@ * contain a message body */ private static boolean canResponseHaveBody(int status) { - log.trace("enter HttpMethodBase.canResponseHaveBody(int)"); + LOG.trace("enter HttpMethodBase.canResponseHaveBody(int)"); boolean result = true; @@ -2200,7 +2243,7 @@ * attempts are needed */ private boolean processAuthenticationResponse(HttpState state) { - log.trace("enter HttpMethodBase.processAuthenticationResponse(" + LOG.trace("enter HttpMethodBase.processAuthenticationResponse(" + "HttpState, HttpConnection)"); int statusCode = statusLine.getStatusCode(); @@ -2222,8 +2265,8 @@ if (null != wwwauth) { String pathAndCreds = getPath() + ":" + wwwauth.getValue(); if (realmsUsed.contains(pathAndCreds)) { - if (log.isInfoEnabled()) { - log.info("Already tried to authenticate to \"" + if (LOG.isInfoEnabled()) { + LOG.info("Already tried to authenticate to \"" + wwwauth.getValue() + "\" but still receiving " + statusCode + "."); } @@ -2246,21 +2289,21 @@ break; } } catch (HttpException httpe) { - log.warn(httpe.getMessage()); + LOG.warn(httpe.getMessage()); return true; // finished request } catch (UnsupportedOperationException uoe) { - log.warn(uoe.getMessage()); + LOG.warn(uoe.getMessage()); //FIXME: should this return true? } if (!authenticated) { // won't be able to authenticate to this challenge // without additional information - log.debug("HttpMethodBase.execute(): Server demands " + LOG.debug("HttpMethodBase.execute(): Server demands " + "authentication credentials, but none are " + "available, so aborting."); } else { - log.debug("HttpMethodBase.execute(): Server demanded " + LOG.debug("HttpMethodBase.execute(): Server demanded " + "authentication credentials, will try again."); // let's try it again, using the credentials } @@ -2292,36 +2335,36 @@ */ private void processRequest(HttpState state, HttpConnection connection) throws HttpException, IOException { - log.trace( + LOG.trace( "enter HttpMethodBase.processRequest(HttpState, HttpConnection)"); //try to do the write int retryCount = 0; do { retryCount++; - if (log.isTraceEnabled()) { - log.trace("Attempt number " + retryCount + " to write request"); + if (LOG.isTraceEnabled()) { + LOG.trace("Attempt number " + retryCount + " to write request"); } try { if (!connection.isOpen()) { - log.debug("Opening the connection."); + LOG.debug("Opening the connection."); connection.open(); } writeRequest(state, connection); used = true; //write worked, mark this method as used break; //move onto the write } catch (HttpRecoverableException httpre) { - if (log.isDebugEnabled()) { - log.debug("Closing the connection."); + if (LOG.isDebugEnabled()) { + LOG.debug("Closing the connection."); } // update the recoverable exception count. recoverableExceptionCount++; connection.close(); - log.info("Recoverable exception caught when writing request"); + LOG.info("Recoverable exception caught when writing request"); if (retryCount == maxRetries) { - log.warn( + LOG.warn( "Attempt to write request has reached max retries: " + maxRetries); throw httpre; @@ -2333,9 +2376,9 @@ try { readResponse(state, connection); } catch (HttpRecoverableException httpre) { - log.warn("Recoverable exception caught when reading response"); - if (log.isDebugEnabled()) { - log.debug("Closing the connection."); + LOG.warn("Recoverable exception caught when reading response"); + if (LOG.isDebugEnabled()) { + LOG.debug("Closing the connection."); } connection.close(); @@ -2359,13 +2402,13 @@ private void writeRemainingRequestBody(HttpState state, HttpConnection connection) throws HttpException, IOException { - log.trace("enter writeRemainingRequestBody(HttpState, HttpConnection)"); + LOG.trace("enter writeRemainingRequestBody(HttpState, HttpConnection)"); if (HttpStatus.SC_CONTINUE == statusLine.getStatusCode()) { if (!bodySent) { bodySent = writeRequestBody(state, connection); } else { - log.warn("Received status CONTINUE but the body has already " + LOG.warn("Received status CONTINUE but the body has already " + "been sent"); // According to RFC 2616 this respose should be ignored } @@ -2374,11 +2417,15 @@ } - protected static String getContentCharSet(Header contentheader) - { - log.trace("enter getContentCharSet( Header contentheader )"); + /** + * Return the character set from the header. + * @param contentheader The content header. + * @return String The character set. + */ + protected static String getContentCharSet(Header contentheader) { + LOG.trace("enter getContentCharSet( Header contentheader )"); String charset = null; - if (contentheader != null){ + if (contentheader != null) { try { HeaderElement values[] = contentheader.getValues(); // I expect only one header element to be there @@ -2386,18 +2433,18 @@ if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { - // If I get anything "funny" UnsupportedEncondingException will result + // If I get anything "funny" + // UnsupportedEncondingException will result charset = param.getValue(); } } - } - catch(HttpException e){ - log.error(e); + } catch (HttpException e) { + LOG.error(e); } } if (charset == null) { - if (log.isDebugEnabled()) { - log.debug("Default charset used: " + HttpConstants.DEFAULT_CONTENT_CHARSET); + if (LOG.isDebugEnabled()) { + LOG.debug("Default charset used: " + HttpConstants.DEFAULT_CONTENT_CHARSET); } charset = HttpConstants.DEFAULT_CONTENT_CHARSET; } @@ -2405,11 +2452,21 @@ } + /** + * Return the character set for the request. This is determined from the + * "Content-Type" header. + * @return String The character set. + */ public String getRequestCharSet() { return getContentCharSet(getRequestHeader("Content-Type")); } + /** + * Return the character set for the response. This is determined from the + * "Content-Type" header. + * @return String The character set. + */ public String getResponseCharSet() { return getContentCharSet(getResponseHeader("Content-Type")); } @@ -2454,7 +2511,7 @@ * Insure that the connection is released back to the pool. */ private void ensureConnectionRelease() { - if ( responseConnection != null ) { + if (responseConnection != null) { responseConnection.releaseConnection(); responseConnection = null; } @@ -2464,7 +2521,7 @@ * This exists so that the public interface to this class need not include * either the responseConsumed or the responseBodyConsumed methods. */ - private ResponseConsumedWatcher m_responseWatcher = new ResponseConsumedWatcher() { + private ResponseConsumedWatcher responseWatcher = new ResponseConsumedWatcher() { public void responseConsumed() { responseBodyConsumed(); } Index: httpclient/src/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.6 diff -u -r1.6 HttpRecoverableException.java --- httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java 28 Jan 2003 04:40:21 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/HttpRecoverableException.java 28 Jan 2003 20:28:46 -0000 @@ -69,6 +69,7 @@ * exception may have been caused by a transient error and the request * may be retried. *

+ * @author Unascribed * @version $Revision: 1.6 $ $Date: 2003/01/28 04:40:21 $ */ public class HttpRecoverableException extends HttpException { Index: httpclient/src/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.16 diff -u -r1.16 HttpState.java --- httpclient/src/java/org/apache/commons/httpclient/HttpState.java 28 Jan 2003 04:40:21 -0000 1.16 +++ httpclient/src/java/org/apache/commons/httpclient/HttpState.java 28 Jan 2003 20:28:46 -0000 @@ -87,6 +87,7 @@ * @author Sean C. Sullivan * @author Michael Becke * @author Oleg Kalnichevski + * @author Mike Bowler * * @version $Revision: 1.16 $ $Date: 2003/01/28 04:40:21 $ * @@ -110,16 +111,17 @@ */ private ArrayList cookies = new ArrayList(); /** - * My cookie policy. + * My cookie policy. Default is {@link CookiePolicy.RFC2109} */ private int cookiePolicy = CookiePolicy.RFC2109; + /** The current connection manager */ private HttpConnectionManager httpConnectionManager; // -------------------------------------------------------- Class Variables /** Log object for this class. */ - private static final Log log = LogFactory.getLog(HttpState.class); + private static final Log LOG = LogFactory.getLog(HttpState.class); /** * Constructor for HttpState. @@ -146,18 +148,18 @@ * */ public synchronized void addCookie(Cookie cookie) { - log.trace("enter HttpState.addCookie(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(); ) { + for (Iterator it = cookies.iterator(); it.hasNext();) { Cookie tmp = (Cookie) it.next(); - if(cookie.equals(tmp)) { + if (cookie.equals(tmp)) { it.remove(); break; } } - if(!cookie.isExpired()) { + if (!cookie.isExpired()) { cookies.add(cookie); } } @@ -175,7 +177,7 @@ * */ public synchronized void addCookies(Cookie[] newcookies) { - log.trace("enter HttpState.addCookies(Cookie[])"); + LOG.trace("enter HttpState.addCookies(Cookie[])"); if (newcookies != null) { for (int i = 0; i < newcookies.length; i++) { @@ -193,8 +195,8 @@ * */ public synchronized Cookie[] getCookies() { - log.trace("enter HttpState.getCookies()"); - return (Cookie[])(cookies.toArray(new Cookie[cookies.size()])); + LOG.trace("enter HttpState.getCookies()"); + return (Cookie[]) (cookies.toArray(new Cookie[cookies.size()])); } /** @@ -244,17 +246,17 @@ String path, boolean secure ) { - log.trace("enter HttpState.getCookies(String, int, String, boolean)"); + LOG.trace("enter HttpState.getCookies(String, int, String, boolean)"); - CookieSpec matcher = CookiePolicy.getDefaultSpec(); + CookieSpec matcher = CookiePolicy.getDefaultSpec(); ArrayList list = new ArrayList(cookies.size()); - for(int i=0,m=cookies.size();idate. + * Remove all of my {@link Cookie}s that have expired by the specified + * date. * + * @param date The date to compare against. + * @return true if any cookies were purged. * @see Cookie#isExpired(java.util.Date) * @see #purgeExpiredCookies() - * */ public synchronized boolean purgeExpiredCookies(Date date) { - log.trace("enter HttpState.purgeExpiredCookies(Date)"); + LOG.trace("enter HttpState.purgeExpiredCookies(Date)"); boolean removed = false; Iterator it = cookies.iterator(); - while(it.hasNext()) { - if( ((Cookie)(it.next())).isExpired(date) ) { + while (it.hasNext()) { + if (((Cookie) (it.next())).isExpired(date)) { it.remove(); removed = true; } @@ -293,21 +296,23 @@ /** - * @return cookie policy (COMPATIBILITY | NETSCAPE_DRAFT | RFC2109) + * Return the current {@link CookiePolicy} + * @return The cookie policy. */ - public int getCookiePolicy() - { + public int getCookiePolicy() { return this.cookiePolicy; } /** - * @param new cookie policy (COMPATIBILITY | NETSCAPE_DRAFT | RFC2109) + * Set the {@link CookiePolicy} to one of {@link + * CookiePolicy#COMPATIBILITY}, {@link CookiePolicy#NETSCAPE_DRAFT} or + * {@link CookiePolicy#RFC2109} + * @param policy new cookie policy */ - public void setCookiePolicy(int policy) - { + public void setCookiePolicy(int policy) { this.cookiePolicy = policy; } @@ -331,8 +336,8 @@ * */ public synchronized void setCredentials(String realm, Credentials credentials) { - log.trace("enter HttpState.setCredentials(String, Credentials)"); - credMap.put(realm,credentials); + LOG.trace("enter HttpState.setCredentials(String, Credentials)"); + credMap.put(realm, credentials); } @@ -350,7 +355,7 @@ * */ public synchronized Credentials getCredentials(String realm) { - log.trace("enter HttpState.getCredentials(String)"); + LOG.trace("enter HttpState.getCredentials(String)"); Credentials creds = (Credentials) credMap.get(realm); if (creds == null) { @@ -380,7 +385,7 @@ * */ public synchronized void setProxyCredentials(String realm, Credentials credentials) { - log.trace("enter HttpState.setProxyCredentials(String, credentials)"); + LOG.trace("enter HttpState.setProxyCredentials(String, credentials)"); proxyCred.put(realm, credentials); } @@ -397,7 +402,7 @@ * @see #setProxyCredentials */ public synchronized Credentials getProxyCredentials(String realm) { - log.trace("enter HttpState.getProxyCredentials(String)"); + LOG.trace("enter HttpState.getProxyCredentials(String)"); Credentials creds = (Credentials) proxyCred.get(realm); if (creds == null) { creds = (Credentials) proxyCred.get(null); @@ -405,75 +410,85 @@ return creds; } - public synchronized String toString() - { - StringBuffer sbResult = new StringBuffer(); - - sbResult.append("["); - sbResult.append(getProxyCredentialsStringRepresentation(proxyCred)); - sbResult.append(" | "); - sbResult.append(getCredentialsStringRepresentation(proxyCred)); - sbResult.append(" | "); - sbResult.append(getCookiesStringRepresentation(cookies)); - sbResult.append("]"); - - String strResult = sbResult.toString(); + /** + * Return a string representation of this object. + * @return The string representation. + * @see java.lang.Object#toString() + */ + public synchronized String toString() { + StringBuffer sbResult = new StringBuffer(); + + sbResult.append("["); + sbResult.append(getProxyCredentialsStringRepresentation(proxyCred)); + sbResult.append(" | "); + sbResult.append(getCredentialsStringRepresentation(proxyCred)); + sbResult.append(" | "); + sbResult.append(getCookiesStringRepresentation(cookies)); + sbResult.append("]"); + + String strResult = sbResult.toString(); - return strResult; + return strResult; } - private static StringBuffer getProxyCredentialsStringRepresentation(final Map proxyCredMap) - { - StringBuffer sbResult = new StringBuffer(); - Iterator iter = proxyCredMap.keySet().iterator(); - while (iter.hasNext()) - { - String key = (String) iter.next(); - Credentials cred = (Credentials) proxyCredMap.get(key); - if (sbResult.length() > 0) - { - sbResult.append(", "); - } - sbResult.append(key); - sbResult.append("#"); - sbResult.append(cred.toString()); - } - return sbResult; - } - - private static StringBuffer getCredentialsStringRepresentation(final Map credMap) - { - StringBuffer sbResult = new StringBuffer(); - Iterator iter = credMap.keySet().iterator(); - while (iter.hasNext()) - { - String key = (String) iter.next(); - Credentials cred = (Credentials) credMap.get(key); - if (sbResult.length() > 0) - { - sbResult.append(", "); - } - sbResult.append(key); - sbResult.append("#"); - sbResult.append(cred.toString()); - } - return sbResult; + /** + * Return a string representation of the proxy credentials + * @param proxyCredMap The proxy credentials + * @return StringBuffer The string representation. + */ + private static StringBuffer getProxyCredentialsStringRepresentation(final Map proxyCredMap) { + StringBuffer sbResult = new StringBuffer(); + Iterator iter = proxyCredMap.keySet().iterator(); + while (iter.hasNext()) { + String key = (String) iter.next(); + Credentials cred = (Credentials) proxyCredMap.get(key); + if (sbResult.length() > 0) { + sbResult.append(", "); + } + sbResult.append(key); + sbResult.append("#"); + sbResult.append(cred.toString()); + } + return sbResult; } - private static StringBuffer getCookiesStringRepresentation(final List cookies) - { - StringBuffer sbResult = new StringBuffer(); - Iterator iter = cookies.iterator(); - while (iter.hasNext()) - { - Cookie ck = (Cookie) iter.next(); - if (sbResult.length() > 0) - { - sbResult.append("#"); - } - sbResult.append(ck.toExternalForm()); - } - return sbResult; + /** + * Return a string representation of the credentials. + * @param credMap The credentials. + * @return StringBuffer The string representation. + */ + private static StringBuffer getCredentialsStringRepresentation(final Map credMap) { + StringBuffer sbResult = new StringBuffer(); + Iterator iter = credMap.keySet().iterator(); + while (iter.hasNext()) { + String key = (String) iter.next(); + Credentials cred = (Credentials) credMap.get(key); + if (sbResult.length() > 0) { + sbResult.append(", "); + } + sbResult.append(key); + sbResult.append("#"); + sbResult.append(cred.toString()); + } + return sbResult; + } + + /** + * Return a string representation of the cookies. + * @param cookies The cookies + * @return StringBuffer The string representation. + */ + private static StringBuffer getCookiesStringRepresentation(final List cookies) { + StringBuffer sbResult = new StringBuffer(); + Iterator iter = cookies.iterator(); + while (iter.hasNext()) { + Cookie ck = (Cookie) iter.next(); + if (sbResult.length() > 0) { + sbResult.append("#"); + } + sbResult.append(ck.toExternalForm()); + } + return sbResult; } /** Index: httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java,v retrieving revision 1.11 diff -u -r1.11 HttpStatus.java --- httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java 28 Jan 2003 04:40:21 -0000 1.11 +++ httpclient/src/java/org/apache/commons/httpclient/HttpStatus.java 28 Jan 2003 20:28:49 -0000 @@ -72,9 +72,10 @@ *

Constants enumerating the HTTP status codes.

* * @see StatusLine + * @author Unascribed + * @author Mike Bowler * * @version $Id: HttpStatus.java,v 1.11 2003/01/28 04:40:21 jsdever Exp $ - * */ public class HttpStatus { @@ -82,10 +83,10 @@ // -------------------------------------------------------- Class Variables /** Reason phrases (as Strings), by status code (as Integer). */ - private static Hashtable mapStatusCodes = new Hashtable(); + private static final Hashtable MAP_STATUS_CODES = new Hashtable(); /** Log object for this class. */ - private static final Log log = LogFactory.getLog(HttpStatus.class); + private static final Log LOG = LogFactory.getLog(HttpStatus.class); // --------------------------------------------------------- Public Methods @@ -98,15 +99,14 @@ * @return the reason phrase associated with the given status code */ public static String getStatusText(int nHttpStatusCode) { - log.trace("enter HttpStatus.getStatusText(int)"); + LOG.trace("enter HttpStatus.getStatusText(int)"); Integer intKey = new Integer(nHttpStatusCode); - if (!mapStatusCodes.containsKey(intKey)) { - log.warn("No status text available for status code " + nHttpStatusCode); + if (!MAP_STATUS_CODES.containsKey(intKey)) { + LOG.warn("No status text available for status code " + nHttpStatusCode); return null; - } else { - return (String) mapStatusCodes.get(intKey); + return (String) MAP_STATUS_CODES.get(intKey); } } @@ -114,11 +114,12 @@ // -------------------------------------------------------- Private Methods /** - * Store the given reason phrase (as String), - * by status code (as Integer). + * Store the given reason phrase (as String), by status code (as Integer). + * @param nKey The status code + * @param strVal The reason phrase */ private static void addStatusCodeMap(int nKey, String strVal) { - mapStatusCodes.put(new Integer(nKey), strVal); + MAP_STATUS_CODES.put(new Integer(nKey), strVal); } @@ -149,7 +150,10 @@ public static final int SC_RESET_CONTENT = 205; /** 206 Partial Content (HTTP/1.1 - RFC 2616) */ public static final int SC_PARTIAL_CONTENT = 206; - /** 207 Multi-Status (WebDAV - RFC 2518) or 207 Partial Update OK (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) */ + /** + * 207 Multi-Status (WebDAV - RFC 2518) or 207 Partial Update + * OK (HTTP/1.1 - draft-ietf-http-v11-spec-rev-01?) + */ public static final int SC_MULTI_STATUS = 207; // --- 3xx Redirection --- @@ -292,9 +296,9 @@ addStatusCodeMap(SC_PAYMENT_REQUIRED, "Payment Required"); addStatusCodeMap(SC_NOT_ACCEPTABLE, "Not Acceptable"); addStatusCodeMap(SC_PROXY_AUTHENTICATION_REQUIRED, - "Proxy Authentication Required"); + "Proxy Authentication Required"); addStatusCodeMap(SC_REQUEST_TIMEOUT, - "Request Timeout"); + "Request Timeout"); addStatusCodeMap(SC_SWITCHING_PROTOCOLS, "Switching Protocols"); addStatusCodeMap(SC_NON_AUTHORITATIVE_INFORMATION, Index: httpclient/src/java/org/apache/commons/httpclient/HttpURL.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpURL.java,v retrieving revision 1.8 diff -u -r1.8 HttpURL.java --- httpclient/src/java/org/apache/commons/httpclient/HttpURL.java 28 Jan 2003 04:40:21 -0000 1.8 +++ httpclient/src/java/org/apache/commons/httpclient/HttpURL.java 28 Jan 2003 20:28:46 -0000 @@ -67,11 +67,13 @@ * The HTTP URL. * * @author Sung-Gu + * @author Mike Bowler */ public class HttpURL extends URI { // ----------------------------------------------------------- Constructors + /** Create an instance. */ protected HttpURL() { } @@ -79,10 +81,10 @@ * Construct a HTTP URL as an escaped form of a character array. * * @param escaped the HTTP URL character sequence - * @exception URIException + * @exception URIException If {@link #checkValid()} fails * @throws NullPointerException if escaped is null */ - public HttpURL(char[] escaped) throws URIException { + public HttpURL(char[] escaped) throws URIException, NullPointerException { parseUriReference(new String(escaped), true); checkValid(); } @@ -92,7 +94,7 @@ * Construct a HTTP URL from a given string. * * @param original the HTTP URL string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String original) throws URIException { parseUriReference(original, false); @@ -105,7 +107,7 @@ * * @param host the host string * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String host, String path) throws URIException { this(null, host, -1, path, null, null); @@ -119,7 +121,7 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String host, int port, String path) throws URIException { this(null, host, port, path, null, null); @@ -134,7 +136,7 @@ * @param port the port number * @param path the path string * @param query the query string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String host, int port, String path, String query) throws URIException { @@ -150,13 +152,13 @@ * @param user the user name * @param password his or her password * @param host the host string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String user, String password, String host) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, -1, null, null, null); checkValid(); } @@ -169,13 +171,13 @@ * @param password his or her password * @param host the host string * @param port the port number - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String user, String password, String host, int port) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, port, null, null, null); checkValid(); } @@ -189,13 +191,13 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String user, String password, String host, int port, String path) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, port, path, null, null); checkValid(); } @@ -209,13 +211,14 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @param query The query string. + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String user, String password, String host, int port, String path, String query) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, port, path, query, null); checkValid(); } @@ -228,7 +231,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String host, String path, String query, String fragment) throws URIException { @@ -246,7 +249,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String userinfo, String host, String path, String query, String fragment) throws URIException { @@ -263,7 +266,7 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String userinfo, String host, int port, String path) throws URIException { @@ -281,7 +284,7 @@ * @param port the port number * @param path the path string * @param query the query string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String userinfo, String host, int port, String path, String query) throws URIException { @@ -300,7 +303,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(String userinfo, String host, int port, String path, String query, String fragment) throws URIException { @@ -308,7 +311,7 @@ // validate and contruct the URI character sequence StringBuffer buff = new StringBuffer(); if (userinfo != null || host != null || port != -1) { - _scheme = _default_scheme; // in order to verify the own protocol + _scheme = DEFAULT_SCHEME; // in order to verify the own protocol buff.append(_default_scheme); buff.append("://"); if (userinfo != null) { @@ -317,7 +320,7 @@ } if (host != null) { buff.append(host); - if (port != -1 || port != _default_port) { + if (port != -1 || port != DEFAULT_PORT) { buff.append(':'); buff.append(port); } @@ -348,7 +351,7 @@ * * @param base the base HttpURL * @param relative the relative HTTP URL string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(HttpURL base, String relative) throws URIException { this(base, new HttpURL(relative)); @@ -360,7 +363,7 @@ * * @param base the base HttpURL * @param relative the relative HttpURL - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpURL(HttpURL base, HttpURL relative) throws URIException { super(base, relative); @@ -372,14 +375,26 @@ /** * Default scheme for HTTP URL. */ - public static final char[] _default_scheme = { 'h', 't', 't', 'p' }; + public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p' }; + /** + * Default scheme for HTTP URL. + * @deprecated Use {@link #DEFAULT_SCHEME} instead. This one doesn't + * conform to the project naming conventions. + */ + public static final char[] _default_scheme = DEFAULT_SCHEME; /** * Default port for HTTP URL. */ - public static final int _default_port = 80; + public static final int DEFAULT_PORT = 80; + /** + * Default port for HTTP URL. + * @deprecated Use {@link #DEFAULT_PORT} instead. This one doesn't conform + * to the project naming conventions. + */ + public static final int _default_port = DEFAULT_PORT; /** * The serialVersionUID. @@ -394,7 +409,7 @@ * @return the scheme */ public char[] getRawScheme() { - return (_scheme == null) ? null : _default_scheme; + return (_scheme == null) ? null : DEFAULT_SCHEME; } @@ -404,16 +419,17 @@ * @return the scheme null if empty or undefined */ public String getScheme() { - return (_scheme == null) ? null : new String(_default_scheme); + return (_scheme == null) ? null : new String(DEFAULT_SCHEME); } // --------------------------------------------------------------- The port /** * Get the port number. + * @return the port number */ public int getPort() { - return (_port == -1) ? _default_port : _port; + return (_port == -1) ? DEFAULT_PORT : _port; } // ----------------------------------------------------------- The userinfo @@ -429,16 +445,18 @@ public void setRawUserinfo(char[] escapedUser, char[] escapedPassword) throws URIException { - if (escapedUser == null || escapedUser.length == 0) + if (escapedUser == null || escapedUser.length == 0) { throw new URIException(URIException.PARSING, "user required"); - if (!validate(escapedUser, within_userinfo) || - ((escapedPassword != null) && - !validate(escapedPassword, within_userinfo))) + } + if (!validate(escapedUser, within_userinfo) + || ((escapedPassword != null) + && !validate(escapedPassword, within_userinfo))) { throw new URIException(URIException.ESCAPING, "escaped userinfo not valid"); + } String username = new String(escapedUser); - String password = (escapedPassword == null) ? null : - new String(escapedPassword); + String password = (escapedPassword == null) + ? null : new String(escapedPassword); String userinfo = username + ((password == null) ? "" : ":" + password); String hostname = new String(getRawHost()); String hostport = (_port == -1) ? hostname : hostname + _port; @@ -459,10 +477,10 @@ * @throws NullPointerException null user */ public void setEscapedUserinfo(String escapedUser, String escapedPassword) - throws URIException { + throws URIException, NullPointerException { - setRawUserinfo(escapedUser.toCharArray(), (escapedPassword == null) ? - null : escapedPassword.toCharArray()); + setRawUserinfo(escapedUser.toCharArray(), (escapedPassword == null) + ? null : escapedPassword.toCharArray()); } @@ -474,24 +492,27 @@ * @exception URIException encoding error or username missed * @throws NullPointerException null user */ - public void setUserinfo(String user, String password) throws URIException { - setRawUserinfo(encode(user, within_userinfo), (password == null) ? - null : encode(password, within_userinfo)); + public void setUserinfo(String user, String password) + throws URIException, NullPointerException { + setRawUserinfo(encode(user, within_userinfo), (password == null) + ? null : encode(password, within_userinfo)); } /** * Set the raw-escaped user. * - * @param the raw-escaped user + * @param escapedUser the raw-escaped user * @exception URIException escaped user not valid or user required */ public void setRawUser(char[] escapedUser) throws URIException { - if (escapedUser == null || escapedUser.length == 0) + if (escapedUser == null || escapedUser.length == 0) { throw new URIException(URIException.PARSING, "user required"); - if (!validate(escapedUser, within_userinfo)) + } + if (!validate(escapedUser, within_userinfo)) { throw new URIException(URIException.ESCAPING, "escaped user not valid"); + } String username = new String(escapedUser); String password = new String(getRawPassword()); String userinfo = username + ((password == null) ? "" : ":" + password); @@ -511,7 +532,7 @@ * @exception URIException escaped user not valid * @throws NullPointerException null user */ - public void setEscapedUser(String escapedUser) throws URIException { + public void setEscapedUser(String escapedUser) throws URIException, NullPointerException { setRawUser(escapedUser.toCharArray()); } @@ -523,7 +544,7 @@ * @exception URIException user encoding error * @throws NullPointerException null user */ - public void setUser(String user) throws URIException { + public void setUser(String user) throws URIException, NullPointerException { setRawUser(encode(user, allowed_within_userinfo)); } @@ -563,7 +584,7 @@ * Get the user. * * @return the user name - * @exception URIException + * @exception URIException If {@link #decode(char[])} fails */ public String getUser() throws URIException { char[] user = getRawUser(); @@ -574,16 +595,18 @@ /** * Set the raw-escaped password. * - * @param password the raw-escaped password; could be null + * @param escapedPassword the raw-escaped password; could be null * @exception URIException escaped password not valid or username missed */ public void setRawPassword(char[] escapedPassword) throws URIException { - if (escapedPassword != null && - !validate(escapedPassword, within_userinfo)) + if (escapedPassword != null + && !validate(escapedPassword, within_userinfo)) { throw new URIException(URIException.ESCAPING, - "escaped password not valid"); - if (getRawUser() == null || getRawUser().length == 0) + "escaped password not valid"); + } + if (getRawUser() == null || getRawUser().length == 0) { throw new URIException(URIException.PARSING, "username required"); + } String username = new String(getRawUser()); String password = new String(escapedPassword); // an emtpy string is allowed as a password @@ -600,12 +623,12 @@ /** * Set the escaped password string. * - * @param password the escaped password string; could be null + * @param escapedPassword the escaped password string; could be null * @exception URIException escaped password not valid or username missed */ public void setEscapedPassword(String escapedPassword) throws URIException { - setRawPassword((escapedPassword == null) ? null : - escapedPassword.toCharArray()); + setRawPassword((escapedPassword == null) ? null + : escapedPassword.toCharArray()); } @@ -616,8 +639,8 @@ * @exception URIException encoding error or username missed */ public void setPassword(String password) throws URIException { - setRawPassword((password == null) ? null : - encode(password, allowed_within_userinfo)); + setRawPassword((password == null) ? null + : encode(password, allowed_within_userinfo)); } @@ -653,7 +676,7 @@ * Get the password. * * @return the password - * @exception URIException + * @exception URIException If {@link #decode(char[],String)} fails. */ public String getPassword() throws URIException { char[] password = getRawPassword(); @@ -666,11 +689,11 @@ * Get the raw-escaped current hierarchy level. * * @return the raw-escaped current hierarchy level - * @exception URIException no hierarchy level + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. */ public char[] getRawCurrentHierPath() throws URIException { - return (_path == null || _path.length == 0) ? rootPath : - super.getRawCurrentHierPath(_path); + return (_path == null || _path.length == 0) ? rootPath + : super.getRawCurrentHierPath(_path); } @@ -678,12 +701,11 @@ * Get the level above the this hierarchy level. * * @return the raw above hierarchy level - * @exception URIException + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. */ public char[] getRawAboveHierPath() throws URIException { char[] path = getRawCurrentHierPath(); - return (path == null || path.length == 0) ? rootPath : - getRawCurrentHierPath(path); + return (path == null || path.length == 0) ? rootPath : getRawCurrentHierPath(path); } @@ -710,7 +732,7 @@ * @see #encode */ public void setQuery(String queryName, String queryValue) - throws URIException { + throws URIException, NullPointerException { StringBuffer buff = new StringBuffer(); buff.append(encode(queryName, allowed_within_query)); @@ -732,18 +754,21 @@ * @see #encode */ public void setQuery(String[] queryName, String[] queryValue) - throws URIException { + throws URIException, NullPointerException { int length = queryName.length; - if (length != queryValue.length) + if (length != queryValue.length) { throw new URIException("wrong array size of query"); + } StringBuffer buff = new StringBuffer(); for (int i = 0; i < length; i++) { buff.append(encode(queryName[i], allowed_within_query)); buff.append('='); buff.append(encode(queryValue[i], allowed_within_query)); - if (i + 1 < length) buff.append('&'); + if (i + 1 < length) { + buff.append('&'); + } } _query = buff.toString().toCharArray(); setURI(); @@ -758,7 +783,7 @@ */ protected void checkValid() throws URIException { // could be explicit protocol or undefined. - if (!(equals(_scheme, _default_scheme) || _scheme == null)) { + if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { throw new URIException(URIException.PARSING, "wrong class use"); } } Index: httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java,v retrieving revision 1.4 diff -u -r1.4 HttpsURL.java --- httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java 28 Jan 2003 04:40:21 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/HttpsURL.java 28 Jan 2003 20:28:49 -0000 @@ -67,11 +67,15 @@ * The HTTPS URL. * * @author Sung-Gu + * @author Mike Bowler */ public class HttpsURL extends HttpURL { // ----------------------------------------------------------- Constructors + /** + * Create an instance. + */ protected HttpsURL() { } @@ -79,10 +83,10 @@ * Construct a HTTPS URL as an escaped form of a character array. * * @param escaped the HTTPS URL character sequence - * @exception URIException + * @exception URIException If {@link #checkValid()} fails * @throws NullPointerException if escaped is null */ - public HttpsURL(char[] escaped) throws URIException { + public HttpsURL(char[] escaped) throws URIException, NullPointerException { parseUriReference(new String(escaped), true); checkValid(); } @@ -92,7 +96,7 @@ * Construct a HTTPS URL from a given string. * * @param original the HTTPS URL string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String original) throws URIException { parseUriReference(original, false); @@ -105,7 +109,7 @@ * * @param host the host string * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String host, String path) throws URIException { this(null, host, -1, path, null, null); @@ -119,7 +123,7 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String host, int port, String path) throws URIException { this(null, host, port, path, null, null); @@ -134,7 +138,7 @@ * @param port the port number * @param path the path string * @param query the query string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String host, int port, String path, String query) throws URIException { @@ -150,13 +154,13 @@ * @param user the user name * @param password his or her password * @param host the host string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String user, String password, String host) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, -1, null, null, null); checkValid(); } @@ -169,13 +173,13 @@ * @param password his or her password * @param host the host string * @param port the port number - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String user, String password, String host, int port) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, port, null, null, null); checkValid(); } @@ -189,13 +193,13 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String user, String password, String host, int port, String path) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, port, path, null, null); checkValid(); } @@ -209,13 +213,14 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @param query The query string. + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String user, String password, String host, int port, String path, String query) throws URIException { - this((user == null) ? null : user + - ((password == null) ? "" : ':' + password), + this((user == null) ? null : user + + ((password == null) ? "" : ':' + password), host, port, path, query, null); checkValid(); } @@ -228,7 +233,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String host, String path, String query, String fragment) throws URIException { @@ -246,7 +251,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String userinfo, String host, String path, String query, String fragment) throws URIException { @@ -263,7 +268,7 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String userinfo, String host, int port, String path) throws URIException { @@ -281,7 +286,7 @@ * @param port the port number * @param path the path string * @param query the query string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String userinfo, String host, int port, String path, String query) throws URIException { @@ -300,7 +305,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(String userinfo, String host, int port, String path, String query, String fragment) throws URIException { @@ -308,7 +313,7 @@ // validate and contruct the URI character sequence StringBuffer buff = new StringBuffer(); if (userinfo != null || host != null || port != -1) { - _scheme = _default_scheme; // in order to verify the own protocol + _scheme = DEFAULT_SCHEME; // in order to verify the own protocol buff.append(_default_scheme); buff.append("://"); if (userinfo != null) { @@ -317,7 +322,7 @@ } if (host != null) { buff.append(host); - if (port != -1 || port != _default_port) { + if (port != -1 || port != DEFAULT_PORT) { buff.append(':'); buff.append(port); } @@ -348,7 +353,7 @@ * * @param base the base HttpsURL * @param relative the relative HTTPS URL string - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(HttpsURL base, String relative) throws URIException { this(base, new HttpsURL(relative)); @@ -360,7 +365,7 @@ * * @param base the base HttpsURL * @param relative the relative HttpsURL - * @exception URIException + * @exception URIException If {@link #checkValid()} fails */ public HttpsURL(HttpsURL base, HttpsURL relative) throws URIException { super(base, relative); @@ -371,14 +376,30 @@ /** * Default scheme for HTTPS URL. + * TODO: Should this really be public? Who else is going to use it? + */ + public static final char[] DEFAULT_SCHEME = { 'h', 't', 't', 'p', 's' }; + + /** + * Default scheme for HTTPS URL. + * @deprecated Use {@link #DEFAULT_SCHEME} instead. This one doesn't + * conform to the project naming conventions. */ - public static final char[] _default_scheme = { 'h', 't', 't', 'p', 's' }; + public static final char[] _default_scheme = DEFAULT_SCHEME; /** * Default port for HTTPS URL. + * TODO: Should this really be public? Who else is going to use it? + */ + public static final int DEFAULT_PORT = 443; + + /** + * Default port for HTTPS URL. + * @deprecated Use {@link #DEFAULT_PORT} instead. This one doesn't conform + * to the project naming conventions. */ - public static final int _default_port = 443; + public static final int _default_port = DEFAULT_PORT; /** @@ -395,7 +416,7 @@ */ protected void checkValid() throws URIException { // could be explicit protocol or undefined. - if (!(equals(_scheme, _default_scheme) || _scheme == null)) { + if (!(equals(_scheme, DEFAULT_SCHEME) || _scheme == null)) { throw new URIException(URIException.PARSING, "wrong class use"); } } Index: httpclient/src/java/org/apache/commons/httpclient/URI.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/URI.java,v retrieving revision 1.25 diff -u -r1.25 URI.java --- httpclient/src/java/org/apache/commons/httpclient/URI.java 28 Jan 2003 05:17:21 -0000 1.25 +++ httpclient/src/java/org/apache/commons/httpclient/URI.java 28 Jan 2003 20:28:48 -0000 @@ -143,6 +143,7 @@ *

* * @author Sung-Gu + * @author Mike Bowler * @version $Revision: 1.25 $ $Date: 2002/03/14 15:14:01 */ public class URI implements Cloneable, Comparable, Serializable { @@ -249,7 +250,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(String scheme, String authority, String path, String query, String fragment) throws URIException { @@ -291,7 +292,7 @@ * @param userinfo the userinfo string * @param host the host string * @param port the port number - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(String scheme, String userinfo, String host, int port) throws URIException { @@ -308,7 +309,7 @@ * @param host the host string * @param port the port number * @param path the path string - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(String scheme, String userinfo, String host, int port, String path) throws URIException { @@ -326,7 +327,7 @@ * @param port the port number * @param path the path string * @param query the query string - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(String scheme, String userinfo, String host, int port, String path, String query) throws URIException { @@ -345,7 +346,7 @@ * @param path the path string * @param query the query string * @param fragment the fragment string - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(String scheme, String userinfo, String host, int port, String path, String query, String fragment) throws URIException { @@ -363,7 +364,7 @@ * @param host the host string * @param path the path string * @param fragment the fragment string - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(String scheme, String host, String path, String fragment) throws URIException { @@ -377,7 +378,7 @@ * * @param base the base URI * @param relative the relative URI string - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(URI base, String relative) throws URIException { this(base, new URI(relative)); @@ -432,7 +433,7 @@ * * @param base the base URI * @param relative the relative URI - * @exception URIException + * @exception URIException If the new URI cannot be created. */ public URI(URI base, URI relative) throws URIException { @@ -2828,7 +2829,7 @@ throw new URIException(URIException.PARSING, "no hierarchy level"); } if (path == null) { - throw new URIException(URIException.PARSING, "emtpy path"); + throw new URIException(URIException.PARSING, "empty path"); } String buff = new String(path); int first = buff.indexOf('/'); @@ -2847,7 +2848,7 @@ * Get the raw-escaped current hierarchy level. * * @return the raw-escaped current hierarchy level - * @exception URIException no hierarchy level + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. */ public char[] getRawCurrentHierPath() throws URIException { return (_path == null) ? null : getRawCurrentHierPath(_path); @@ -2858,7 +2859,7 @@ * Get the escaped current hierarchy level. * * @return the escaped current hierarchy level - * @exception URIException no hierarchy level + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. */ public String getEscapedCurrentHierPath() throws URIException { char[] path = getRawCurrentHierPath(); @@ -2870,7 +2871,7 @@ * Get the current hierarchy level. * * @return the current hierarchy level - * @exception URIException + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. * @see #decode */ public String getCurrentHierPath() throws URIException { @@ -2883,7 +2884,7 @@ * Get the level above the this hierarchy level. * * @return the raw above hierarchy level - * @exception URIException + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. */ public char[] getRawAboveHierPath() throws URIException { char[] path = getRawCurrentHierPath(); @@ -2895,7 +2896,7 @@ * Get the level above the this hierarchy level. * * @return the raw above hierarchy level - * @exception URIException + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. */ public String getEscapedAboveHierPath() throws URIException { char[] path = getRawAboveHierPath(); @@ -2907,7 +2908,7 @@ * Get the level above the this hierarchy level. * * @return the above hierarchy level - * @exception URIException + * @exception URIException If {@link #getRawCurrentHierPath(char[])} fails. * @see #decode */ public String getAboveHierPath() throws URIException { Index: httpclient/src/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.21 diff -u -r1.21 GetMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java 23 Jan 2003 22:48:06 -0000 1.21 +++ httpclient/src/java/org/apache/commons/httpclient/methods/GetMethod.java 28 Jan 2003 20:28:49 -0000 @@ -82,6 +82,7 @@ * @author Remy Maucherat * @author Sung-Gu Park * @author Sean C. Sullivan + * @author Mike Bowler * @since 1.0 */ public class GetMethod extends HttpMethodBase { @@ -90,7 +91,7 @@ // -------------------------------------------------------------- Constants /** Log object for this class. */ - private static final Log log = LogFactory.getLog(GetMethod.class); + private static final Log LOG = LogFactory.getLog(GetMethod.class); /** Temporary directory. */ private static final String TEMP_DIR = "temp/"; @@ -132,7 +133,7 @@ */ public GetMethod(String uri) { super(uri); - log.trace("enter GetMethod(String)"); + LOG.trace("enter GetMethod(String)"); setFollowRedirects(true); } @@ -146,7 +147,7 @@ */ public GetMethod(String path, String tempDir) { super(path); - log.trace("enter GetMethod(String, String)"); + LOG.trace("enter GetMethod(String, String)"); setUseDisk(true); setTempDir(tempDir); setFollowRedirects(true); @@ -163,7 +164,7 @@ */ public GetMethod(String path, String tempDir, String tempFile) { super(path); - log.trace("enter GetMethod(String, String, String)"); + LOG.trace("enter GetMethod(String, String, String)"); setUseDisk(true); setTempDir(tempDir); setTempFile(tempFile); @@ -180,7 +181,7 @@ */ public GetMethod(String path, File fileData) { this(path); - log.trace("enter GetMethod(String, File)"); + LOG.trace("enter GetMethod(String, File)"); useDisk = true; this.fileData = fileData; setFollowRedirects(true); @@ -233,7 +234,7 @@ * @since 2.0 */ public byte[] getResponseBody() { - log.trace("enter GetMethod.getResponseBody()"); + LOG.trace("enter GetMethod.getResponseBody()"); checkUsed(); return super.getResponseBody(); @@ -250,7 +251,7 @@ * @since 2.0 */ public InputStream getResponseBodyAsStream() throws IOException { - log.trace("enter GetMethod.getResponseBodyAsStream()"); + LOG.trace("enter GetMethod.getResponseBodyAsStream()"); checkUsed(); return super.getResponseBodyAsStream(); @@ -336,7 +337,7 @@ * @since 1.0 */ public void recycle() { - log.trace("enter GetMethod.recycle()"); + LOG.trace("enter GetMethod.recycle()"); super.recycle(); this.fileData = null; @@ -353,12 +354,12 @@ * @param conn the connection to read data from * * @throws IOException when there are problems reading from the connection - * + * @throws HttpException when a protocol error occurs or state is invalid * @since 2.0 */ protected void readResponseBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter GetMethod.readResponseBody(HttpState, HttpConnection)"); + LOG.trace("enter GetMethod.readResponseBody(HttpState, HttpConnection)"); super.readResponseBody(state, conn); Index: httpclient/src/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.14 diff -u -r1.14 HeadMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java 23 Jan 2003 22:48:06 -0000 1.14 +++ httpclient/src/java/org/apache/commons/httpclient/methods/HeadMethod.java 28 Jan 2003 20:28:50 -0000 @@ -74,13 +74,14 @@ * HEAD Method. * * @author Remy Maucherat + * @author Mike Bowler * @since 1.0 */ public class HeadMethod extends HttpMethodBase { //~ Static variables/initializers ·········································· /** Log object for this class. */ - private static final Log log = LogFactory.getLog(HeadMethod.class); + private static final Log LOG = LogFactory.getLog(HeadMethod.class); //~ Constructors ··························································· @@ -143,7 +144,7 @@ */ protected void readResponseBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace( + LOG.trace( "enter HeadMethod.readResponseBody(HttpState, HttpConnection)"); // despite the possible presence of a content-length header, Index: httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java,v retrieving revision 1.6 diff -u -r1.6 MultipartPostMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 23 Jan 2003 22:48:08 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/methods/MultipartPostMethod.java 28 Jan 2003 20:28:49 -0000 @@ -62,15 +62,19 @@ package org.apache.commons.httpclient.methods; -import java.util.List; -import java.util.ArrayList; -import java.util.Iterator; import java.io.File; -import java.io.OutputStream; -import java.io.IOException; import java.io.FileNotFoundException; -import org.apache.commons.httpclient.*; -import org.apache.commons.httpclient.methods.multipart.*; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.apache.commons.httpclient.HttpConnection; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpState; +import org.apache.commons.httpclient.methods.multipart.FilePart; +import org.apache.commons.httpclient.methods.multipart.Part; +import org.apache.commons.httpclient.methods.multipart.StringPart; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -81,15 +85,17 @@ * @author Jeff Dever * @author Adrian Sutton * @author Mark Diggory + * @author Mike Bowler * * @since 2.0 */ public class MultipartPostMethod extends GetMethod { /** Log object for this class. */ - private static final Log log = LogFactory.getLog(MultipartPostMethod.class); + private static final Log LOG = LogFactory.getLog(MultipartPostMethod.class); - private List parameters = new ArrayList(); + /** The parameters for this method */ + private final List parameters = new ArrayList(); /** * No-arg constructor. @@ -141,65 +147,96 @@ * Clear my request body. */ public void recycle() { - log.trace("enter recycle()"); + LOG.trace("enter recycle()"); super.recycle(); parameters.clear(); } - + /** + * Add a parameter + * @param parameterName The name of the parameter. + * @param parameterValue The value of the parameter. + */ public void addParameter(String parameterName, String parameterValue) { - log.trace("enter addParameter(String parameterName, String parameterValue)"); + LOG.trace("enter addParameter(String parameterName, String parameterValue)"); Part param = new StringPart(parameterName, parameterValue); parameters.add(param); } - + /** + * Add a parameter + * @param parameterName The name of the parameter + * @param parameterFile The name of the file. + * @throws FileNotFoundException If the file cannot be found. + */ public void addParameter(String parameterName, File parameterFile) throws FileNotFoundException { - log.trace("enter addParameter(String parameterName, File parameterFile)"); + LOG.trace("enter addParameter(String parameterName, File parameterFile)"); Part param = new FilePart(parameterName, parameterFile); parameters.add(param); } + /** + * Add a parameter. + * + * @param parameterName The name of the parameter + * @param fileName The file name + * @param parameterFile The file + * @throws FileNotFoundException If the file cannot be found. + */ public void addParameter(String parameterName, String fileName, File parameterFile) throws FileNotFoundException { - log.trace("enter addParameter(String parameterName, String fileName, File parameterFile)"); + LOG.trace("enter addParameter(String parameterName, String fileName, File parameterFile)"); Part param = new FilePart(parameterName, fileName, parameterFile); parameters.add(param); } /** * Adds another part to this post. + * @param part The part to add. */ - public void addPart( Part part ) { - log.trace("enter addPart(Part part)"); + public void addPart (final Part part) { + LOG.trace("enter addPart(Part part)"); parameters.add(part); } + /** + * Add a request header. + * + * @param state the client state + * @param conn the {@link HttpConnection} the headers will eventually be + * written to + * @throws IOException when an error occurs writing the request + * @throws HttpException when a HTTP protocol error occurs + */ protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter addRequestHeaders(HttpState state, HttpConnection conn)"); - super.addRequestHeaders(state,conn); + LOG.trace("enter addRequestHeaders(HttpState state, HttpConnection conn)"); + super.addRequestHeaders(state, conn); - if (! parameters.isEmpty()) - { + if (!parameters.isEmpty()) { setRequestHeader("Content-Type", "multipart/form-data; boundary=" + Part.getBoundary()); } } /** - * Override method of {@link HttpMethodBase} - * to write request parameters as the - * request body. + * Write the request body. + * + * @param state the client state + * @param conn the connection to write to + * + * @return true + * @throws IOException when i/o errors occur reading the response + * @throws HttpException when a protocol error occurs or state is invalid */ protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter writeRequestBody(HttpState state, HttpConnection conn)"); + LOG.trace("enter writeRequestBody(HttpState state, HttpConnection conn)"); OutputStream out = conn.getRequestOutputStream(); for (Iterator it = parameters.iterator(); it.hasNext();) { - Part part = (Part)it.next(); + final Part part = (Part) it.next(); part.send(out); } @@ -211,20 +248,20 @@ } /** - * Override method of {@link HttpMethodBase} - * to return the length of the request body. + *

Return the length of the request body.

* - * Once this method has been invoked, - * the request parameters cannot be altered - * until I am {@link #recycle recycled}. + *

Once this method has been invoked, the request parameters cannot be + * altered until I am {@link #recycle recycled}.

+ * + * @return The request content length. */ protected int getRequestContentLength() { - log.trace("enter getRequestContentLength()"); + LOG.trace("enter getRequestContentLength()"); long length = 0; try { for (Iterator it = parameters.iterator(); it.hasNext();) { - Part part = (Part)it.next(); + final Part part = (Part) it.next(); length += part.length(); } @@ -237,9 +274,9 @@ // Chop the length to the max int value. if (length <= Integer.MAX_VALUE) { - return((new Long(length)).intValue()); + return ((new Long(length)).intValue()); } else { - return(Integer.MAX_VALUE); + return (Integer.MAX_VALUE); } } } Index: httpclient/src/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.10 diff -u -r1.10 OptionsMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/OptionsMethod.java 23 Jan 2003 22:48:08 -0000 1.10 +++ httpclient/src/java/org/apache/commons/httpclient/methods/OptionsMethod.java 28 Jan 2003 20:28:49 -0000 @@ -78,6 +78,7 @@ * OPTIONS Method. * * @author Remy Maucherat + * @author Mike Bowler * * @since 1.0 */ @@ -88,7 +89,7 @@ // --------------------------------------------------------- Class Variables /** Log object for this class. */ - private static final Log log = LogFactory.getLog(OptionsMethod.class); + private static final Log LOG = LogFactory.getLog(OptionsMethod.class); // ----------------------------------------------------------- Constructors @@ -126,7 +127,8 @@ // --------------------------------------------------------- Public Methods /** - * + * Get the name. + * @return "OPTIONS" * @since 2.0 */ public String getName() { @@ -136,7 +138,9 @@ /** * Is the specified method allowed ? - * + * + * @param method The method to check. + * @return true if the specified method is allowed. * @since 1.0 */ public boolean isAllowed(String method) { @@ -147,6 +151,7 @@ /** * Get a list of allowed methods. + * @return An enumeration of all the allowed methods. * * @since 1.0 */ @@ -159,11 +164,13 @@ // ----------------------------------------------------- HttpMethod Methods /** - * + * Process the response headers. + * @param state The state. + * @param conn The connection. * @since 2.0 */ protected void processResponseHeaders(HttpState state, HttpConnection conn) { - log.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)"); + LOG.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)"); Header allowHeader = getResponseHeader("allow"); if (allowHeader != null) { Index: httpclient/src/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.33 diff -u -r1.33 PostMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java 23 Jan 2003 22:48:08 -0000 1.33 +++ httpclient/src/java/org/apache/commons/httpclient/methods/PostMethod.java 28 Jan 2003 20:28:50 -0000 @@ -115,6 +115,7 @@ * @author Doug Sale * @author Jeff Dever * @author Ortwin Glück + * @author Mike Bowler * @since 1.0 */ public class PostMethod extends GetMethod { @@ -135,10 +136,10 @@ // -------------------------------------------------------------- Constants /** Log object for this class. */ - private static final Log log = LogFactory.getLog(PostMethod.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", + private static final Header CONTENT_TYPE = new Header("Content-Type", "application/x-www-form-urlencoded"); /** The buffered request body. */ @@ -153,8 +154,10 @@ /** Counts how often the request was sent to the server. */ protected int repeatCount = 0; - /** The content length of the requestBody or one of - * CONTENT_LENGTH_AUTO and CONTENT_LENGTH_CHUNKED. + /** + * The content length of the requestBody or one of + * {@link #CONTENT_LENGTH_AUTO} and + * {@link #CONTENT_LENGTH_CHUNKED}. */ protected int requestContentLength = CONTENT_LENGTH_AUTO; @@ -190,8 +193,8 @@ * * @since 1.0 */ - public PostMethod(String uti, String tempDir) { - super(uti, tempDir); + public PostMethod(String uri, String tempDir) { + super(uri, tempDir); setFollowRedirects(false); } @@ -257,8 +260,9 @@ * @deprecated use {@link #removeParameter(String,String)} followed by * {@link #addParameter(String,String)}. */ - public void setParameter(String parameterName, String parameterValue) { - log.trace("enter PostMethod.setParameter(String, String)"); + public void setParameter(String parameterName, String parameterValue) + throws IllegalStateException { + LOG.trace("enter PostMethod.setParameter(String, String)"); if (null != requestBody) { throw new IllegalStateException("Request body already generated."); @@ -280,7 +284,7 @@ * @since 2.0 */ public NameValuePair getParameter(String paramName) { - log.trace("enter PostMethod.getParameter(String)"); + LOG.trace("enter PostMethod.getParameter(String)"); if (paramName == null) { return null; @@ -311,7 +315,7 @@ * @see #getParameter(java.lang.String) */ public NameValuePair[] getParameters() { - log.trace("enter PostMethod.getParameters()"); + LOG.trace("enter PostMethod.getParameters()"); int numPairs = parameters.size(); Object[] objectArr = parameters.toArray(); @@ -338,8 +342,8 @@ * * @since 2.0 */ - public void setRequestBody(String body) { - log.trace("enter PostMethod.setRequestBody(String)"); + public void setRequestBody(String body) throws IllegalStateException { + LOG.trace("enter PostMethod.setRequestBody(String)"); if (!parameters.isEmpty()) { throw new IllegalStateException( @@ -369,8 +373,8 @@ * * @since 2.0 */ - public void setRequestBody(InputStream body) { - log.trace("enter PostMethod.getRequestBody(InputStream)"); + public void setRequestBody(InputStream body) throws IllegalStateException { + LOG.trace("enter PostMethod.getRequestBody(InputStream)"); if (!parameters.isEmpty()) { throw new IllegalStateException( @@ -389,7 +393,7 @@ * @since 2.0 */ public InputStream getRequestBody() { - log.trace("enter PostMethod.getRequestBody()"); + LOG.trace("enter PostMethod.getRequestBody()"); if (requestBody != null) { return requestBody; @@ -401,15 +405,15 @@ } /** - * DOCUMENT ME! + * Return the request body as a string. * * @return the request body as a string - * @throws IOException DOCUMENT ME! + * @throws IOException If an IO problem occurs. * * @since 2.0 */ public String getRequestBodyAsString() throws IOException { - log.trace("enter PostMethod.getRequestBodyAsString()"); + LOG.trace("enter PostMethod.getRequestBodyAsString()"); StringBuffer buffer = new StringBuffer(); InputStream requestBody = getRequestBody(); @@ -446,8 +450,11 @@ * * @since 2.0 */ - public void setRequestContentLength(int length) { - log.trace("enter PostMethod.setRequestContentLength(int)"); + public void setRequestContentLength(int length) + throws RuntimeException { + //TODO: We should be throwing a more specific exception than this. + + LOG.trace("enter PostMethod.setRequestContentLength(int)"); if ((length == CONTENT_LENGTH_CHUNKED) && !isHttp11()) { throw new RuntimeException( @@ -469,8 +476,10 @@ * * @since 1.0 */ - public void addParameter(String paramName, String paramValue) { - log.trace("enter PostMethod.addParameter(String, String)"); + public void addParameter(String paramName, String paramValue) + throws IllegalStateException, IllegalArgumentException { + + LOG.trace("enter PostMethod.addParameter(String, String)"); if (null != requestBody) { throw new IllegalStateException("Request body already generated."); @@ -497,8 +506,10 @@ * @since 2.0 * @see #addParameter(String,String) */ - public void addParameter(NameValuePair param) { - log.trace("enter PostMethod.addParameter(NameValuePair)"); + public void addParameter(NameValuePair param) + throws IllegalStateException, IllegalArgumentException { + + LOG.trace("enter PostMethod.addParameter(NameValuePair)"); if (null != requestBody) { throw new IllegalStateException("Request body already generated."); @@ -524,15 +535,17 @@ * @since 2.0 * @see #addParameter(org.apache.commons.httpclient.NameValuePair) */ - public void addParameters(NameValuePair[] parameters) { - log.trace("enter PostMethod.addParameters(NameValuePair[])"); + public void addParameters(NameValuePair[] parameters) + throws IllegalStateException { + + LOG.trace("enter PostMethod.addParameters(NameValuePair[])"); if (null != requestBody) { throw new IllegalStateException("Request body already generated."); } if (null == parameters) { - log.warn("Attempt to addParameters(null) ignored"); + LOG.warn("Attempt to addParameters(null) ignored"); } else { for (int i = 0; i < parameters.length; i++) { addParameter(parameters[i]); @@ -547,7 +560,7 @@ * @since 1.0 */ public void recycle() { - log.trace("enter PostMethod.recycle()"); + LOG.trace("enter PostMethod.recycle()"); super.recycle(); requestBody = null; requestContentLength = CONTENT_LENGTH_AUTO; @@ -572,8 +585,10 @@ * * @since 2.0 */ - public boolean removeParameter(String paramName) { - log.trace("enter PostMethod.removeParameter(String)"); + public boolean removeParameter(String paramName) + throws IllegalArgumentException, IllegalStateException { + + LOG.trace("enter PostMethod.removeParameter(String)"); if (null != requestBody) { throw new IllegalStateException("Request body already generated."); @@ -615,8 +630,10 @@ * * @since 2.0 */ - public boolean removeParameter(String paramName, String paramValue) { - log.trace("enter PostMethod.removeParameter(String, String)"); + public boolean removeParameter(String paramName, String paramValue) + throws IllegalArgumentException, IllegalStateException { + + LOG.trace("enter PostMethod.removeParameter(String, String)"); if (null != requestBody) { throw new IllegalStateException("Request body already generated."); @@ -653,7 +670,7 @@ * @since 2.0 */ protected int getRequestContentLength() { - log.trace("enter PostMethod.getRequestContentLength()"); + LOG.trace("enter PostMethod.getRequestContentLength()"); if (null == requestBody) { requestBody = generateRequestBody(parameters); @@ -708,7 +725,7 @@ */ protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace( + LOG.trace( "enter PostMethod.writeRequestBody(HttpState, HttpConnection)"); if (null == requestBody) { @@ -742,11 +759,12 @@ total += i; } if (outstream instanceof ChunkedOutputStream) { - ((ChunkedOutputStream)outstream).writeClosingChunk(); + ((ChunkedOutputStream) outstream).writeClosingChunk(); } if ((this.requestContentLength > 0) && (total < this.requestContentLength)) { throw new IOException("Unexpected end of input stream after " - +total +" bytes (expected "+ this.requestContentLength +" bytes)"); + + total + " bytes (expected " + + this.requestContentLength + " bytes)"); } if (buffer != null) { @@ -768,8 +786,8 @@ * @since 1.0 */ protected InputStream generateRequestBody(List params) { - log.trace("enter PostMethod.generateRequestBody(List)"); - String body = generateRequestBodyAsString(params); + LOG.trace("enter PostMethod.generateRequestBody(List)"); + String body = generateRequestBodyAsString(params); return new ByteArrayInputStream( HttpConstants.getContentBytes(body, getRequestCharSet())); @@ -788,7 +806,7 @@ * @since 2.0 */ protected static String generateRequestBodyAsString(List params) { - log.trace("enter PostMethod.generateRequestBodyAsString(List)"); + LOG.trace("enter PostMethod.generateRequestBodyAsString(List)"); Iterator it = params.iterator(); StringBuffer buff = new StringBuffer(); @@ -800,7 +818,7 @@ try { queryName = URIUtil.encodeWithinQuery(parameter.getName()); } catch (URIException urie) { - log.error("encoding error within query name", urie); + LOG.error("encoding error within query name", urie); queryName = parameter.getName(); } buff.append(queryName).append("="); @@ -808,7 +826,7 @@ try { queryValue = URIUtil.encodeWithinQuery(parameter.getValue()); } catch (URIException urie) { - log.error("encoding error within query value", urie); + LOG.error("encoding error within query value", urie); queryValue = parameter.getValue(); } buff.append(queryValue); @@ -826,7 +844,7 @@ * @since 1.0 */ private void bufferContent() { - log.trace("enter PostMethod.bufferContent()"); + LOG.trace("enter PostMethod.bufferContent()"); if (buffer != null) { return; Index: httpclient/src/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.19 diff -u -r1.19 PutMethod.java --- httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java 23 Jan 2003 22:48:09 -0000 1.19 +++ httpclient/src/java/org/apache/commons/httpclient/methods/PutMethod.java 28 Jan 2003 20:28:50 -0000 @@ -85,6 +85,7 @@ * PUT Method. * * @author Remy Maucherat + * @author Mike Bowler * * @since 1.0 */ @@ -153,6 +154,8 @@ /** * Set my request body content to the contents of a file. * + * @param file The file + * @throws IOException if an IO problem occurs * @since 2.0 */ public void setRequestBody(File file) throws IOException { @@ -163,6 +166,8 @@ /** * Set my request body content to the resource at the specified URL. * + * @param url The URL + * @throws IOException If an IO problem occurs. * @since 2.0 */ public void setRequestBody(URL url) throws IOException { @@ -173,6 +178,7 @@ /** * Set my request body content to the contents of a byte array. * + * @param bodydata The new content. * @since 2.0 */ public void setRequestBody(byte[] bodydata) { @@ -183,6 +189,7 @@ /** * Set my request body content to the contents of a string. * + * @param bodydata The new content * @since 2.0 */ public void setRequestBody(String bodydata) { @@ -191,16 +198,17 @@ } /** - * Set my request body content to the contents of an input stream. - * The contents will be buffered into - * memory. To upload large entities, it is recommended to first buffer the - * data into a temporary file, and then send that file. + * Set my request body content to the contents of an input stream. The + * contents will be buffered into memory. To upload large entities, it is + * recommended to first buffer the data into a temporary file, and then send + * that file. * + * @param is The input stream. + * @throws IOException If an IO problem occurs * @since 2.0 */ - public void setRequestBody(InputStream is) - throws IOException { - log.trace("enter PutMethod.setRequestBody(InputStream)"); + public void setRequestBody(InputStream is) throws IOException { + LOG.trace("enter PutMethod.setRequestBody(InputStream)"); checkNotUsed(); byte[] buffer = new byte[4096]; @@ -220,50 +228,59 @@ // ------------------------------------------------- HttpMethodBase Methods /** - * Override the method of {@link HttpMethodBase} - * to set the Expect header if it has - * not already been set, in addition to the "standard" - * set of headers. - * + * Override the method of {@link HttpMethodBase} to set the Expect + * header if it has not already been set, in addition to the "standard" set + * of headers. + * + * @param state The state. + * @param conn The connection. + * @throws IOException If an IO problem occurs + * @throws HttpException Never. * @since 2.0 */ protected void addRequestHeaders(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter PutMethod.addRequestHeaders(HttpState, HttpConnection)"); + // TODO: Determine why this method is declared to throw HttpException + // since it never actually does throw it. + LOG.trace("enter PutMethod.addRequestHeaders(HttpState, HttpConnection)"); - super.addRequestHeaders(state,conn); + super.addRequestHeaders(state, conn); // Send expectation header - if(isHttp11() && null == getRequestHeader("expect")) { - setRequestHeader("Expect","100-continue"); + if (isHttp11() && null == getRequestHeader("expect")) { + setRequestHeader("Expect", "100-continue"); } } /** - * Override the method of {@link HttpMethodBase} - * to not send any data until - * the 100 Continue status has not be - * read. + * Override the method of {@link HttpMethodBase} to not send any data until + * the 100 Continue status has not be read. * + * @param state The state + * @param conn The connection + * @return true if the data was written. + * @throws IOException If an IO problem occurs + * @throws HttpException This doesn't ever seem to be thrown. * @since 2.0 */ protected boolean writeRequestBody(HttpState state, HttpConnection conn) throws IOException, HttpException { - log.trace("enter PutMethod.writeRequestBody(HttpState, HttpConnection)"); + LOG.trace("enter PutMethod.writeRequestBody(HttpState, HttpConnection)"); if (getStatusLine() == null) { return false; } - if(null != getRequestHeader("expect") && - getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) { + if (null != getRequestHeader("expect") + && getStatusLine().getStatusCode() != HttpStatus.SC_CONTINUE) { return false; } - OutputStream out = conn.getRequestOutputStream((isHttp11() && (null == getRequestHeader("Content-Length")))); + OutputStream out = conn.getRequestOutputStream((isHttp11() + && (null == getRequestHeader("Content-Length")))); InputStream inputStream = null; if (file != null && file.exists()) { inputStream = new FileInputStream(file); } else if (url != null) { inputStream = url.openConnection().getInputStream(); - } else if(data != null){ + } else if (data != null) { inputStream = new ByteArrayInputStream(data); } else { return true; @@ -286,16 +303,17 @@ * Override the method of {@link HttpMethodBase} * to return the appropriate content length. * + * @return the content length * @since 2.0 */ protected int getRequestContentLength() { - log.trace("enter PutMethod.getRequestContentLength()"); + LOG.trace("enter PutMethod.getRequestContentLength()"); - if(null != data) { + if (null != data) { return data.length; - } else if(null != file && file.exists()) { - return (int)(file.length()); - } else if(url != null) { + } else if (null != file && file.exists()) { + return (int) (file.length()); + } else if (url != null) { return -1; } else { return 0; @@ -314,5 +332,5 @@ } /** Log object for this class. */ - private static final Log log = LogFactory.getLog(PutMethod.class); + private static final Log LOG = LogFactory.getLog(PutMethod.class); } Index: httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java,v retrieving revision 1.9 diff -u -r1.9 FilePart.java --- httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java 25 Jan 2003 00:59:11 -0000 1.9 +++ httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePart.java 28 Jan 2003 20:28:50 -0000 @@ -80,6 +80,7 @@ * @author Adrian Sutton * @author Michael Becke * @author Mark Diggory + * @author Mike Bowler * * @since 2.0 * @@ -87,10 +88,13 @@ public class FilePart extends Part { /** Log object for this class. */ - private static final Log log = LogFactory.getLog(FilePart.class); + private static final Log LOG = LogFactory.getLog(FilePart.class); - //TODO: make this configurable - static int MAX_BUFF_SIZE = 1 * 1024 * 1024; // 1 MiBs + /** + *

The maximum buffer size.

+ * TODO: make this configurable + */ + private static final int MAX_BUFF_SIZE = 1 * 1024 * 1024; // 1 MiBs /** Name of the file part. */ private String name; @@ -144,45 +148,70 @@ } + /** + * Write the header to the output stream + * @param out The output stream + * @throws IOException If an IO problem occurs + * @see org.apache.commons.httpclient.methods.multipart.Part#sendHeader(OutputStream) + */ protected void sendHeader(OutputStream out) throws IOException { - log.trace("enter sendHeader(OutputStream out)"); + LOG.trace("enter sendHeader(OutputStream out)"); super.sendHeader(out); sendFilename(out); sendContentType(out); } + /** + * Write the filename to the output stream + * @param out The output stream + * @throws IOException If an IO problem occurs + */ protected void sendFilename(OutputStream out) throws IOException { - log.trace("enter sendFilename(OutputStream out)"); + LOG.trace("enter sendFilename(OutputStream out)"); String filename = "; filename=\"" + source.getFileName() + "\""; out.write(HttpConstants.getBytes(filename)); } - + /** + * Write the Content-Type header to the output stream + * @param out The output stream. + * @throws IOException If an IO problem occurs + */ protected void sendContentType(OutputStream out) throws IOException { - log.trace("enter sendContentType(OutputStream out)"); - out.write(CRLF_bytes); + LOG.trace("enter sendContentType(OutputStream out)"); + out.write(CRLF_BYTES); out.write(HttpConstants.getBytes("Content-Type: application/octet-stream")); } + /** + * Return the name. + * @return The name. + * @see org.apache.commons.httpclient.methods.multipart.Part#getName() + */ public String getName() { return name; } - protected void sendData(OutputStream out) - throws IOException { - log.trace("enter sendData(OutputStream out)"); + /** + * Write the data in "source" to the specified stream. + * @param out The output stream. + * @throws IOException if an IO problem occurs. + * @see org.apache.commons.httpclient.methods.multipart.Part#sendData(OutputStream) + */ + protected void sendData(OutputStream out) throws IOException { + LOG.trace("enter sendData(OutputStream out)"); byte[] buff; - if ( lengthOfData() == 0 ) { + if (lengthOfData() == 0) { // this file contains no data, so there is nothing to send. // we don't want to create a zero length buffer as this will // cause an infinite loop when reading. - log.debug("No data to send."); + LOG.debug("No data to send."); return; } else if (lengthOfData() > MAX_BUFF_SIZE) { @@ -199,9 +228,14 @@ } } - - protected long lengthOfData() - throws IOException { + + /** + * Return the length of the data. + * @return The length. + * @throws IOException if an IO problem occurs + * @see org.apache.commons.httpclient.methods.multipart.Part#lengthOfData() + */ + protected long lengthOfData() throws IOException { return source.getLength(); } Index: httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePartSource.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePartSource.java,v retrieving revision 1.5 diff -u -r1.5 FilePartSource.java --- httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePartSource.java 25 Jan 2003 00:59:11 -0000 1.5 +++ httpclient/src/java/org/apache/commons/httpclient/methods/multipart/FilePartSource.java 28 Jan 2003 20:28:50 -0000 @@ -73,6 +73,7 @@ * * @author Michael Becke * @author Mark Diggory + * @author Mike Bowler * * @since 2.0 */ @@ -94,11 +95,11 @@ */ public FilePartSource(File file) throws FileNotFoundException { - if (! file.isFile()) { + if (!file.isFile()) { throw new FileNotFoundException("File is not a normal file."); } - if (! file.canRead()) { + if (!file.canRead()) { throw new FileNotFoundException("File is not readable."); } @@ -118,11 +119,11 @@ public FilePartSource(String fileName, File file) throws FileNotFoundException { - if (! file.isFile()) { + if (!file.isFile()) { throw new FileNotFoundException("File is not a normal file."); } - if (! file.canRead()) { + if (!file.canRead()) { throw new FileNotFoundException("File is not readable."); } @@ -131,6 +132,8 @@ } /** + * Return the length of the file + * @return the length of the file. * @see PartSource#getLength() */ public long getLength() { @@ -138,6 +141,8 @@ } /** + * Return the current filename + * @return the filename. * @see PartSource#getFileName() */ public String getFileName() { @@ -145,6 +150,8 @@ } /** + * Return a new {@link FileInputStream} for the current filename. + * @return the new input stream. * @see PartSource#createInputStream() */ public InputStream createInputStream() throws IOException { Index: httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java,v retrieving revision 1.6 diff -u -r1.6 Part.java --- httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java 25 Jan 2003 00:59:11 -0000 1.6 +++ httpclient/src/java/org/apache/commons/httpclient/methods/multipart/Part.java 28 Jan 2003 20:28:51 -0000 @@ -75,38 +75,65 @@ * @author Matthew Albright * @author Jeff Dever * @author Adrian Sutton + * @author Mike Bowler * * @since 2.0 */ public abstract class Part { /** Log object for this class. */ - private static final Log log = LogFactory.getLog(Part.class); + private static final Log LOG = LogFactory.getLog(Part.class); //TODO: Make this configurable - static String boundary = "----------------314159265358979323846"; - static byte[] boundary_bytes = HttpConstants.getBytes(boundary); - static String CRLF = "\r\n"; - static byte[] CRLF_bytes = HttpConstants.getBytes(CRLF); - static String extra = "--"; - static byte[] extra_bytes = HttpConstants.getBytes(extra); + /** The boundary */ + private static final String BOUNDARY = "----------------314159265358979323846"; + + /** The boundary as a byte array */ + private static final byte[] BOUNDARY_BYTES = HttpConstants.getBytes(BOUNDARY); + + /** Carriage return/linefeed */ + private static final String CRLF = "\r\n"; + + /** Carriage return/linefeed as a byte array */ + protected static final byte[] CRLF_BYTES = HttpConstants.getBytes(CRLF); + + /** Extra characters */ + private static final String EXTRA = "--"; + + /** Extra characters as a byte array */ + private static final byte[] EXTRA_BYTES = HttpConstants.getBytes(EXTRA); + + /** + * Return the boundary string. + * @return the boundary string + */ public static String getBoundary() { - return boundary; + return BOUNDARY; } + /** + * Write the last boundary to the specified output stream + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ public static void sendLastBoundary(OutputStream out) throws IOException { - log.trace("enter sendLastBoundary(OutputStream out)"); - out.write(extra_bytes); - out.write(boundary_bytes); - out.write(extra_bytes); - out.write(CRLF_bytes); + LOG.trace("enter sendLastBoundary(OutputStream out)"); + out.write(EXTRA_BYTES); + out.write(BOUNDARY_BYTES); + out.write(EXTRA_BYTES); + out.write(CRLF_BYTES); } - public static int lengthOfLastBoundary() - throws IOException { - log.trace("enter lengthOfLastBoundary()"); + /** + * Return the length of the last boundary string + * + * @return int The length of the last boundary string + * @throws IOException If an IO problem occurs + */ + public static int lengthOfLastBoundary() throws IOException { + LOG.trace("enter lengthOfLastBoundary()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendLastBoundary(out); @@ -114,71 +141,121 @@ return out.size(); } + /** + * Return the name of this part. + * @return String The name. + */ public abstract String getName(); - protected void sendStart(OutputStream out) - throws IOException { - log.trace("enter sendStart(OutputStream out)"); - out.write(extra_bytes); - out.write(boundary_bytes); - out.write(CRLF_bytes); + /** + * Write the start to the specified output stream + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ + protected void sendStart(OutputStream out) throws IOException { + LOG.trace("enter sendStart(OutputStream out)"); + out.write(EXTRA_BYTES); + out.write(BOUNDARY_BYTES); + out.write(CRLF_BYTES); } - protected int lengthOfStart() - throws IOException { - log.trace("enter lengthOfStart()"); + /** + * Return the length of the starting data + * @return int The length of the data + * @throws IOException If an IO problem occurs + */ + protected int lengthOfStart() throws IOException { + LOG.trace("enter lengthOfStart()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendStart(out); return out.size(); } - protected void sendHeader(OutputStream out) - throws IOException { - log.trace("enter sendHeader(OutputStream out)"); - String content_dispos = "Content-Disposition: form-data; name=\"" + /** + * Write the header to the specified output stream + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ + protected void sendHeader(OutputStream out) throws IOException { + LOG.trace("enter sendHeader(OutputStream out)"); + String contentDisposition = "Content-Disposition: form-data; name=\"" + getName() + "\""; - out.write(HttpConstants.getBytes(content_dispos)); + out.write(HttpConstants.getBytes(contentDisposition)); } - protected int lengthOfHeader() - throws IOException { - log.trace("enter lengthOfHeader()"); + /** + * Return the length of the header + * + * @return long The length. + * @throws IOException If an IO problem occurs + */ + protected int lengthOfHeader() throws IOException { + LOG.trace("enter lengthOfHeader()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendHeader(out); - return(out.size()); + return (out.size()); } - protected void sendEndOfHeader(OutputStream out) - throws IOException { - log.trace("enter sendEndOfHeader(OutputStream out)"); - out.write(CRLF_bytes); - out.write(CRLF_bytes); + /** + * Write the end of the header to the output stream + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ + protected void sendEndOfHeader(OutputStream out) throws IOException { + LOG.trace("enter sendEndOfHeader(OutputStream out)"); + out.write(CRLF_BYTES); + out.write(CRLF_BYTES); } - protected int lengthOfEndOfHeader() - throws IOException { - log.trace("enter lengthOfEndOfHeader()"); + /** + * Return the length of the end of header + * + * @return long The length. + * @throws IOException If an IO problem occurs + */ + protected int lengthOfEndOfHeader() throws IOException { + LOG.trace("enter lengthOfEndOfHeader()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendEndOfHeader(out); return out.size(); } + /** + * Write the data to the specified output stream + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ protected abstract void sendData(OutputStream out) throws IOException; + /** + * Return the length of the main content + * + * @return long The length. + * @throws IOException If an IO problem occurs + */ protected abstract long lengthOfData() throws IOException; - protected void sendEnd(OutputStream out) - throws IOException { - log.trace("enter sendEnd(OutputStream out)"); - out.write(CRLF_bytes); + /** + * Write the end data to the output stream. + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ + protected void sendEnd(OutputStream out) throws IOException { + LOG.trace("enter sendEnd(OutputStream out)"); + out.write(CRLF_BYTES); } - protected int lengthOfEnd() - throws IOException { - log.trace("enter lengthOfEnd()"); + /** + * Return the length of the end data + * + * @return long The length. + * @throws IOException If an IO problem occurs + */ + protected int lengthOfEnd() throws IOException { + LOG.trace("enter lengthOfEnd()"); ByteArrayOutputStream out = new ByteArrayOutputStream(); sendEnd(out); return out.size(); @@ -189,8 +266,13 @@ * is to make sure they AREN'T overridden. */ + /** + * Write all the data to the output stream. + * @param out The output stream + * @throws IOException If an IO problem occurs. + */ public final void send(OutputStream out) throws IOException { - log.trace("enter send(OutputStream out)"); + LOG.trace("enter send(OutputStream out)"); sendStart(out); sendHeader(out); sendEndOfHeader(out); @@ -198,15 +280,26 @@ sendEnd(out); } + /** + * Return the full length of all the data. + * + * @return long The length. + * @throws IOException If an IO problem occurs + */ public final long length() throws IOException { - log.trace("enter length()"); + LOG.trace("enter length()"); return lengthOfStart() + lengthOfHeader() + lengthOfEndOfHeader() + lengthOfData() + lengthOfEnd(); } - + + /** + * Return a string representation of this object. + * @return A string representation of this object. + * @see java.lang.Object#toString() + */ public String toString() { return this.getName(); } Index: httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartSource.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartSource.java,v retrieving revision 1.3 diff -u -r1.3 PartSource.java --- httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartSource.java 25 Jan 2003 00:59:11 -0000 1.3 +++ httpclient/src/java/org/apache/commons/httpclient/methods/multipart/PartSource.java 28 Jan 2003 20:28:50 -0000 @@ -64,7 +64,6 @@ import java.io.IOException; import java.io.InputStream; -import org.apache.commons.httpclient.methods.MultipartPostMethod; /** * An interface for providing access to data when posting MultiPart messages. Index: httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java,v retrieving revision 1.4 diff -u -r1.4 StringPart.java --- httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java 25 Jan 2003 00:59:11 -0000 1.4 +++ httpclient/src/java/org/apache/commons/httpclient/methods/multipart/StringPart.java 28 Jan 2003 20:28:51 -0000 @@ -71,6 +71,7 @@ * * @author Matthew Albright * @author Jeff Dever + * @author Mike Bowler * * @since 2.0 */ @@ -85,7 +86,7 @@ /** * Constructor. * - * @param name + * @param name The name of the part * @param value the string to post */ public StringPart(String name, String value) { @@ -94,19 +95,30 @@ } /** + * Return the name of this part. * @return the name of this StringPart. */ public String getName() { return name; } - protected void sendData(OutputStream out) - throws IOException { + /** + * Write the data to the specified output stream + * @param out The output stream. + * @throws IOException If an IO problem occurs + * @see org.apache.commons.httpclient.methods.multipart.Part#sendData(OutputStream) + */ + protected void sendData(OutputStream out) throws IOException { out.write(HttpConstants.getBytes(value)); } - protected long lengthOfData() - throws IOException { + /** + * Return the length of the data. + * @return The length of the data. + * @throws IOException If an IO problem occurs + * @see org.apache.commons.httpclient.methods.multipart.Part#lengthOfData() + */ + protected long lengthOfData() throws IOException { return HttpConstants.getBytes(value).length; } }