Produced by Araxis Merge on 9/25/2018 2:13:12 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\net\spi | DefaultProxySelector.java | Mon Jan 22 14:46:54 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\sun\net\spi | DefaultProxySelector.java | Wed Sep 12 17:45:02 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 788 |
Changed | 1 | 2 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | /* | |
2 | * Copyrig ht (c) 200 3, 2013, O racle and/ or its aff iliates. A ll rights reserved. | |
3 | * DO NOT ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER. | |
4 | * | |
5 | * This co de is free software; you can r edistribut e it and/o r modify i t | |
6 | * under t he terms o f the GNU General Pu blic Licen se version 2 only, a s | |
7 | * publish ed by the Free Softw are Founda tion. Ora cle design ates this | |
8 | * particu lar file a s subject to the "Cl asspath" e xception a s provided | |
9 | * by Orac le in the LICENSE fi le that ac companied this code. | |
10 | * | |
11 | * This co de is dist ributed in the hope that it wi ll be usef ul, but WI THOUT | |
12 | * ANY WAR RANTY; wit hout even the implie d warranty of MERCHA NTABILITY or | |
13 | * FITNESS FOR A PAR TICULAR PU RPOSE. Se e the GNU General Pu blic Licen se | |
14 | * version 2 for mor e details (a copy is included in the LIC ENSE file that | |
15 | * accompa nied this code). | |
16 | * | |
17 | * You sho uld have r eceived a copy of th e GNU Gene ral Public License v ersion | |
18 | * 2 along with this work; if not, write to the Fr ee Softwar e Foundati on, | |
19 | * Inc., 5 1 Franklin St, Fifth Floor, Bo ston, MA 0 2110-1301 USA. | |
20 | * | |
21 | * Please contact Or acle, 500 Oracle Par kway, Redw ood Shores , CA 94065 USA | |
22 | * or visi t www.orac le.com if you need a dditional informatio n or have any | |
23 | * questio ns. | |
24 | */ | |
25 | ||
26 | package su n.net.spi; | |
27 | ||
28 | import jav a.net.Inet SocketAddr ess; | |
29 | import jav a.net.Prox y; | |
30 | import jav a.net.Prox ySelector; | |
31 | import jav a.net.Sock etAddress; | |
32 | import jav a.net.URI; | |
33 | import jav a.util.Arr ayList; | |
34 | import jav a.util.Lis t; | |
35 | import jav a.io.IOExc eption; | |
36 | import jav a.security .AccessCon troller; | |
37 | import jav a.security .Privilege dAction; | |
38 | import jav a.util.Str ingJoiner; | |
39 | import jav a.util.reg ex.Pattern ; | |
40 | import sun .net.NetPr operties; | |
41 | import sun .net.Socks Proxy; | |
42 | import sta tic java.u til.regex. Pattern.qu ote; | |
43 | ||
44 | /** | |
45 | * Support s proxy se ttings usi ng system properties This prox y selector | |
46 | * provide s backward compatibi lity with the old ht tp protoco l handler | |
47 | * as far as how pro xy is set | |
48 | * | |
49 | * Most of the imple mentation copied fro m the old http proto col handle r | |
50 | * | |
51 | * Support s http/htt ps/ftp.pro xyHost, ht tp/https/f tp.proxyPo rt, | |
52 | * proxyHo st, proxyP ort, and h ttp/https/ ftp.nonPro xyHost, an d socks. | |
53 | * NOTE: n eed to do gopher as well | |
54 | */ | |
55 | public cla ss Default ProxySelec tor extend s ProxySel ector { | |
56 | ||
57 | /** | |
58 | * Thi s is where we define all the v alid Syste m Properti es we have to | |
59 | * sup port for e ach given protocol. | |
60 | * The format of this 2 di mensional array is : | |
61 | * - 1 row per p rotocol (h ttp, ftp, ...) | |
62 | * - 1 st element of each r ow is the protocol n ame | |
63 | * - s ubsequent elements a re prefixe s for Host & Port pr operties | |
64 | * l isted in o rder of pr iority. | |
65 | * Exa mple: | |
66 | * {"f tp", "ftp. proxy", "f tpProxy", "proxy", " socksProxy "}, | |
67 | * mea ns for FTP we try in that oder : | |
68 | * + ft p.proxyHos t & ftp.pr oxyPort | |
69 | * + ft pProxyHost & ftpProx yPort | |
70 | * + pr oxyHost & proxyPort | |
71 | * + so cksProxyHo st & socks ProxyPort | |
72 | * | |
73 | * Not e that the socksProx y should * always* be the last on the lis t | |
74 | */ | |
75 | final static Str ing[][] pr ops = { | |
76 | /* | |
77 | * protocol, Property prefix 1, Property p refix 2, . .. | |
78 | * / | |
79 | {" http", "ht tp.proxy", "proxy", "socksProx y"}, | |
80 | {" https", "h ttps.proxy ", "proxy" , "socksPr oxy"}, | |
81 | {" ftp", "ftp .proxy", " ftpProxy", "proxy", "socksProx y"}, | |
82 | {" gopher", " gopherProx y", "socks Proxy"}, | |
83 | {" socket", " socksProxy "} | |
84 | }; | |
85 | ||
86 | privat e static f inal Strin g SOCKS_PR OXY_VERSIO N = "socks ProxyVersi on"; | |
87 | ||
88 | privat e static b oolean has SystemProx ies = fals e; | |
89 | ||
90 | static { | |
91 | fi nal String key = "ja va.net.use SystemProx ies"; | |
92 | Bo olean b = AccessCont roller.doP rivileged( | |
93 | new Priv ilegedActi on<Boolean >() { | |
94 | publ ic Boolean run() { | |
95 | return Net Properties .getBoolea n(key); | |
96 | }}); | |
97 | if (b != nul l && b.boo leanValue( )) { | |
98 | java.sec urity.Acce ssControll er.doPrivi leged( | |
99 | new java.secur ity.Privil egedAction <Void>() { | |
100 | public Voi d run() { | |
101 | System .loadLibra ry("net"); | |
102 | return null; | |
103 | } | |
104 | }); | |
105 | hasSyste mProxies = init(); | |
106 | } | |
107 | } | |
108 | ||
109 | /** | |
110 | * How to deal w ith "non p roxy hosts ": | |
111 | * sin ce we do h ave to gen erate a pa ttern we d on't want to do that if | |
112 | * it' s not nece ssary. The refore we do cache t he result, on a per- protocol | |
113 | * bas is, and ch ange it on ly when th e "source" , i.e. the system pr operty, | |
114 | * did change. | |
115 | */ | |
116 | ||
117 | static class Non ProxyInfo { | |
118 | // Default v alue for n onProxyHos ts, this p rovides ba ckward com patibility | |
119 | // by exclud ing localh ost and it s litteral notations . | |
120 | st atic final String de fStringVal = "localh ost|127.*| [::1]|0.0. 0.0|[::0]" ; | |
121 | ||
122 | St ring hosts Source; | |
123 | Pa ttern patt ern; | |
124 | fi nal String property; | |
125 | fi nal String defaultVa l; | |
126 | st atic NonPr oxyInfo ft pNonProxyI nfo = new NonProxyIn fo("ftp.no nProxyHost s", null, null, defS tringVal); | |
127 | st atic NonPr oxyInfo ht tpNonProxy Info = new NonProxyI nfo("http. nonProxyHo sts", null , null, de fStringVal ); | |
128 | st atic NonPr oxyInfo so cksNonProx yInfo = ne w NonProxy Info("sock sNonProxyH osts", nul l, null, d efStringVa l); | |
129 | ||
130 | No nProxyInfo (String p, String s, Pattern p attern, St ring d) { | |
131 | property = p; | |
132 | hostsSou rce = s; | |
133 | this.pat tern = pat tern; | |
134 | defaultV al = d; | |
135 | } | |
136 | } | |
137 | ||
138 | ||
139 | /** | |
140 | * sel ect() meth od. Where all the ha rd work is done. | |
141 | * Bui ld a list of proxies depending on URI. | |
142 | * Sin ce we're o nly provid ing compat ibility wi th the sys tem proper ties | |
143 | * fro m previous releases (see list above), th at list wi ll always | |
144 | * con tain 1 sin gle proxy, default b eing NO_PR OXY. | |
145 | */ | |
146 | public java.util .List<Prox y> select( URI uri) { | |
147 | if (uri == n ull) { | |
148 | throw ne w IllegalA rgumentExc eption("UR I can't be null."); | |
149 | } | |
150 | St ring proto col = uri. getScheme( ); | |
151 | St ring host = uri.getH ost(); | |
152 | ||
153 | if (host == null) { | |
154 | // This is a hack to ensure backward c ompatibili ty in two | |
155 | // cases : 1. hostn ames conta in non-asc ii charact ers, | |
156 | // inter nationaliz ed domain names. in which case , URI will | |
157 | // retur n null, se e BugID 49 57669; 2. Some hostn ames can | |
158 | // conta in '_' cha rs even th ough it's not suppos ed to be | |
159 | // legal , in which case URI will retur n null for getHost, | |
160 | // but n ot for get Authority( ) See BugI D 4913253 | |
161 | String a uth = uri. getAuthori ty(); | |
162 | if (auth != null) { | |
163 | int i; | |
164 | i = auth.index Of('@'); | |
165 | if ( i >= 0) { | |
166 | auth = aut h.substrin g(i+1); | |
167 | } | |
168 | i = auth.lastI ndexOf(':' ); | |
169 | if ( i >= 0) { | |
170 | auth = aut h.substrin g(0,i); | |
171 | } | |
172 | host = auth; | |
173 | } | |
174 | } | |
175 | ||
176 | if (protocol == null | | host == null) { | |
177 | throw ne w IllegalA rgumentExc eption("pr otocol = " +protocol+ " host = " +host); | |
178 | } | |
179 | Li st<Proxy> proxyl = n ew ArrayLi st<Proxy>( 1); | |
180 | ||
181 | No nProxyInfo pinfo = n ull; | |
182 | ||
183 | if ("http".e qualsIgnor eCase(prot ocol)) { | |
184 | pinfo = NonProxyIn fo.httpNon ProxyInfo; | |
185 | } else if (" https".equ alsIgnoreC ase(protoc ol)) { | |
186 | // HTTPS uses the same prope rty as HTT P, for bac kward | |
187 | // compa tibility | |
188 | pinfo = NonProxyIn fo.httpNon ProxyInfo; | |
189 | } else if (" ftp".equal sIgnoreCas e(protocol )) { | |
190 | pinfo = NonProxyIn fo.ftpNonP roxyInfo; | |
191 | } else if (" socket".eq ualsIgnore Case(proto col)) { | |
192 | pinfo = NonProxyIn fo.socksNo nProxyInfo ; | |
193 | } | |
194 | ||
195 | /* * | |
196 | * Let's che ck the Sys tem proper ties for t hat protoc ol | |
197 | * / | |
198 | fi nal String proto = p rotocol; | |
199 | fi nal NonPro xyInfo npr op = pinfo ; | |
200 | fi nal String urlhost = host.toLo werCase(); | |
201 | ||
202 | /* * | |
203 | * This is o ne big doP rivileged call, but we're tryi ng to opti mize | |
204 | * the code as much as possible. Since we' re checkin g quite a few | |
205 | * System pr operties i t does hel p having o nly 1 call to doPriv ileged. | |
206 | * Be mindfu l what you do in her e though! | |
207 | * / | |
208 | Pr oxy p = Ac cessContro ller.doPri vileged( | |
209 | new Priv ilegedActi on<Proxy>( ) { | |
210 | publ ic Proxy r un() { | |
211 | int i, j; | |
212 | String pho st = null ; | |
213 | int p PORT
|
|
214 | String nph osts = nu ll; | |
215 | InetSocket Address sa ddr = null ; | |
216 | ||
217 | // Then le t's walk t he list of protocols in our ar ray | |
218 | for (i=0; i<props.le ngth; i++) { | |
219 | if (pr ops[i][0]. equalsIgno reCase(pro to)) { | |
220 | fo r (j = 1; j < props[ i].length; j++) { | |
221 | /* Syste m.getProp( ) will giv e us an em pty | |
222 | * Strin g, "" for a defined but "empty " | |
223 | * prope rty. | |
224 | */ | |
225 | phost = NetProper ties.get(p rops[i][j] +"Host"); | |
226 | if (phos t != null && phost.l ength() != 0) | |
227 | brea k; | |
228 | } | |
229 | if (phost == null || p host.lengt h() == 0) { | |
230 | /** | |
231 | * No sy stem prope rty define d for that | |
232 | * proto col. Let's check Sys tem Proxy | |
233 | * setti ngs (Gnome & Windows ) if we we re | |
234 | * instr ucted to. | |
235 | */ | |
236 | if (hasS ystemProxi es) { | |
237 | Stri ng sproto; | |
238 | if ( proto.equa lsIgnoreCa se("socket ")) | |
239 | sproto = " socks"; | |
240 | else | |
241 | sproto = p roto; | |
242 | Prox y sproxy = getSystem Proxy(spro to, urlhos t); | |
243 | if ( sproxy != null) { | |
244 | return spr oxy; | |
245 | } | |
246 | } | |
247 | return P roxy.NO_PR OXY; | |
248 | } | |
249 | // If a Prox y Host is defined fo r that pro tocol | |
250 | // Let's get the NonPr oxyHosts p roperty | |
251 | if (nprop != null) { | |
252 | nphosts = NetPrope rties.get( nprop.prop erty); | |
253 | synchron ized (npro p) { | |
254 | if ( nphosts == null) { | |
255 | if (nprop. defaultVal != null) { | |
256 | nphost s = nprop. defaultVal ; | |
257 | } else { | |
258 | nprop. hostsSourc e = null; | |
259 | nprop. pattern = null; | |
260 | } | |
261 | } el se if (nph osts.lengt h() != 0) { | |
262 | // add the required default pa tterns | |
263 | // but onl y if prope rty no set . If it | |
264 | // is empt y, leave e mpty. | |
265 | nphosts += "|" + Non ProxyInfo | |
266 | .de fStringVal ; | |
267 | } | |
268 | if ( nphosts != null) { | |
269 | if (!nphos ts.equals( nprop.host sSource)) { | |
270 | nprop. pattern = toPattern( nphosts); | |
271 | nprop. hostsSourc e = nphost s; | |
272 | } | |
273 | } | |
274 | if ( shouldNotU seProxyFor (nprop.pat tern, urlh ost)) { | |
275 | return Pro xy.NO_PROX Y; | |
276 | } | |
277 | } | |
278 | } | |
279 | // We got a host, let' s check fo r port | |
280 | ||
281 | pp ort = NetP roperties. getInteger (props[i][ j]+"Port", 0).intVal ue(); | |
282 | if (pport == 0 && j < (props[i]. length - 1 )) { | |
283 | // Can't find a po rt with sa me prefix as Host | |
284 | // AND i t's not a SOCKS prox y | |
285 | // Let's try the o ther prefi xes for th at proto | |
286 | for (int k = 1; k < (props[i ].length - 1); k++) { | |
287 | if ( (k != j) & & (pport = = 0)) | |
288 | pport = Ne tPropertie s.getInteg er(props[i ][k]+"Port ", 0).intV alue(); | |
289 | } | |
290 | } | |
291 | ||
292 | // Still cou ldn't find a port, l et's use d efault | |
293 | if (pport == 0) { | |
294 | if (j == (props[i] .length - 1)) // SOC KS | |
295 | ppor t = defaul tPort("soc ket"); | |
296 | else | |
297 | ppor t = defaul tPort(prot o); | |
298 | } | |
299 | // We did fi nd a proxy definitio n. | |
300 | // Let's cre ate the ad dress, but don't res olve it | |
301 | // as this w ill be don e at conne ction time | |
302 | sa ddr = Inet SocketAddr ess.create Unresolved (phost, pp ort); | |
303 | // Socks is *always* t he last on the list. | |
304 | if (j == (pr ops[i].len gth - 1)) { | |
305 | int vers ion = NetP roperties. getInteger (SOCKS_PRO XY_VERSION , 5).intVa lue(); | |
306 | return S ocksProxy. create(sad dr, versio n); | |
307 | } else { | |
308 | return n ew Proxy(P roxy.Type. HTTP, sadd r); | |
309 | } | |
310 | } | |
311 | } | |
312 | return Pro xy.NO_PROX Y; | |
313 | }}); | |
314 | ||
315 | pr oxyl.add(p ); | |
316 | ||
317 | /* | |
318 | * If no spe cific prop erty was s et for tha t URI, we should be | |
319 | * returning an iterat or to an e mpty List. | |
320 | * / | |
321 | re turn proxy l; | |
322 | } | |
323 | ||
324 | public void conn ectFailed( URI uri, S ocketAddre ss sa, IOE xception i oe) { | |
325 | if (uri == n ull || sa == null || ioe == nu ll) { | |
326 | throw ne w IllegalA rgumentExc eption("Ar guments ca n't be nul l."); | |
327 | } | |
328 | // ignored | |
329 | } | |
330 | ||
331 | ||
332 | privat e int defa ultPort(St ring proto col) { | |
333 | if ("http".e qualsIgnor eCase(prot ocol)) { | |
334 | return 8 0; | |
335 | } else if (" https".equ alsIgnoreC ase(protoc ol)) { | |
336 | return 4 43; | |
337 | } else if (" ftp".equal sIgnoreCas e(protocol )) { | |
338 | return 8 0; | |
339 | } else if (" socket".eq ualsIgnore Case(proto col)) { | |
340 | return 1 080; | |
341 | } else if (" gopher".eq ualsIgnore Case(proto col)) { | |
342 | return 8 0; | |
343 | } else { | |
344 | return - 1; | |
345 | } | |
346 | } | |
347 | ||
348 | privat e native s tatic bool ean init() ; | |
349 | privat e synchron ized nativ e Proxy ge tSystemPro xy(String protocol, String hos t); | |
350 | ||
351 | /** | |
352 | * @re turn {@cod e true} if given thi s pattern for non-pr oxy hosts and this | |
353 | * urlho st the pro xy should NOT be use d to acces s this url host | |
354 | */ | |
355 | static boolean s houldNotUs eProxyFor( Pattern pa ttern, Str ing urlhos t) { | |
356 | if (pattern == null || urlhost.i sEmpty()) | |
357 | return f alse; | |
358 | bo olean matc hes = patt ern.matche r(urlhost) .matches() ; | |
359 | re turn match es; | |
360 | } | |
361 | ||
362 | /** | |
363 | * @pa ram mask n on-null ma sk | |
364 | * @re turn {@lin k java.uti l.regex.Pa ttern} cor responding to this m ask | |
365 | * or {@ code null} in case m ask should not match anything | |
366 | */ | |
367 | static Pattern t oPattern(S tring mask ) { | |
368 | bo olean disj unctionEmp ty = true; | |
369 | St ringJoiner joiner = new String Joiner("|" ); | |
370 | fo r (String disjunct : mask.spli t("\\|")) { | |
371 | if (disj unct.isEmp ty()) | |
372 | cont inue; | |
373 | disjunct ionEmpty = false; | |
374 | String r egex = dis junctToReg ex(disjunc t.toLowerC ase()); | |
375 | joiner.a dd(regex); | |
376 | } | |
377 | re turn disju nctionEmpt y ? null : Pattern.c ompile(joi ner.toStri ng()); | |
378 | } | |
379 | ||
380 | /** | |
381 | * @pa ram disjun ct non-nul l mask dis junct | |
382 | * @re turn java regex stri ng corresp onding to this mask | |
383 | */ | |
384 | static String di sjunctToRe gex(String disjunct) { | |
385 | St ring regex ; | |
386 | if (disjunct .startsWit h("*")) { | |
387 | regex = ".*" + quo te(disjunc t.substrin g(1)); | |
388 | } else if (d isjunct.en dsWith("*" )) { | |
389 | regex = quote(disj unct.subst ring(0, di sjunct.len gth() - 1) ) + ".*"; | |
390 | } else { | |
391 | regex = quote(disj unct); | |
392 | } | |
393 | re turn regex ; | |
394 | } | |
395 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.