提交 54fce0c8 编写于 作者: K kevinw

Merge

...@@ -24,14 +24,12 @@ ...@@ -24,14 +24,12 @@
*/ */
package sun.net.www.http; package sun.net.www.http;
import java.io.*; import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.net.NetProperties;
import java.util.regex.*; import java.util.regex.*;
import sun.net.NetProperties;
import sun.util.logging.PlatformLogger;
/** /**
* Main class of the HTTP traffic capture tool. * Main class of the HTTP traffic capture tool.
...@@ -62,76 +60,6 @@ public class HttpCapture { ...@@ -62,76 +60,6 @@ public class HttpCapture {
private static boolean initialized = false; private static boolean initialized = false;
private static volatile ArrayList<Pattern> patterns = null; private static volatile ArrayList<Pattern> patterns = null;
private static volatile ArrayList<String> capFiles = null; private static volatile ArrayList<String> capFiles = null;
/* Logging is done in an ugly way so that it does not require the presence
* the java.util.logging package. If the Logger class is not available, then
* logging is turned off. This is for helping the modularization effort.
*/
private static Object logger = null;
private static boolean logging = false;
static {
Class cl;
try {
cl = Class.forName("java.util.logging.Logger");
} catch (ClassNotFoundException ex) {
cl = null;
}
if (cl != null) {
try {
Method m = cl.getMethod("getLogger", String.class);
logger = m.invoke(null, "sun.net.www.protocol.http.HttpURLConnection");
logging = true;
} catch (NoSuchMethodException noSuchMethodException) {
} catch (SecurityException securityException) {
} catch (IllegalAccessException illegalAccessException) {
} catch (IllegalArgumentException illegalArgumentException) {
} catch (InvocationTargetException invocationTargetException) {
}
}
}
public static void fine(String s) {
if (logging) {
((Logger)logger).fine(s);
}
}
public static void finer(String s) {
if (logging) {
((Logger)logger).finer(s);
}
}
public static void finest(String s) {
if (logging) {
((Logger)logger).finest(s);
}
}
public static void severe(String s) {
if (logging) {
((Logger)logger).finest(s);
}
}
public static void info(String s) {
if (logging) {
((Logger)logger).info(s);
}
}
public static void warning(String s) {
if (logging) {
((Logger)logger).warning(s);
}
}
public static boolean isLoggable(String level) {
if (!logging) {
return false;
}
return ((Logger)logger).isLoggable(Level.parse(level));
}
private static synchronized void init() { private static synchronized void init() {
initialized = true; initialized = true;
...@@ -187,7 +115,7 @@ public class HttpCapture { ...@@ -187,7 +115,7 @@ public class HttpCapture {
out = new BufferedWriter(new FileWriter(file, true)); out = new BufferedWriter(new FileWriter(file, true));
out.write("URL: " + url + "\n"); out.write("URL: " + url + "\n");
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(HttpCapture.class.getName()).log(Level.SEVERE, null, ex); PlatformLogger.getLogger(HttpCapture.class.getName()).severe(null, ex);
} }
} }
......
...@@ -35,6 +35,7 @@ import sun.net.www.HeaderParser; ...@@ -35,6 +35,7 @@ import sun.net.www.HeaderParser;
import sun.net.www.MeteredStream; import sun.net.www.MeteredStream;
import sun.net.www.ParseUtil; import sun.net.www.ParseUtil;
import sun.net.www.protocol.http.HttpURLConnection; import sun.net.www.protocol.http.HttpURLConnection;
import sun.util.logging.PlatformLogger;
/** /**
* @author Herb Jellinek * @author Herb Jellinek
...@@ -804,8 +805,9 @@ public class HttpClient extends NetworkClient { ...@@ -804,8 +805,9 @@ public class HttpClient extends NetworkClient {
if (isKeepingAlive()) { if (isKeepingAlive()) {
// Wrap KeepAliveStream if keep alive is enabled. // Wrap KeepAliveStream if keep alive is enabled.
if (HttpCapture.isLoggable("FINEST")) { PlatformLogger logger = HttpURLConnection.getHttpLogger();
HttpCapture.finest("KeepAlive stream used: " + url); if (logger.isLoggable(PlatformLogger.FINEST)) {
logger.finest("KeepAlive stream used: " + url);
} }
serverInput = new KeepAliveStream(serverInput, pi, cl, this); serverInput = new KeepAliveStream(serverInput, pi, cl, this);
failedOnce = false; failedOnce = false;
......
...@@ -25,12 +25,11 @@ ...@@ -25,12 +25,11 @@
package sun.net.www.http; package sun.net.www.http;
import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.NotSerializableException; import java.io.NotSerializableException;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.net.URL; import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
/** /**
* A class that implements a cache of idle Http connections for keep-alive * A class that implements a cache of idle Http connections for keep-alive
...@@ -39,7 +38,7 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -39,7 +38,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @author Dave Brown * @author Dave Brown
*/ */
public class KeepAliveCache public class KeepAliveCache
extends ConcurrentHashMap<KeepAliveKey, ClientVector> extends HashMap<KeepAliveKey, ClientVector>
implements Runnable { implements Runnable {
private static final long serialVersionUID = -2937172892064557949L; private static final long serialVersionUID = -2937172892064557949L;
...@@ -163,8 +162,8 @@ public class KeepAliveCache ...@@ -163,8 +162,8 @@ public class KeepAliveCache
* Errs on the side of caution (leave connections idle for a relatively * Errs on the side of caution (leave connections idle for a relatively
* short time). * short time).
*/ */
@Override
public void run() { public void run() {
int total_cache;
do { do {
try { try {
Thread.sleep(LIFETIME); Thread.sleep(LIFETIME);
...@@ -311,6 +310,7 @@ class KeepAliveKey { ...@@ -311,6 +310,7 @@ class KeepAliveKey {
/** /**
* Determine whether or not two objects of this type are equal * Determine whether or not two objects of this type are equal
*/ */
@Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if ((obj instanceof KeepAliveKey) == false) if ((obj instanceof KeepAliveKey) == false)
return false; return false;
...@@ -325,6 +325,7 @@ class KeepAliveKey { ...@@ -325,6 +325,7 @@ class KeepAliveKey {
* The hashCode() for this object is the string hashCode() of * The hashCode() for this object is the string hashCode() of
* concatenation of the protocol, host name and port. * concatenation of the protocol, host name and port.
*/ */
@Override
public int hashCode() { public int hashCode() {
String str = protocol+host+port; String str = protocol+host+port;
return this.obj == null? str.hashCode() : return this.obj == null? str.hashCode() :
......
...@@ -25,10 +25,7 @@ ...@@ -25,10 +25,7 @@
package sun.net.www.http; package sun.net.www.http;
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.*; import java.io.*;
import java.util.StringTokenizer;
import sun.net.ProgressSource; import sun.net.ProgressSource;
import sun.net.www.MeteredStream; import sun.net.www.MeteredStream;
...@@ -50,9 +47,8 @@ class KeepAliveStream extends MeteredStream implements Hurryable { ...@@ -50,9 +47,8 @@ class KeepAliveStream extends MeteredStream implements Hurryable {
// has this KeepAliveStream been put on the queue for asynchronous cleanup. // has this KeepAliveStream been put on the queue for asynchronous cleanup.
protected boolean queuedForCleanup = false; protected boolean queuedForCleanup = false;
private static KeepAliveStreamCleaner queue = new KeepAliveStreamCleaner(); private static final KeepAliveStreamCleaner queue = new KeepAliveStreamCleaner();
private static Thread cleanerThread = null; private static Thread cleanerThread; // null
private static boolean startCleanupThread;
/** /**
* Constructor * Constructor
...@@ -155,43 +151,46 @@ class KeepAliveStream extends MeteredStream implements Hurryable { ...@@ -155,43 +151,46 @@ class KeepAliveStream extends MeteredStream implements Hurryable {
} }
} }
private static synchronized void queueForCleanup(KeepAliveCleanerEntry kace) { private static void queueForCleanup(KeepAliveCleanerEntry kace) {
if(queue != null && !kace.getQueuedForCleanup()) { synchronized(queue) {
if (!queue.offer(kace)) { if(!kace.getQueuedForCleanup()) {
kace.getHttpClient().closeServer(); if (!queue.offer(kace)) {
return; kace.getHttpClient().closeServer();
} return;
}
kace.setQueuedForCleanup(); kace.setQueuedForCleanup();
} queue.notifyAll();
}
startCleanupThread = (cleanerThread == null); boolean startCleanupThread = (cleanerThread == null);
if (!startCleanupThread) { if (!startCleanupThread) {
if (!cleanerThread.isAlive()) { if (!cleanerThread.isAlive()) {
startCleanupThread = true; startCleanupThread = true;
}
} }
}
if (startCleanupThread) { if (startCleanupThread) {
java.security.AccessController.doPrivileged( java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() { new java.security.PrivilegedAction<Void>() {
public Void run() { public Void run() {
// We want to create the Keep-Alive-SocketCleaner in the // We want to create the Keep-Alive-SocketCleaner in the
// system threadgroup // system threadgroup
ThreadGroup grp = Thread.currentThread().getThreadGroup(); ThreadGroup grp = Thread.currentThread().getThreadGroup();
ThreadGroup parent = null; ThreadGroup parent = null;
while ((parent = grp.getParent()) != null) { while ((parent = grp.getParent()) != null) {
grp = parent; grp = parent;
}
cleanerThread = new Thread(grp, queue, "Keep-Alive-SocketCleaner");
cleanerThread.setDaemon(true);
cleanerThread.setPriority(Thread.MAX_PRIORITY - 2);
cleanerThread.start();
return null;
} }
});
cleanerThread = new Thread(grp, queue, "Keep-Alive-SocketCleaner"); }
cleanerThread.setDaemon(true); } // queue
cleanerThread.setPriority(Thread.MAX_PRIORITY - 2);
cleanerThread.start();
return null;
}
});
}
} }
protected long remainingToRead() { protected long remainingToRead() {
......
...@@ -25,9 +25,8 @@ ...@@ -25,9 +25,8 @@
package sun.net.www.http; package sun.net.www.http;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedList;
import sun.net.NetProperties; import sun.net.NetProperties;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
...@@ -44,7 +43,9 @@ import java.security.PrivilegedAction; ...@@ -44,7 +43,9 @@ import java.security.PrivilegedAction;
*/ */
@SuppressWarnings("serial") // never serialized @SuppressWarnings("serial") // never serialized
public class KeepAliveStreamCleaner extends LinkedBlockingQueue<KeepAliveCleanerEntry> implements Runnable class KeepAliveStreamCleaner
extends LinkedList<KeepAliveCleanerEntry>
implements Runnable
{ {
// maximum amount of remaining data that we will try to cleanup // maximum amount of remaining data that we will try to cleanup
protected static int MAX_DATA_REMAINING = 512; protected static int MAX_DATA_REMAINING = 512;
...@@ -78,23 +79,39 @@ public class KeepAliveStreamCleaner extends LinkedBlockingQueue<KeepAliveCleaner ...@@ -78,23 +79,39 @@ public class KeepAliveStreamCleaner extends LinkedBlockingQueue<KeepAliveCleaner
} }
public KeepAliveStreamCleaner() @Override
{ public boolean offer(KeepAliveCleanerEntry e) {
super(MAX_CAPACITY); if (size() >= MAX_CAPACITY)
} return false;
public KeepAliveStreamCleaner(int capacity) return super.offer(e);
{
super(capacity);
} }
@Override
public void run() public void run()
{ {
KeepAliveCleanerEntry kace = null; KeepAliveCleanerEntry kace = null;
do { do {
try { try {
kace = poll((long)TIMEOUT, TimeUnit.MILLISECONDS); synchronized(this) {
long before = System.currentTimeMillis();
long timeout = TIMEOUT;
while ((kace = poll()) == null) {
this.wait(timeout);
long after = System.currentTimeMillis();
long elapsed = after - before;
if (elapsed > timeout) {
/* one last try */
kace = poll();
break;
}
before = after;
timeout -= elapsed;
}
}
if(kace == null) if(kace == null)
break; break;
......
...@@ -49,8 +49,10 @@ public class HttpLogFormatter extends java.util.logging.SimpleFormatter { ...@@ -49,8 +49,10 @@ public class HttpLogFormatter extends java.util.logging.SimpleFormatter {
@Override @Override
public String format(LogRecord record) { public String format(LogRecord record) {
if (!"sun.net.www.http.HttpCapture".equalsIgnoreCase(record.getSourceClassName())) { String sourceClassName = record.getSourceClassName();
// Don't change format for stuff that doesn't concern us if (sourceClassName == null ||
!(sourceClassName.startsWith("sun.net.www.protocol.http") ||
sourceClassName.startsWith("sun.net.www.http"))) {
return super.format(record); return super.format(record);
} }
String src = record.getMessage(); String src = record.getMessage();
......
...@@ -57,7 +57,7 @@ import sun.net.www.http.HttpClient; ...@@ -57,7 +57,7 @@ import sun.net.www.http.HttpClient;
import sun.net.www.http.PosterOutputStream; import sun.net.www.http.PosterOutputStream;
import sun.net.www.http.ChunkedInputStream; import sun.net.www.http.ChunkedInputStream;
import sun.net.www.http.ChunkedOutputStream; import sun.net.www.http.ChunkedOutputStream;
import sun.net.www.http.HttpCapture; import sun.util.logging.PlatformLogger;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.TimeZone; import java.util.TimeZone;
import java.net.MalformedURLException; import java.net.MalformedURLException;
...@@ -292,6 +292,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -292,6 +292,10 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
private int connectTimeout = -1; private int connectTimeout = -1;
private int readTimeout = -1; private int readTimeout = -1;
/* Logging support */
private static final PlatformLogger logger =
PlatformLogger.getLogger("sun.net.www.protocol.http.HttpURLConnection");
/* /*
* privileged request password authentication * privileged request password authentication
* *
...@@ -309,20 +313,25 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -309,20 +313,25 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
return java.security.AccessController.doPrivileged( return java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<PasswordAuthentication>() { new java.security.PrivilegedAction<PasswordAuthentication>() {
public PasswordAuthentication run() { public PasswordAuthentication run() {
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
HttpCapture.finest("Requesting Authentication: host =" + host + " url = " + url); logger.finest("Requesting Authentication: host =" + host + " url = " + url);
} }
PasswordAuthentication pass = Authenticator.requestPasswordAuthentication( PasswordAuthentication pass = Authenticator.requestPasswordAuthentication(
host, addr, port, protocol, host, addr, port, protocol,
prompt, scheme, url, authType); prompt, scheme, url, authType);
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
HttpCapture.finest("Authentication returned: " + (pass != null ? pass.toString() : "null")); logger.finest("Authentication returned: " + (pass != null ? pass.toString() : "null"));
} }
return pass; return pass;
} }
}); });
} }
/* Logging support */
public static PlatformLogger getHttpLogger() {
return logger;
}
/* /*
* checks the validity of http message header and throws * checks the validity of http message header and throws
* IllegalArgumentException if invalid. * IllegalArgumentException if invalid.
...@@ -471,8 +480,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -471,8 +480,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
setRequests=true; setRequests=true;
} }
if (HttpCapture.isLoggable("FINE")) { if (logger.isLoggable(PlatformLogger.FINE)) {
HttpCapture.fine(requests.toString()); logger.fine(requests.toString());
} }
http.writeRequests(requests, poster); http.writeRequests(requests, poster);
if (ps.checkError()) { if (ps.checkError()) {
...@@ -736,9 +745,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -736,9 +745,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
&& !(cachedResponse instanceof SecureCacheResponse)) { && !(cachedResponse instanceof SecureCacheResponse)) {
cachedResponse = null; cachedResponse = null;
} }
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
HttpCapture.finest("Cache Request for " + uri + " / " + getRequestMethod()); logger.finest("Cache Request for " + uri + " / " + getRequestMethod());
HttpCapture.finest("From cache: " + (cachedResponse != null ? cachedResponse.toString() : "null")); logger.finest("From cache: " + (cachedResponse != null ? cachedResponse.toString() : "null"));
} }
if (cachedResponse != null) { if (cachedResponse != null) {
cachedHeaders = mapToMessageHeader(cachedResponse.getHeaders()); cachedHeaders = mapToMessageHeader(cachedResponse.getHeaders());
...@@ -777,8 +786,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -777,8 +786,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
}); });
if (sel != null) { if (sel != null) {
URI uri = sun.net.www.ParseUtil.toURI(url); URI uri = sun.net.www.ParseUtil.toURI(url);
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
HttpCapture.finest("ProxySelector Request for " + uri); logger.finest("ProxySelector Request for " + uri);
} }
Iterator<Proxy> it = sel.select(uri).iterator(); Iterator<Proxy> it = sel.select(uri).iterator();
Proxy p; Proxy p;
...@@ -794,9 +803,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -794,9 +803,9 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
http = getNewHttpClient(url, p, connectTimeout, false); http = getNewHttpClient(url, p, connectTimeout, false);
http.setReadTimeout(readTimeout); http.setReadTimeout(readTimeout);
} }
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
if (p != null) { if (p != null) {
HttpCapture.finest("Proxy used: " + p.toString()); logger.finest("Proxy used: " + p.toString());
} }
} }
break; break;
...@@ -1026,15 +1035,15 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1026,15 +1035,15 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
URI uri = ParseUtil.toURI(url); URI uri = ParseUtil.toURI(url);
if (uri != null) { if (uri != null) {
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
HttpCapture.finest("CookieHandler request for " + uri); logger.finest("CookieHandler request for " + uri);
} }
Map<String, List<String>> cookies Map<String, List<String>> cookies
= cookieHandler.get( = cookieHandler.get(
uri, requests.getHeaders(EXCLUDE_HEADERS)); uri, requests.getHeaders(EXCLUDE_HEADERS));
if (!cookies.isEmpty()) { if (!cookies.isEmpty()) {
if (HttpCapture.isLoggable("FINEST")) { if (logger.isLoggable(PlatformLogger.FINEST)) {
HttpCapture.finest("Cookies retrieved: " + cookies.toString()); logger.finest("Cookies retrieved: " + cookies.toString());
} }
for (Map.Entry<String, List<String>> entry : for (Map.Entry<String, List<String>> entry :
cookies.entrySet()) { cookies.entrySet()) {
...@@ -1165,8 +1174,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1165,8 +1174,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
writeRequests(); writeRequests();
} }
http.parseHTTP(responses, pi, this); http.parseHTTP(responses, pi, this);
if (HttpCapture.isLoggable("FINE")) { if (logger.isLoggable(PlatformLogger.FINE)) {
HttpCapture.fine(responses.toString()); logger.fine(responses.toString());
} }
inputStream = http.getInputStream(); inputStream = http.getInputStream();
...@@ -1610,8 +1619,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1610,8 +1619,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
http.parseHTTP(responses, null, this); http.parseHTTP(responses, null, this);
/* Log the response to the CONNECT */ /* Log the response to the CONNECT */
if (HttpCapture.isLoggable("FINE")) { if (logger.isLoggable(PlatformLogger.FINE)) {
HttpCapture.fine(responses.toString()); logger.fine(responses.toString());
} }
statusLine = responses.getValue(0); statusLine = responses.getValue(0);
...@@ -1738,8 +1747,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1738,8 +1747,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
setPreemptiveProxyAuthentication(requests); setPreemptiveProxyAuthentication(requests);
/* Log the CONNECT request */ /* Log the CONNECT request */
if (HttpCapture.isLoggable("FINE")) { if (logger.isLoggable(PlatformLogger.FINE)) {
HttpCapture.fine(requests.toString()); logger.fine(requests.toString());
} }
http.writeRequests(requests, null); http.writeRequests(requests, null);
...@@ -1852,7 +1861,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1852,7 +1861,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} }
a = null; a = null;
if (tryTransparentNTLMProxy) { if (tryTransparentNTLMProxy) {
HttpCapture.finest("Trying Transparent NTLM authentication"); logger.finest("Trying Transparent NTLM authentication");
} else { } else {
a = privilegedRequestPasswordAuthentication( a = privilegedRequestPasswordAuthentication(
host, null, port, url.getProtocol(), host, null, port, url.getProtocol(),
...@@ -1880,7 +1889,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1880,7 +1889,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
ret = new NegotiateAuthentication(new HttpCallerInfo(authhdr.getHttpCallerInfo(), "Kerberos")); ret = new NegotiateAuthentication(new HttpCallerInfo(authhdr.getHttpCallerInfo(), "Kerberos"));
break; break;
case UNKNOWN: case UNKNOWN:
HttpCapture.finest("Unknown/Unsupported authentication scheme: " + scheme); logger.finest("Unknown/Unsupported authentication scheme: " + scheme);
default: default:
throw new AssertionError("should not reach here"); throw new AssertionError("should not reach here");
} }
...@@ -1906,8 +1915,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -1906,8 +1915,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} }
} }
} }
if (HttpCapture.isLoggable("FINER")) { if (logger.isLoggable(PlatformLogger.FINER)) {
HttpCapture.finer("Proxy Authentication for " + authhdr.toString() +" returned " + (ret != null ? ret.toString() : "null")); logger.finer("Proxy Authentication for " + authhdr.toString() +" returned " + (ret != null ? ret.toString() : "null"));
} }
return ret; return ret;
} }
...@@ -2004,7 +2013,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -2004,7 +2013,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} }
a = null; a = null;
if (tryTransparentNTLMServer) { if (tryTransparentNTLMServer) {
HttpCapture.finest("Trying Transparent NTLM authentication"); logger.finest("Trying Transparent NTLM authentication");
} else { } else {
a = privilegedRequestPasswordAuthentication( a = privilegedRequestPasswordAuthentication(
url.getHost(), addr, port, url.getProtocol(), url.getHost(), addr, port, url.getProtocol(),
...@@ -2027,7 +2036,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -2027,7 +2036,7 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} }
break; break;
case UNKNOWN: case UNKNOWN:
HttpCapture.finest("Unknown/Unsupported authentication scheme: " + scheme); logger.finest("Unknown/Unsupported authentication scheme: " + scheme);
default: default:
throw new AssertionError("should not reach here"); throw new AssertionError("should not reach here");
} }
...@@ -2051,8 +2060,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -2051,8 +2060,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
} }
} }
} }
if (HttpCapture.isLoggable("FINER")) { if (logger.isLoggable(PlatformLogger.FINER)) {
HttpCapture.finer("Server Authentication for " + authhdr.toString() +" returned " + (ret != null ? ret.toString() : "null")); logger.finer("Server Authentication for " + authhdr.toString() +" returned " + (ret != null ? ret.toString() : "null"));
} }
return ret; return ret;
} }
...@@ -2127,8 +2136,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection { ...@@ -2127,8 +2136,8 @@ public class HttpURLConnection extends java.net.HttpURLConnection {
if (streaming()) { if (streaming()) {
throw new HttpRetryException (RETRY_MSG3, stat, loc); throw new HttpRetryException (RETRY_MSG3, stat, loc);
} }
if (HttpCapture.isLoggable("FINE")) { if (logger.isLoggable(PlatformLogger.FINE)) {
HttpCapture.fine("Redirected from " + url + " to " + locUrl); logger.fine("Redirected from " + url + " to " + locUrl);
} }
// clear out old response headers!!!! // clear out old response headers!!!!
......
...@@ -28,7 +28,7 @@ import java.net.URL; ...@@ -28,7 +28,7 @@ import java.net.URL;
import java.net.PasswordAuthentication; import java.net.PasswordAuthentication;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import sun.net.www.http.HttpCapture; import sun.util.logging.PlatformLogger;
/** /**
* Proxy class for loading NTLMAuthentication, so as to remove static * Proxy class for loading NTLMAuthentication, so as to remove static
...@@ -59,7 +59,7 @@ class NTLMAuthenticationProxy { ...@@ -59,7 +59,7 @@ class NTLMAuthenticationProxy {
try { try {
return threeArgCtr.newInstance(isProxy, url, pw); return threeArgCtr.newInstance(isProxy, url, pw);
} catch (ReflectiveOperationException roe) { } catch (ReflectiveOperationException roe) {
log(roe); finest(roe);
} }
return null; return null;
...@@ -72,7 +72,7 @@ class NTLMAuthenticationProxy { ...@@ -72,7 +72,7 @@ class NTLMAuthenticationProxy {
try { try {
return fiveArgCtr.newInstance(isProxy, host, port, pw); return fiveArgCtr.newInstance(isProxy, host, port, pw);
} catch (ReflectiveOperationException roe) { } catch (ReflectiveOperationException roe) {
log(roe); finest(roe);
} }
return null; return null;
...@@ -86,7 +86,7 @@ class NTLMAuthenticationProxy { ...@@ -86,7 +86,7 @@ class NTLMAuthenticationProxy {
try { try {
return (Boolean)method.invoke(null); return (Boolean)method.invoke(null);
} catch (ReflectiveOperationException roe) { } catch (ReflectiveOperationException roe) {
log(roe); finest(roe);
} }
return false; return false;
...@@ -116,7 +116,7 @@ class NTLMAuthenticationProxy { ...@@ -116,7 +116,7 @@ class NTLMAuthenticationProxy {
fiveArg); fiveArg);
} }
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
log(cnfe); finest(cnfe);
} catch (ReflectiveOperationException roe) { } catch (ReflectiveOperationException roe) {
throw new AssertionError(roe); throw new AssertionError(roe);
} }
...@@ -124,9 +124,8 @@ class NTLMAuthenticationProxy { ...@@ -124,9 +124,8 @@ class NTLMAuthenticationProxy {
return null; return null;
} }
static void log(Exception e) { static void finest(Exception e) {
if (HttpCapture.isLoggable("FINEST")) { PlatformLogger logger = HttpURLConnection.getHttpLogger();
HttpCapture.finest("NTLMAuthenticationProxy: " + e); logger.finest("NTLMAuthenticationProxy: " + e);
}
} }
} }
...@@ -30,12 +30,12 @@ import java.util.HashMap; ...@@ -30,12 +30,12 @@ import java.util.HashMap;
import sun.net.www.HeaderParser; import sun.net.www.HeaderParser;
import sun.misc.BASE64Decoder; import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder; import sun.misc.BASE64Encoder;
import sun.util.logging.PlatformLogger;
import java.net.URL; import java.net.URL;
import java.io.IOException; import java.io.IOException;
import java.net.Authenticator.RequestorType; import java.net.Authenticator.RequestorType;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import sun.net.www.http.HttpCapture;
import static sun.net.www.protocol.http.AuthScheme.NEGOTIATE; import static sun.net.www.protocol.http.AuthScheme.NEGOTIATE;
import static sun.net.www.protocol.http.AuthScheme.KERBEROS; import static sun.net.www.protocol.http.AuthScheme.KERBEROS;
...@@ -258,7 +258,7 @@ abstract class Negotiator { ...@@ -258,7 +258,7 @@ abstract class Negotiator {
clazz = Class.forName("sun.net.www.protocol.http.NegotiatorImpl", true, null); clazz = Class.forName("sun.net.www.protocol.http.NegotiatorImpl", true, null);
c = clazz.getConstructor(HttpCallerInfo.class); c = clazz.getConstructor(HttpCallerInfo.class);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
log(cnfe); finest(cnfe);
throw cnfe; throw cnfe;
} catch (ReflectiveOperationException roe) { } catch (ReflectiveOperationException roe) {
// if the class is there then something seriously wrong if // if the class is there then something seriously wrong if
...@@ -269,10 +269,10 @@ abstract class Negotiator { ...@@ -269,10 +269,10 @@ abstract class Negotiator {
try { try {
return (Negotiator) (c.newInstance(hci)); return (Negotiator) (c.newInstance(hci));
} catch (ReflectiveOperationException roe) { } catch (ReflectiveOperationException roe) {
log(roe); finest(roe);
Throwable t = roe.getCause(); Throwable t = roe.getCause();
if (t != null && t instanceof Exception) if (t != null && t instanceof Exception)
log((Exception)t); finest((Exception)t);
throw roe; throw roe;
} }
} }
...@@ -281,9 +281,8 @@ abstract class Negotiator { ...@@ -281,9 +281,8 @@ abstract class Negotiator {
abstract byte[] nextToken(byte[] in) throws IOException; abstract byte[] nextToken(byte[] in) throws IOException;
static void log(Exception e) { static void finest(Exception e) {
if (HttpCapture.isLoggable("FINEST")) { PlatformLogger logger = HttpURLConnection.getHttpLogger();
HttpCapture.finest("NegotiateAuthentication: " + e); logger.finest("NegotiateAuthentication: " + e);
}
} }
} }
...@@ -29,15 +29,15 @@ package sun.util.logging; ...@@ -29,15 +29,15 @@ package sun.util.logging;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.io.File;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.logging.Logger; import java.util.Date;
import java.util.*; import java.util.HashMap;
import java.util.Map;
import sun.misc.JavaLangAccess; import sun.misc.JavaLangAccess;
import sun.misc.SharedSecrets; import sun.misc.SharedSecrets;
...@@ -493,6 +493,7 @@ public class PlatformLogger { ...@@ -493,6 +493,7 @@ public class PlatformLogger {
private static final Method getLoggerMethod; private static final Method getLoggerMethod;
private static final Method setLevelMethod; private static final Method setLevelMethod;
private static final Method getLevelMethod; private static final Method getLevelMethod;
private static final Method isLoggableMethod;
private static final Method logMethod; private static final Method logMethod;
private static final Method logThrowMethod; private static final Method logThrowMethod;
private static final Method logParamsMethod; private static final Method logParamsMethod;
...@@ -505,6 +506,7 @@ public class PlatformLogger { ...@@ -505,6 +506,7 @@ public class PlatformLogger {
getLoggerMethod = getMethod(loggerClass, "getLogger", String.class); getLoggerMethod = getMethod(loggerClass, "getLogger", String.class);
setLevelMethod = getMethod(loggerClass, "setLevel", levelClass); setLevelMethod = getMethod(loggerClass, "setLevel", levelClass);
getLevelMethod = getMethod(loggerClass, "getLevel"); getLevelMethod = getMethod(loggerClass, "getLevel");
isLoggableMethod = getMethod(loggerClass, "isLoggable", levelClass);
logMethod = getMethod(loggerClass, "log", levelClass, String.class); logMethod = getMethod(loggerClass, "log", levelClass, String.class);
logThrowMethod = getMethod(loggerClass, "log", levelClass, String.class, Throwable.class); logThrowMethod = getMethod(loggerClass, "log", levelClass, String.class, Throwable.class);
logParamsMethod = getMethod(loggerClass, "log", levelClass, String.class, Object[].class); logParamsMethod = getMethod(loggerClass, "log", levelClass, String.class, Object[].class);
...@@ -608,6 +610,10 @@ public class PlatformLogger { ...@@ -608,6 +610,10 @@ public class PlatformLogger {
levelValue = newLevel; levelValue = newLevel;
invoke(setLevelMethod, javaLogger, levelObjects.get(newLevel)); invoke(setLevelMethod, javaLogger, levelObjects.get(newLevel));
} }
public boolean isLoggable(int level) {
return (Boolean) invoke(isLoggableMethod, javaLogger, levelObjects.get(level));
}
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册