Debian Codegraph @

src/test/java/com/github/markusbernhardt/proxy/selector/pac/PacProxyDebugging.java

raw symbols SCIP
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 * Test program submitted to test the issue 27 with PAC proxy selector that is
17 * while downloading the PAC file invoking itself. This has lead to a endless
18 * loop. The issue is now solved but I keep this test program for future PAC
19 * testing.
20 *
21 * @author Markus Bernhardt, Copyright 2016
22 * @author Bernd Rosstauscher, Copyright 2009
23 ****************************************************************************/
24
25 public class PacProxyDebugging {
26
27 private static final String TEST_URL = "http://www.asetune.com";
28
29 /*************************************************************************
30 * Setup a console logger.
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 * Main entry point for the test application.
47 *
48 * @param args
49 * the command line arguments.
50 ************************************************************************/
51
52 public static void main(String[] args) {
53 // System.setProperty("http.proxyHost", "10.65.12.21");
54 // System.setProperty("http.proxyPort", "8080");
55 // System.setProperty("java.net.useSystemProxies", "true");
56
57 PacProxyDebugging pt = new PacProxyDebugging();
58 pt.installLogger();
59
60 ProxySearch proxySearch = ProxySearch.getDefaultProxySearch();
61
62 // ProxySearch proxySearch = new ProxySearch();
63 // proxySearch.addStrategy(Strategy.JAVA);
64 // proxySearch.addStrategy(Strategy.BROWSER);
65 // proxySearch.addStrategy(Strategy.OS_DEFAULT);
66 // proxySearch.addStrategy(Strategy.ENV_VAR);
67
68 ProxySelector myProxySelector = proxySearch.getProxySelector();
69
70 ProxySelector.setDefault(myProxySelector);
71 System.out.println("Using proxy selector: " + myProxySelector);
72
73 // String webAddress = "http://www.google.com";
74 String webAddress = TEST_URL;
75 try {
76 URL url = new URL(webAddress);
77 // List<Proxy> result = myProxySelector.select(url.toURI());
78 // if (result == null || result.size() == 0)
79 // {
80 // System.out.println("No proxy found for this url.");
81 // return;
82 // }
83 // System.out.println("Proxy Settings found using 'xxx' strategy.\n"
84 // +
85 // "Proxy used for URL is: "+result.get(0));
86
87 System.out.println("Now open a connection to the url: " + webAddress);
88 System.out.println("==============================================");
89
90 // open the connection and prepare it to POST
91 URLConnection conn = url.openConnection();
92 conn.setConnectTimeout(10 * 1000);
93
94 // Return the response
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 }