| 1 |
package com.github.markusbernhardt.proxy.selector.pac; |
| 2 |
|
| 3 |
import java.io.InputStream; |
| 4 |
import java.io.InputStreamReader; |
| 5 |
import java.io.LineNumberReader; |
| 6 |
import java.net.ProxySelector; |
| 7 |
import java.net.URL; |
| 8 |
import java.net.URLConnection; |
| 9 |
import java.text.MessageFormat; |
| 10 |
|
| 11 |
import com.github.markusbernhardt.proxy.ProxySearch; |
| 12 |
import com.github.markusbernhardt.proxy.util.Logger; |
| 13 |
import com.github.markusbernhardt.proxy.util.Logger.LogLevel; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class PacProxyDebugging { |
| 26 |
|
| 27 |
private static final String TEST_URL = "http://www.asetune.com"; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
private void installLogger() { |
| 34 |
Logger.setBackend(new Logger.LogBackEnd() { |
| 35 |
public void log(Class<?> clazz, LogLevel loglevel, String msg, Object... params) { |
| 36 |
System.out.println(loglevel + "\t" + MessageFormat.format(msg, params)); |
| 37 |
} |
| 38 |
|
| 39 |
public boolean isLogginEnabled(LogLevel logLevel) { |
| 40 |
return true; |
| 41 |
} |
| 42 |
}); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public static void main(String[] args) { |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
PacProxyDebugging pt = new PacProxyDebugging(); |
| 58 |
pt.installLogger(); |
| 59 |
|
| 60 |
ProxySearch proxySearch = ProxySearch.getDefaultProxySearch(); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ProxySelector myProxySelector = proxySearch.getProxySelector(); |
| 69 |
|
| 70 |
ProxySelector.setDefault(myProxySelector); |
| 71 |
System.out.println("Using proxy selector: " + myProxySelector); |
| 72 |
|
| 73 |
|
| 74 |
String webAddress = TEST_URL; |
| 75 |
try { |
| 76 |
URL url = new URL(webAddress); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
System.out.println("Now open a connection to the url: " + webAddress); |
| 88 |
System.out.println("=============================================="); |
| 89 |
|
| 90 |
|
| 91 |
URLConnection conn = url.openConnection(); |
| 92 |
conn.setConnectTimeout(10 * 1000); |
| 93 |
|
| 94 |
|
| 95 |
InputStream in = conn.getInputStream(); |
| 96 |
LineNumberReader lr = new LineNumberReader(new InputStreamReader(in)); |
| 97 |
String line; |
| 98 |
while ((line = lr.readLine()) != null) { |
| 99 |
System.out.println("response line " + lr.getLineNumber() + ": " + line); |
| 100 |
} |
| 101 |
System.out.println("---- END -------------------------------------"); |
| 102 |
} catch (Exception e) { |
| 103 |
e.printStackTrace(); |
| 104 |
} |
| 105 |
} |
| 106 |
} |