diff options
Diffstat (limited to 'libjava/classpath/gnu/java/net/protocol/http')
6 files changed, 58 insertions, 63 deletions
diff --git a/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java b/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java index 9870412f2da..8abef71d521 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java +++ b/libjava/classpath/gnu/java/net/protocol/http/ChunkedInputStream.java @@ -58,10 +58,6 @@ import java.net.ProtocolException; public class ChunkedInputStream extends InputStream { - - private static final byte CR = 0x0d; - private static final byte LF = 0x0a; - Headers headers; /** The underlying stream. */ diff --git a/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java b/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java index 3956d2aba3a..9d19bfbdba4 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java +++ b/libjava/classpath/gnu/java/net/protocol/http/HTTPConnection.java @@ -129,7 +129,7 @@ public class HTTPConnection */ protected int minorVersion; - private final List handshakeCompletedListeners; + private final List<HandshakeCompletedListener> handshakeCompletedListeners; /** * The socket this connection communicates on. @@ -154,7 +154,7 @@ public class HTTPConnection /** * Nonce values seen by this connection. */ - private Map nonceCounts; + private Map<String, Integer> nonceCounts; /** * The cookie manager for this connection. @@ -244,7 +244,8 @@ public class HTTPConnection this.connectionTimeout = connectionTimeout; this.timeout = timeout; majorVersion = minorVersion = 1; - handshakeCompletedListeners = new ArrayList(2); + handshakeCompletedListeners + = new ArrayList<HandshakeCompletedListener>(2); } /** @@ -357,7 +358,8 @@ public class HTTPConnection /** * The pool */ - final LinkedList connectionPool = new LinkedList(); + final LinkedList<HTTPConnection> connectionPool + = new LinkedList<HTTPConnection>(); /** * Maximum size of the pool. @@ -857,7 +859,7 @@ public class HTTPConnection { return 0; } - return((Integer) nonceCounts.get(nonce)).intValue(); + return nonceCounts.get(nonce).intValue(); } /** @@ -868,7 +870,7 @@ public class HTTPConnection int current = getNonceCount(nonce); if (nonceCounts == null) { - nonceCounts = new HashMap(); + nonceCounts = new HashMap<String, Integer>(); } nonceCounts.put(nonce, new Integer(current + 1)); } diff --git a/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java b/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java index 6c926b72fb4..b31f426695f 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java +++ b/libjava/classpath/gnu/java/net/protocol/http/HTTPURLConnection.java @@ -50,11 +50,11 @@ import java.net.URL; import java.security.cert.Certificate; import java.util.Collections; import java.util.Date; +import java.util.List; import java.util.Map; import javax.net.ssl.HandshakeCompletedEvent; import javax.net.ssl.HandshakeCompletedListener; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLSocketFactory; @@ -170,7 +170,8 @@ public class HTTPURLConnection if (secure) { SSLSocketFactory factory = getSSLSocketFactory(); - HostnameVerifier verifier = getHostnameVerifier(); + // FIXME: use the verifier + // HostnameVerifier verifier = getHostnameVerifier(); if (factory != null) { connection.setSSLSocketFactory(factory); @@ -428,12 +429,12 @@ public class HTTPURLConnection return requestHeaders.getValue(key); } - public Map getRequestProperties() + public Map<String, List<String>> getRequestProperties() { if (connected) throw new IllegalStateException("Already connected"); - Map m = requestHeaders.getAsMap(); + Map<String, List<String>> m = requestHeaders.getAsMap(); return Collections.unmodifiableMap(m); } @@ -509,7 +510,7 @@ public class HTTPURLConnection return errorSink; } - public Map getHeaderFields() + public Map<String,List<String>> getHeaderFields() { if (!connected) { @@ -522,7 +523,7 @@ public class HTTPURLConnection return null; } } - Map m = response.getHeaders().getAsMap(); + Map<String,List<String>> m = response.getHeaders().getAsMap(); m.put(null, Collections.singletonList(getStatusLine(response))); return Collections.unmodifiableMap(m); } diff --git a/libjava/classpath/gnu/java/net/protocol/http/Headers.java b/libjava/classpath/gnu/java/net/protocol/http/Headers.java index a793bbd9728..c8736bbac8f 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/Headers.java +++ b/libjava/classpath/gnu/java/net/protocol/http/Headers.java @@ -42,6 +42,7 @@ import gnu.java.net.LineInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.Iterable; import java.text.DateFormat; import java.text.ParseException; import java.util.ArrayList; @@ -49,6 +50,7 @@ import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; /** @@ -60,12 +62,13 @@ import java.util.Map; * @author Chris Burdess (dog@gnu.org) * @author David Daney (ddaney@avtrex.com) */ -class Headers +class Headers implements Iterable<Headers.HeaderElement> { /** * A list of HeaderElements */ - private final ArrayList headers = new ArrayList(); + private final ArrayList<HeaderElement> headers + = new ArrayList<HeaderElement>(); /** * The HTTP dateformat used to parse date header fields. @@ -102,7 +105,7 @@ class Headers * * @return the Iterator. */ - Iterator iterator() + public Iterator<HeaderElement> iterator() { return headers.iterator(); } @@ -118,7 +121,7 @@ class Headers { for (int i = headers.size() - 1; i >= 0; i--) { - HeaderElement e = (HeaderElement)headers.get(i); + HeaderElement e = headers.get(i); if (e.name.equalsIgnoreCase(header)) { return e.value; @@ -219,7 +222,7 @@ class Headers { for (int i = headers.size() - 1; i >= 0; i--) { - HeaderElement e = (HeaderElement)headers.get(i); + HeaderElement e = headers.get(i); if (e.name.equalsIgnoreCase(name)) { e.value = value; @@ -240,9 +243,9 @@ class Headers */ public void putAll(Headers o) { - for (Iterator it = o.iterator(); it.hasNext(); ) + for (Iterator<HeaderElement> it = o.iterator(); it.hasNext(); ) { - HeaderElement e = (HeaderElement)it.next(); + HeaderElement e = it.next(); remove(e.name); addValue(e.name, e.value); } @@ -256,9 +259,9 @@ class Headers */ public void remove(String name) { - for (Iterator it = headers.iterator(); it.hasNext(); ) + for (Iterator<HeaderElement> it = headers.iterator(); it.hasNext(); ) { - HeaderElement e = (HeaderElement)it.next(); + HeaderElement e = it.next(); if (e.name.equalsIgnoreCase(name)) it.remove(); } @@ -358,26 +361,26 @@ class Headers * * @return a Map containing all the headers. */ - public Map getAsMap() + public Map<String,List<String>> getAsMap() { - LinkedHashMap m = new LinkedHashMap(); - for (Iterator it = headers.iterator(); it.hasNext(); ) + LinkedHashMap<String,List<String>> m = new LinkedHashMap<String,List<String>>(); + for (Iterator<HeaderElement> it = headers.iterator(); it.hasNext(); ) { - HeaderElement e = (HeaderElement)it.next(); - ArrayList l = (ArrayList)m.get(e.name); + HeaderElement e = it.next(); + ArrayList<String> l = (ArrayList<String>)m.get(e.name); if (l == null) { - l = new ArrayList(1); + l = new ArrayList<String>(1); l.add(e.value); m.put(e.name, l); } else l.add(0, e.value); } - for (Iterator it = m.entrySet().iterator(); it.hasNext(); ) + for (Iterator<Map.Entry<String,List<String>>> it = m.entrySet().iterator(); it.hasNext(); ) { - Map.Entry me = (Map.Entry)it.next(); - ArrayList l = (ArrayList)me.getValue(); + Map.Entry<String,List<String>> me = it.next(); + List<String> l = me.getValue(); me.setValue(Collections.unmodifiableList(l)); } return m; @@ -397,7 +400,7 @@ class Headers if (i >= headers.size() || i < 0) return null; - return ((HeaderElement)headers.get(i)).name; + return headers.get(i).name; } /** @@ -414,8 +417,6 @@ class Headers if (i >= headers.size() || i < 0) return null; - return ((HeaderElement)headers.get(i)).value; + return headers.get(i).value; } - } - diff --git a/libjava/classpath/gnu/java/net/protocol/http/Request.java b/libjava/classpath/gnu/java/net/protocol/http/Request.java index cd9d7ea4423..06a779f3311 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/Request.java +++ b/libjava/classpath/gnu/java/net/protocol/http/Request.java @@ -1,5 +1,5 @@ /* Request.java -- - Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,8 +38,8 @@ exception statement from your version. */ package gnu.java.net.protocol.http; -import gnu.java.net.BASE64; import gnu.java.net.LineInputStream; +import gnu.java.util.Base64; import java.io.IOException; import java.io.InputStream; @@ -96,7 +96,7 @@ public class Request /** * Map of response header handlers. */ - protected Map responseHeaderHandlers; + protected Map<String, ResponseHeaderHandler> responseHeaderHandlers; /** * The authenticator. @@ -121,7 +121,7 @@ public class Request this.method = method; this.path = path; requestHeaders = new Headers(); - responseHeaderHandlers = new HashMap(); + responseHeaderHandlers = new HashMap<String, ResponseHeaderHandler>(); } /** @@ -302,9 +302,8 @@ public class Request String line = method + ' ' + requestUri + ' ' + version + CRLF; out.write(line.getBytes(US_ASCII)); // Request headers - for (Iterator i = requestHeaders.iterator(); i.hasNext(); ) + for (Headers.HeaderElement elt : requestHeaders) { - Headers.HeaderElement elt = (Headers.HeaderElement)i.next(); line = elt.name + HEADER_SEP + elt.value + CRLF; out.write(line.getBytes(US_ASCII)); } @@ -439,9 +438,8 @@ public class Request void notifyHeaderHandlers(Headers headers) { - for (Iterator i = headers.iterator(); i.hasNext(); ) + for (Headers.HeaderElement entry : headers) { - Headers.HeaderElement entry = (Headers.HeaderElement) i.next(); // Handle Set-Cookie if ("Set-Cookie".equalsIgnoreCase(entry.name)) handleSetCookie(entry.value); @@ -461,7 +459,6 @@ public class Request throws IOException { long contentLength = -1; - Headers trailer = null; // Persistent connections are the default in HTTP/1.1 boolean doClose = "close".equalsIgnoreCase(getHeader("Connection")) || @@ -532,7 +529,7 @@ public class Request Credentials creds = authenticator.getCredentials(realm, attempts); String userPass = creds.getUsername() + ':' + creds.getPassword(); byte[] b_userPass = userPass.getBytes("US-ASCII"); - byte[] b_encoded = BASE64.encode(b_userPass); + byte[] b_encoded = Base64.encode(b_userPass).getBytes("US-ASCII"); String authorization = scheme + " " + new String(b_encoded, "US-ASCII"); setHeader("Authorization", authorization); diff --git a/libjava/classpath/gnu/java/net/protocol/http/SimpleCookieManager.java b/libjava/classpath/gnu/java/net/protocol/http/SimpleCookieManager.java index 8947471885c..fe05ba09e5e 100644 --- a/libjava/classpath/gnu/java/net/protocol/http/SimpleCookieManager.java +++ b/libjava/classpath/gnu/java/net/protocol/http/SimpleCookieManager.java @@ -1,5 +1,5 @@ /* CookieManager.java -- - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,7 +42,6 @@ import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; -import java.util.List; import java.util.Map; /** @@ -59,23 +58,23 @@ public class SimpleCookieManager * The cookie cache. * This is a dictionary mapping domains to maps of cookies by name. */ - protected Map cookies; + protected Map<String, Map<String, Cookie>> cookies; /** * Constructor. */ public SimpleCookieManager() { - cookies = new HashMap(); + cookies = new HashMap<String, Map<String, Cookie>>(); } public void setCookie(Cookie cookie) { String domain = cookie.getDomain(); - Map map =(Map) cookies.get(domain); + Map<String, Cookie> map = cookies.get(domain); if (map == null) { - map = new HashMap(); + map = new HashMap<String, Cookie>(); cookies.put(domain, map); } String name = cookie.getName(); @@ -84,7 +83,7 @@ public class SimpleCookieManager public Cookie[] getCookies(String host, boolean secure, String path) { - List matches = new ArrayList(); + ArrayList<Cookie> matches = new ArrayList<Cookie>(); Date now = new Date(); if (Character.isLetter(host.charAt(0))) { @@ -102,17 +101,16 @@ public class SimpleCookieManager return ret; } - private void addCookies(List matches, String domain, boolean secure, - String path, Date now) + private void addCookies(ArrayList<Cookie> matches, String domain, + boolean secure, String path, Date now) { - Map map = (Map) cookies.get(domain); + Map<String, Cookie> map = cookies.get(domain); if (map != null) { - List expired = new ArrayList(); - for (Iterator i = map.entrySet().iterator(); i.hasNext(); ) + ArrayList<String> expired = new ArrayList<String>(); + for (Map.Entry<String, Cookie> entry : map.entrySet()) { - Map.Entry entry = (Map.Entry) i.next(); - Cookie cookie = (Cookie) entry.getValue(); + Cookie cookie = entry.getValue(); Date expires = cookie.getExpiryDate(); if (expires != null && expires.before(now)) { @@ -129,7 +127,7 @@ public class SimpleCookieManager } } // Good housekeeping - for (Iterator i = expired.iterator(); i.hasNext(); ) + for (Iterator<String> i = expired.iterator(); i.hasNext(); ) { map.remove(i.next()); } |

