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\javax\management\remote | JMXServiceURL.java | Mon Jan 22 14:46:52 2018 UTC |
2 | build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\javax\management\remote | JMXServiceURL.java | Wed Sep 12 17:21:05 2018 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 1464 |
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 2, 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 | ||
27 | package ja vax.manage ment.remot e; | |
28 | ||
29 | ||
30 | import com .sun.jmx.r emote.util .ClassLogg er; | |
31 | import com .sun.jmx.r emote.util .EnvHelp; | |
32 | import jav a.io.IOExc eption; | |
33 | import jav a.io.Inval idObjectEx ception; | |
34 | import jav a.io.Objec tInputStre am; | |
35 | ||
36 | import jav a.io.Seria lizable; | |
37 | import jav a.net.Inet Address; | |
38 | import jav a.net.Malf ormedURLEx ception; | |
39 | import jav a.net.Unkn ownHostExc eption; | |
40 | import jav a.util.Bit Set; | |
41 | import jav a.util.Str ingTokeniz er; | |
42 | ||
43 | /** | |
44 | * <p>The address of a JMX API connector server. Instances of this cl ass | |
45 | * are imm utable.</p > | |
46 | * | |
47 | * <p>The address is an <em>Ab stract Ser vice URL</ em> for SL P, as | |
48 | * defined in RFC 26 09 and ame nded by RF C 3111. I t must loo k like | |
49 | * this:</ p> | |
50 | * | |
51 | * <blockq uote> | |
52 | * | |
53 | * <code>s ervice:jmx :<em>proto col</em>:< em>sap</em ></code> | |
54 | * | |
55 | * </block quote> | |
56 | * | |
57 | * <p>Here , <code><e m>protocol </em></cod e> is the transport | |
58 | * protoco l to be us ed to conn ect to the connector server. It is | |
59 | * a strin g of one o r more ASC II charact ers, each of which i s a | |
60 | * letter, a digit, or one of the charac ters <code >+</code> or | |
61 | * <code>- </code>. The first character must be a letter. | |
62 | * Upperca se letters are conve rted into lowercase ones.</p> | |
63 | * | |
64 | * <p><cod e><em>sap< /em></code > is the a ddress at which the connector | |
65 | * server is found. This addr ess uses a subset of the synta x defined | |
66 | * by RFC 2609 for I P-based pr otocols. It is a su bset becau se the | |
67 | * <code>u ser@host</ code> synt ax is not supported. </p> | |
68 | * | |
69 | * <p>The other synt axes defin ed by RFC 2609 are n ot current ly | |
70 | * support ed by this class.</p > | |
71 | * | |
72 | * <p>The supported syntax is: </p> | |
73 | * | |
74 | * <blockq uote> | |
75 | * | |
76 | * <code>/ /<em>[host [</em>:<em >port]][ur l-path]</e m></code> | |
77 | * | |
78 | * </block quote> | |
79 | * | |
80 | * <p>Squa re bracket s <code>[] </code> in dicate opt ional part s of | |
81 | * the add ress. Not all proto cols will recognize all option al | |
82 | * parts.< /p> | |
83 | * | |
84 | * <p>The <code><em> host</em>< /code> is a host nam e, an IPv4 numeric | |
85 | * host ad dress, or an IPv6 nu meric addr ess enclos ed in squa re | |
86 | * bracket s.</p> | |
87 | * | |
88 | * <p>The <code><em> port</em>< /code> is a decimal port numbe r. 0 | |
89 | * means a default o r anonymou s port, de pending on the proto col.</p> | |
90 | * | |
91 | * <p>The <code><em> host</em>< /code> and <code><em >port</em> </code> | |
92 | * can be omitted. The <code> <em>port</ em></code> cannot be supplied | |
93 | * without a <code>< em>host</e m></code>. </p> | |
94 | * | |
95 | * <p>The <code><em> url-path</ em></code> , if any, begins wit h a slash | |
96 | * (<code> /</code>) or a semic olon (<cod e>;</code> ) and cont inues to | |
97 | * the end of the ad dress. It can conta in attribu tes using the | |
98 | * semicol on syntax specified in RFC 260 9. Those attributes are not | |
99 | * parsed by this cl ass and in correct at tribute sy ntax is no t | |
100 | * detecte d.</p> | |
101 | * | |
102 | * <p>Alth ough it is legal acc ording to RFC 2609 t o have a | |
103 | * <code>< em>url-pat h</em></co de> that b egins with a semicol on, not | |
104 | * all imp lementatio ns of SLP allow it, so it is r ecommended to avoid | |
105 | * that sy ntax.</p> | |
106 | * | |
107 | * <p>Case is not si gnificant in the ini tial | |
108 | * <code>s ervice:jmx :<em>proto col</em></ code> stri ng or in t he host | |
109 | * part of the addre ss. Depen ding on th e protocol , case can be | |
110 | * signifi cant in th e <code><e m>url-path </em></cod e>.</p> | |
111 | * | |
112 | * @see <a | |
113 | * href="h ttp://www. ietf.org/r fc/rfc2609 .txt">RFC 2609, | |
114 | * "Servic e Template s and <cod e>Service: </code> Sc hemes"</a> | |
115 | * @see <a | |
116 | * href="h ttp://www. ietf.org/r fc/rfc3111 .txt">RFC 3111, | |
117 | * "Servic e Location Protocol Modificati ons for IP v6"</a> | |
118 | * | |
119 | * @since 1.5 | |
120 | */ | |
121 | public cla ss JMXServ iceURL imp lements Se rializable { | |
122 | ||
123 | privat e static f inal long serialVers ionUID = 8 1733644098 60779292L; | |
124 | ||
125 | /** | |
126 | * <p> Constructs a <code>J MXServiceU RL</code> by parsing a Service URL | |
127 | * str ing.</p> | |
128 | * | |
129 | * @pa ram servic eURL the U RL string to be pars ed. | |
130 | * | |
131 | * @ex ception Nu llPointerE xception i f <code>se rviceURL</ code> is | |
132 | * nul l. | |
133 | * | |
134 | * @ex ception Ma lformedURL Exception if <code>s erviceURL< /code> | |
135 | * doe s not conf orm to the syntax fo r an Abstr act Servic e URL or | |
136 | * if it is not a valid na me for a J MX Remote API servic e. A | |
137 | * <co de>JMXServ iceURL</co de> must b egin with the string | |
138 | * <co de>"servic e:jmx:"</c ode> (case -insensiti ve). It m ust not | |
139 | * con tain any c haracters that are n ot printab le ASCII c haracters. | |
140 | */ | |
141 | public JMXServic eURL(Strin g serviceU RL) throws Malformed URLExcepti on { | |
142 | fi nal int se rviceURLLe ngth = ser viceURL.le ngth(); | |
143 | ||
144 | /* Check tha t there ar e no non-A SCII chara cters in t he URL, | |
145 | following RFC 2609. */ | |
146 | fo r (int i = 0; i < se rviceURLLe ngth; i++) { | |
147 | char c = serviceUR L.charAt(i ); | |
148 | if (c < 32 || c >= 127) { | |
149 | thro w new Malf ormedURLEx ception("S ervice URL contains " + | |
150 | "n on-ASCII c haracter 0 x" + | |
151 | In teger.toHe xString(c) ); | |
152 | } | |
153 | } | |
154 | ||
155 | // Parse the required prefix | |
156 | fi nal String requiredP refix = "s ervice:jmx :"; | |
157 | fi nal int re quiredPref ixLength = requiredP refix.leng th(); | |
158 | if (!service URL.region Matches(tr ue, // ign ore case | |
159 | 0, // ser viceURL of fset | |
160 | re quiredPref ix, | |
161 | 0, // req uiredPrefi x offset | |
162 | re quiredPref ixLength)) { | |
163 | throw ne w Malforme dURLExcept ion("Servi ce URL mus t start wi th " + | |
164 | requir edPrefix); | |
165 | } | |
166 | ||
167 | // Parse the protocol name | |
168 | fi nal int pr otoStart = requiredP refixLengt h; | |
169 | fi nal int pr otoEnd = i ndexOf(ser viceURL, ' :', protoS tart); | |
170 | th is.protoco l = | |
171 | serviceU RL.substri ng(protoSt art, proto End).toLow erCase(); | |
172 | ||
173 | if (!service URL.region Matches(pr otoEnd, ": //", 0, 3) ) { | |
174 | throw ne w Malforme dURLExcept ion("Missi ng \"://\" after " + | |
175 | "proto col name") ; | |
176 | } | |
177 | ||
178 | // Parse the host name | |
179 | fi nal int ho stStart = protoEnd + 3; | |
180 | fi nal int ho stEnd; | |
181 | if (hostStar t < servic eURLLength | |
182 | && servi ceURL.char At(hostSta rt) == '[' ) { | |
183 | hostEnd = serviceU RL.indexOf (']', host Start) + 1 ; | |
184 | if (host End == 0) | |
185 | thro w new Malf ormedURLEx ception("B ad host na me: [ with out ]"); | |
186 | this.hos t = servic eURL.subst ring(hostS tart + 1, hostEnd - 1); | |
187 | if (!isN umericIPv6 Address(th is.host)) { | |
188 | thro w new Malf ormedURLEx ception("A ddress ins ide [...] must " + | |
189 | "b e numeric IPv6 addre ss"); | |
190 | } | |
191 | } else { | |
192 | hostEnd = | |
193 | inde xOfFirstNo tInSet(ser viceURL, h ostNameBit Set, hostS tart); | |
194 | this.hos t = servic eURL.subst ring(hostS tart, host End); | |
195 | } | |
196 | ||
197 | // Parse the port numb er | |
198 | fi nal int po rtEnd; | |
199 | if (hostEnd < serviceU RLLength & & serviceU RL.charAt( hostEnd) = = ':') { | |
200 | if (this .host.leng th() == 0) { | |
201 | thro w new Malf ormedURLEx ception("C annot give port numb er " + | |
202 | "w ithout hos t name"); | |
203 | } | |
204 | final in t portStar t = hostEn d + 1; | |
205 | portEnd = | |
206 | inde xOfFirstNo tInSet(ser viceURL, n umericBitS et, portSt art); | |
207 | final St ring portS tring = se rviceURL.s ubstring(p ortStart, portEnd); | |
208 | try { | |
209 | this .port = In teger.pars eInt(portS tring); | |
210 | } catch (NumberFor matExcepti on e) { | |
211 | thro w new Malf ormedURLEx ception("B ad port nu mber: \"" + | |
212 | po rtString + "\": " + e); | |
213 | } | |
214 | } else { | |
215 | portEnd = hostEnd; | |
216 | this. PORT
|
|
217 | } | |
218 | ||
219 | // Parse the URL path | |
220 | fi nal int ur lPathStart = portEnd ; | |
221 | if (urlPathS tart < ser viceURLLen gth) | |
222 | this.url Path = ser viceURL.su bstring(ur lPathStart ); | |
223 | el se | |
224 | this.url Path = ""; | |
225 | ||
226 | va lidate(); | |
227 | } | |
228 | ||
229 | /** | |
230 | * <p> Constructs a <code>J MXServiceU RL</code> with the g iven proto col, | |
231 | * hos t, and por t. This c onstructor is equiva lent to | |
232 | * {@l ink #JMXSe rviceURL(S tring, Str ing, int, String) | |
233 | * JMX ServiceURL (protocol, host, por t, null)}. </p> | |
234 | * | |
235 | * @pa ram protoc ol the pro tocol part of the UR L. If nul l, default s | |
236 | * to <code>jmxm p</code>. | |
237 | * | |
238 | * @pa ram host t he host pa rt of the URL. If n ull, defau lts to the | |
239 | * loc al host na me, as det ermined by | |
240 | * <co de>InetAdd ress.getLo calHost(). getHostNam e()</code> . If it | |
241 | * is a numeric IPv6 addre ss, it can optionall y be enclo sed in | |
242 | * squ are bracke ts <code>[ ]</code>. | |
243 | * | |
244 | * @pa ram port t he port pa rt of the URL. | |
245 | * | |
246 | * @ex ception Ma lformedURL Exception if one of the parts is | |
247 | * syn tactically incorrect , or if <c ode>host</ code> is n ull and it | |
248 | * is not possib le to find the local host name , or if | |
249 | * <co de>port</c ode> is ne gative. | |
250 | */ | |
251 | public JMXServic eURL(Strin g protocol , String h ost, int p ort) | |
252 | throws M alformedUR LException { | |
253 | th is(protoco l, host, p ort, null) ; | |
254 | } | |
255 | ||
256 | /** | |
257 | * <p> Constructs a <code>J MXServiceU RL</code> with the g iven parts . | |
258 | * | |
259 | * @pa ram protoc ol the pro tocol part of the UR L. If nul l, default s | |
260 | * to <code>jmxm p</code>. | |
261 | * | |
262 | * @pa ram host t he host pa rt of the URL. If n ull, defau lts to the | |
263 | * loc al host na me, as det ermined by | |
264 | * <co de>InetAdd ress.getLo calHost(). getHostNam e()</code> . If it | |
265 | * is a numeric IPv6 addre ss, it can optionall y be enclo sed in | |
266 | * squ are bracke ts <code>[ ]</code>. | |
267 | * | |
268 | * @pa ram port t he port pa rt of the URL. | |
269 | * | |
270 | * @pa ram urlPat h the URL path part of the URL . If null , defaults to | |
271 | * the empty str ing. | |
272 | * | |
273 | * @ex ception Ma lformedURL Exception if one of the parts is | |
274 | * syn tactically incorrect , or if <c ode>host</ code> is n ull and it | |
275 | * is not possib le to find the local host name , or if | |
276 | * <co de>port</c ode> is ne gative. | |
277 | */ | |
278 | public JMXServic eURL(Strin g protocol , String h ost, int p ort, | |
279 | Strin g urlPath) | |
280 | throws M alformedUR LException { | |
281 | if (protocol == null) | |
282 | protocol = "jmxmp" ; | |
283 | ||
284 | if (host == null) { | |
285 | InetAddr ess local; | |
286 | try { | |
287 | loca l = InetAd dress.getL ocalHost() ; | |
288 | } catch (UnknownHo stExceptio n e) { | |
289 | thro w new Malf ormedURLEx ception("L ocal host name unkno wn: " + | |
290 | e) ; | |
291 | } | |
292 | ||
293 | host = l ocal.getHo stName(); | |
294 | ||
295 | /* We mi ght have a hostname that viola tes DNS na ming | |
296 | rules , for exam ple that c ontains an `_'. Whi le we | |
297 | could be strict and throw an except ion, this is rather | |
298 | user- hostile. Instead we use its n umerical I P address. | |
299 | We ca n only rea sonably do this for the host== null case. | |
300 | If we 're given an explici t host nam e that is illegal we | |
301 | have to reject it. (Bug 5057532.) */ | |
302 | try { | |
303 | vali dateHost(h ost, port) ; | |
304 | } catch (Malformed URLExcepti on e) { | |
305 | if ( logger.fin eOn()) { | |
306 | logger.fin e("JMXServ iceURL", | |
307 | "Replaci ng illegal local hos t name " + | |
308 | host + " with nume ric IP add ress " + | |
309 | "(see RF C 1034)", e); | |
310 | } | |
311 | host = local.g etHostAddr ess(); | |
312 | /* U se the num eric addre ss, which could be e ither IPv4 | |
313 | o r IPv6. v alidateHos t will acc ept either . */ | |
314 | } | |
315 | } | |
316 | ||
317 | if (host.sta rtsWith("[ ")) { | |
318 | if (!hos t.endsWith ("]")) { | |
319 | thro w new Malf ormedURLEx ception("H ost starts with [ bu t " + | |
320 | "d oes not en d with ]") ; | |
321 | } | |
322 | host = h ost.substr ing(1, hos t.length() - 1); | |
323 | if (!isN umericIPv6 Address(ho st)) { | |
324 | thro w new Malf ormedURLEx ception("A ddress ins ide [...] must " + | |
325 | "b e numeric IPv6 addre ss"); | |
326 | } | |
327 | if (host .startsWit h("[")) | |
328 | thro w new Malf ormedURLEx ception("M ore than o ne [[...]] "); | |
329 | } | |
330 | ||
331 | th is.protoco l = protoc ol.toLower Case(); | |
332 | th is.host = host; | |
333 | th is.port = port; | |
334 | ||
335 | if (urlPath == null) | |
336 | urlPath = ""; | |
337 | th is.urlPath = urlPath ; | |
338 | ||
339 | va lidate(); | |
340 | } | |
341 | ||
342 | privat e static f inal Strin g INVALID_ INSTANCE_M SG = | |
343 | "Trying to deseria lize an in valid inst ance of JM XServiceUR L"; | |
344 | privat e void rea dObject(Ob jectInputS tream inp utStream) throws IOE xception, ClassNotFo undExcepti on { | |
345 | Ob jectInputS tream.GetF ield gf = inputStrea m.readFiel ds(); | |
346 | St ring h = ( String)gf. get("host" , null); | |
347 | in t p = (int )gf.get("p ort", -1); | |
348 | St ring proto = (String )gf.get("p rotocol", null); | |
349 | St ring url = (String)g f.get("url Path", nul l); | |
350 | ||
351 | if (proto == null || u rl == null || h == n ull) { | |
352 | StringBu ilder sb = new Strin gBuilder(I NVALID_INS TANCE_MSG) .append('[ '); | |
353 | boolean empty = tr ue; | |
354 | if (prot o == null) { | |
355 | sb.a ppend("pro tocol=null "); | |
356 | empt y = false; | |
357 | } | |
358 | if (h == null) { | |
359 | sb.a ppend(empt y ? "" : " ,").append ("host=nul l"); | |
360 | empt y = false; | |
361 | } | |
362 | if (url == null) { | |
363 | sb.a ppend(empt y ? "" : " ,").append ("urlPath= null"); | |
364 | } | |
365 | sb.appen d(']'); | |
366 | throw ne w InvalidO bjectExcep tion(sb.to String()); | |
367 | } | |
368 | ||
369 | if (h.contai ns("[") || h.contain s("]")) { | |
370 | throw ne w InvalidO bjectExcep tion("Inva lid host n ame: " + h ); | |
371 | } | |
372 | ||
373 | tr y { | |
374 | validate (proto, h, p, url); | |
375 | this.pro tocol = pr oto; | |
376 | this.hos t = h; | |
377 | this.por t = p; | |
378 | this.url Path = url ; | |
379 | } catch (Mal formedURLE xception e ) { | |
380 | throw ne w InvalidO bjectExcep tion(INVAL ID_INSTANC E_MSG + ": " + | |
381 | e.get Message()) ; | |
382 | } | |
383 | ||
384 | } | |
385 | ||
386 | privat e void val idate(Stri ng proto, String h, int p, Str ing url) | |
387 | th rows Malfo rmedURLExc eption { | |
388 | // Check pro tocol | |
389 | fi nal int pr otoEnd = i ndexOfFirs tNotInSet( proto, pro tocolBitSe t, 0); | |
390 | if (protoEnd == 0 || p rotoEnd < proto.leng th() | |
391 | || !alph aBitSet.ge t(proto.ch arAt(0))) { | |
392 | throw ne w Malforme dURLExcept ion("Missi ng or inva lid protoc ol " + | |
393 | "name: \"" + pro to + "\"") ; | |
394 | } | |
395 | ||
396 | // Check hos t | |
397 | va lidateHost (h, p); | |
398 | ||
399 | // Check por t | |
400 | if (p < 0) | |
401 | throw ne w Malforme dURLExcept ion("Bad p ort: " + p ); | |
402 | ||
403 | // Check URL path | |
404 | if (url.leng th() > 0) { | |
405 | if (!url .startsWit h("/") && !url.start sWith(";") ) | |
406 | thro w new Malf ormedURLEx ception("B ad URL pat h: " + url ); | |
407 | } | |
408 | } | |
409 | ||
410 | privat e void val idate() th rows Malfo rmedURLExc eption { | |
411 | va lidate(thi s.protocol , this.hos t, this.po rt, this.u rlPath); | |
412 | } | |
413 | ||
414 | privat e static v oid valida teHost(Str ing h, int port) | |
415 | throws M alformedUR LException { | |
416 | ||
417 | if (h.length () == 0) { | |
418 | if (port != 0) { | |
419 | thro w new Malf ormedURLEx ception("C annot give port numb er " + | |
420 | "w ithout hos t name"); | |
421 | } | |
422 | return; | |
423 | } | |
424 | ||
425 | if (isNumeri cIPv6Addre ss(h)) { | |
426 | /* We as sume J2SE >= 1.4 her e. Otherw ise you ca n't | |
427 | use t he address anyway. We can't c all | |
428 | InetA ddress.get ByName wit hout check ing for a | |
429 | numer ic IPv6 ad dress, bec ause we mu stn't try to do | |
430 | a DNS lookup in case the address is not actua lly | |
431 | numer ic. */ | |
432 | try { | |
433 | Inet Address.ge tByName(h) ; | |
434 | } catch (Exception e) { | |
435 | /* W e should r eally catc h UnknownH ostExcepti on | |
436 | h ere, but a bug in JD K 1.4 caus es it to t hrow | |
437 | A rrayIndexO utOfBounds Exception, e.g. if t he | |
438 | s tring is " :". */ | |
439 | Malf ormedURLEx ception ba d = | |
440 | new Malfor medURLExce ption("Bad IPv6 addr ess: " + h ); | |
441 | EnvH elp.initCa use(bad, e ); | |
442 | thro w bad; | |
443 | } | |
444 | } else { | |
445 | /* Tiny state mach ine to che ck valid h ost name. This | |
446 | check s the host name gramm ar from RF C 1034 (DN S), | |
447 | page 11. A hos tname is a dot-separ ated list of one | |
448 | or mo re labels, where eac h label co nsists of | |
449 | lette rs, number s, or hyph ens. A la bel cannot begin | |
450 | or en d with a h yphen. Em pty hostna mes are no t | |
451 | allow ed. Note that numer ic IPv4 ad dresses ar e a | |
452 | speci al case of this gram mar. | |
453 | ||
454 | The s tate is en tirely cap tured by t he last | |
455 | chara cter seen, with a vi rtual `.' preceding the | |
456 | name. We repre sent any a lphanumeri c characte r by | |
457 | `a'. | |
458 | ||
459 | We ne ed a speci al hack to check, as required by the | |
460 | RFC 2 609 (SLP) grammar, t hat the la st compone nt of | |
461 | the h ostname be gins with a letter. Respectin g the | |
462 | inten t of the R FC, we onl y do this if there i s more | |
463 | than one compon ent. If y our local hostname b egins | |
464 | with a digit, w e don't re ject it. */ | |
465 | final in t hostLen = h.length (); | |
466 | char las tc = '.'; | |
467 | boolean sawDot = f alse; | |
468 | char com ponentStar t = 0; | |
469 | ||
470 | loop: | |
471 | for (int i = 0; i < hostLen; i++) { | |
472 | char c = h.cha rAt(i); | |
473 | bool ean isAlph aNumeric = alphaNume ricBitSet. get(c); | |
474 | if ( lastc == ' .') | |
475 | componentS tart = c; | |
476 | if ( isAlphaNum eric) | |
477 | lastc = 'a '; | |
478 | else if (c == '-') { | |
479 | if (lastc == '.') | |
480 | break; // will t hrow excep tion | |
481 | lastc = '- '; | |
482 | } el se if (c = = '.') { | |
483 | sawDot = t rue; | |
484 | if (lastc != 'a') | |
485 | break; // will t hrow excep tion | |
486 | lastc = '. '; | |
487 | } el se { | |
488 | lastc = '. '; // will throw exc eption | |
489 | break; | |
490 | } | |
491 | } | |
492 | ||
493 | try { | |
494 | if ( lastc != ' a') | |
495 | throw rand omExceptio n; | |
496 | if ( sawDot && !alphaBitS et.get(com ponentStar t)) { | |
497 | /* Must be a numeric IPv4 addr ess. In a ddition to | |
498 | the exp licitly-th rown excep tions, we can get | |
499 | NoSuchE lementExce ption from the calls to | |
500 | tok.nex tToken and NumberFor matExcepti on from | |
501 | the cal l to Integ er.parseIn t. Using exceptions | |
502 | for con trol flow this way i s a bit ev il but it | |
503 | does si mplify thi ngs enormo usly. */ | |
504 | StringToke nizer tok = new Stri ngTokenize r(h, ".", true); | |
505 | for (int i = 0; i < 4; i++) { | |
506 | String ns = tok. nextToken( ); | |
507 | int n = Integer. parseInt(n s); | |
508 | if (n < 0 || n > 255) | |
509 | th row random Exception; | |
510 | if (i < 3 && !to k.nextToke n().equals (".")) | |
511 | th row random Exception; | |
512 | } | |
513 | if (tok.ha sMoreToken s()) | |
514 | throw randomExce ption; | |
515 | } | |
516 | } catch (Exception e) { | |
517 | thro w new Malf ormedURLEx ception("B ad host: \ "" + h + " \""); | |
518 | } | |
519 | } | |
520 | } | |
521 | ||
522 | privat e static f inal Excep tion rando mException = new Exc eption(); | |
523 | ||
524 | ||
525 | /** | |
526 | * <p> The protoc ol part of the Servi ce URL. | |
527 | * | |
528 | * @re turn the p rotocol pa rt of the Service UR L. This i s never nu ll. | |
529 | */ | |
530 | public String ge tProtocol( ) { | |
531 | re turn proto col; | |
532 | } | |
533 | ||
534 | /** | |
535 | * <p> The host p art of the Service U RL. If th e Service URL was | |
536 | * con structed w ith the co nstructor that takes a URL str ing | |
537 | * par ameter, th e result i s the subs tring spec ifying the host in | |
538 | * tha t URL. If the Servi ce URL was construct ed with a | |
539 | * con structor t hat takes a separate host para meter, the result is | |
540 | * the string th at was spe cified. I f that str ing was nu ll, the | |
541 | * res ult is | |
542 | * <co de>InetAdd ress.getLo calHost(). getHostNam e()</code> .</p> | |
543 | * | |
544 | * <p> In either case, if t he host wa s specifie d using th e | |
545 | * <co de>[...]</ code> synt ax for num eric IPv6 addresses, the | |
546 | * squ are bracke ts are not included in the ret urn value here.</p> | |
547 | * | |
548 | * @re turn the h ost part o f the Serv ice URL. This is ne ver null. | |
549 | */ | |
550 | public String ge tHost() { | |
551 | re turn host; | |
552 | } | |
553 | ||
554 | /** | |
555 | * <p> The port o f the Serv ice URL. If no port was | |
556 | * spe cified, th e returned value is 0.</p> | |
557 | * | |
558 | * @re turn the p ort of the Service U RL, or 0 i f none. | |
559 | */ | |
560 | public int getPo rt() { | |
561 | re turn port; | |
562 | } | |
563 | ||
564 | /** | |
565 | * <p> The URL Pa th part of the Servi ce URL. T his is an empty | |
566 | * str ing, or a string beg inning wit h a slash (<code>/</ code>), or | |
567 | * a s tring begi nning with a semicol on (<code> ;</code>). | |
568 | * | |
569 | * @re turn the U RL Path pa rt of the Service UR L. This i s never | |
570 | * nul l. | |
571 | */ | |
572 | public String ge tURLPath() { | |
573 | re turn urlPa th; | |
574 | } | |
575 | ||
576 | /** | |
577 | * <p> The string represent ation of t his Servic e URL. If the value | |
578 | * ret urned by t his method is suppli ed to the | |
579 | * <co de>JMXServ iceURL</co de> constr uctor, the resultant object is | |
580 | * equ al to this one.</p> | |
581 | * | |
582 | * <p> The <code> <em>host</ em></code> part of t he returne d string | |
583 | * is the value returned b y {@link # getHost()} . If that value | |
584 | * spe cifies a n umeric IPv 6 address, it is sur rounded by square | |
585 | * bra ckets <cod e>[]</code >.</p> | |
586 | * | |
587 | * <p> The <code> <em>port</ em></code> part of t he returne d string | |
588 | * is the value returned b y {@link # getPort()} in its sh ortest | |
589 | * dec imal form. If the v alue is ze ro, it is omitted.</ p> | |
590 | * | |
591 | * @re turn the s tring repr esentation of this S ervice URL . | |
592 | */ | |
593 | public String to String() { | |
594 | /* We don't bother syn chronizing the acces s to toStr ing. At w orst, | |
595 | n threads will inde pendently compute an d store th e same val ue. */ | |
596 | if (toString != null) | |
597 | return t oString; | |
598 | St ringBuilde r buf = ne w StringBu ilder("ser vice:jmx:" ); | |
599 | bu f.append(g etProtocol ()).append ("://"); | |
600 | fi nal String getHost = getHost() ; | |
601 | if (isNumeri cIPv6Addre ss(getHost )) | |
602 | buf.appe nd('[').ap pend(getHo st).append (']'); | |
603 | el se | |
604 | buf.appe nd(getHost ); | |
605 | fi nal int ge tPort = ge tPort(); | |
606 | if (getPort != 0) | |
607 | buf.appe nd(':').ap pend(getPo rt); | |
608 | bu f.append(g etURLPath( )); | |
609 | to String = b uf.toStrin g(); | |
610 | re turn toStr ing; | |
611 | } | |
612 | ||
613 | /** | |
614 | * <p> Indicates whether so me other o bject is e qual to th is one. | |
615 | * Thi s method r eturns tru e if and o nly if <co de>obj</co de> is an | |
616 | * ins tance of < code>JMXSe rviceURL</ code> whos e {@link | |
617 | * #ge tProtocol( )}, {@link #getHost( )}, {@link #getPort( )}, and | |
618 | * {@l ink #getUR LPath()} m ethods ret urn the sa me values as for | |
619 | * thi s object. The value s for {@li nk #getPro tocol()} a nd {@link | |
620 | * #ge tHost()} c an differ in case wi thout affe cting equa lity. | |
621 | * | |
622 | * @pa ram obj th e referenc e object w ith which to compare . | |
623 | * | |
624 | * @re turn <code >true</cod e> if this object is the same as the | |
625 | * <co de>obj</co de> argume nt; <code> false</cod e> otherwi se. | |
626 | */ | |
627 | public boolean e quals(Obje ct obj) { | |
628 | if (!(obj in stanceof J MXServiceU RL)) | |
629 | return f alse; | |
630 | JM XServiceUR L u = (JMX ServiceURL ) obj; | |
631 | re turn | |
632 | (u.getPr otocol().e qualsIgnor eCase(getP rotocol()) && | |
633 | u.getHo st().equal sIgnoreCas e(getHost( )) && | |
634 | u.getPo rt() == ge tPort() && | |
635 | u.getUR LPath().eq uals(getUR LPath())); | |
636 | } | |
637 | ||
638 | public int hashC ode() { | |
639 | re turn toStr ing().hash Code(); | |
640 | } | |
641 | ||
642 | /* Tru e if this string, as sumed to b e a valid argument t o | |
643 | * Ine tAddress.g etByName, is a numer ic IPv6 ad dress. | |
644 | */ | |
645 | privat e static b oolean isN umericIPv6 Address(St ring s) { | |
646 | // address c ontains co lon if and only if i t's a nume ric IPv6 a ddress | |
647 | re turn (s.in dexOf(':') >= 0); | |
648 | } | |
649 | ||
650 | // lik e String.i ndexOf but returns s tring leng th not -1 if not pre sent | |
651 | privat e static i nt indexOf (String s, char c, i nt fromInd ex) { | |
652 | in t index = s.indexOf( c, fromInd ex); | |
653 | if (index < 0) | |
654 | return s .length(); | |
655 | el se | |
656 | return i ndex; | |
657 | } | |
658 | ||
659 | privat e static i nt indexOf FirstNotIn Set(String s, BitSet set, | |
660 | int fr omIndex) { | |
661 | fi nal int sl en = s.len gth(); | |
662 | in t i = from Index; | |
663 | wh ile (true) { | |
664 | if (i >= slen) | |
665 | brea k; | |
666 | char c = s.charAt( i); | |
667 | if (c >= 128) | |
668 | brea k; // not ASCII | |
669 | if (!set .get(c)) | |
670 | brea k; | |
671 | i++; | |
672 | } | |
673 | re turn i; | |
674 | } | |
675 | ||
676 | privat e final st atic BitSe t alphaBit Set = new BitSet(128 ); | |
677 | privat e final st atic BitSe t numericB itSet = ne w BitSet(1 28); | |
678 | privat e final st atic BitSe t alphaNum ericBitSet = new Bit Set(128); | |
679 | privat e final st atic BitSe t protocol BitSet = n ew BitSet( 128); | |
680 | privat e final st atic BitSe t hostName BitSet = n ew BitSet( 128); | |
681 | static { | |
682 | /* J2SE 1.4 adds lots of handy m ethods to BitSet tha t would | |
683 | allow us to simplif y here, e. g. by not writing lo ops, but | |
684 | we want t o work on J2SE 1.3 t oo. */ | |
685 | ||
686 | fo r (char c = '0'; c < = '9'; c++ ) | |
687 | numericB itSet.set( c); | |
688 | ||
689 | fo r (char c = 'A'; c < = 'Z'; c++ ) | |
690 | alphaBit Set.set(c) ; | |
691 | fo r (char c = 'a'; c < = 'z'; c++ ) | |
692 | alphaBit Set.set(c) ; | |
693 | ||
694 | al phaNumeric BitSet.or( alphaBitSe t); | |
695 | al phaNumeric BitSet.or( numericBit Set); | |
696 | ||
697 | pr otocolBitS et.or(alph aNumericBi tSet); | |
698 | pr otocolBitS et.set('+' ); | |
699 | pr otocolBitS et.set('-' ); | |
700 | ||
701 | ho stNameBitS et.or(alph aNumericBi tSet); | |
702 | ho stNameBitS et.set('-' ); | |
703 | ho stNameBitS et.set('.' ); | |
704 | } | |
705 | ||
706 | /** | |
707 | * The value ret urned by { @link #get Protocol() }. | |
708 | */ | |
709 | privat e String p rotocol; | |
710 | ||
711 | /** | |
712 | * The value ret urned by { @link #get Host()}. | |
713 | */ | |
714 | privat e String h ost; | |
715 | ||
716 | /** | |
717 | * The value ret urned by { @link #get Port()}. | |
718 | */ | |
719 | privat e int port ; | |
720 | ||
721 | /** | |
722 | * The value ret urned by { @link #get URLPath()} . | |
723 | */ | |
724 | privat e String u rlPath; | |
725 | ||
726 | /** | |
727 | * Cac hed result of {@link #toString ()}. | |
728 | */ | |
729 | privat e transien t String t oString; | |
730 | ||
731 | privat e static f inal Class Logger log ger = | |
732 | ne w ClassLog ger("javax .managemen t.remote.m isc", "JMX ServiceURL "); | |
733 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.