Scenario 1, exploiting JRE from non-Java (Re: Minor thoughts (Re: [External] : Re: JEP draft: Prepare to Restrict The Use of JNI
Rony G. Flatscher
Rony.Flatscher at wu.ac.at
Tue Sep 5 09:53:23 UTC 2023
Consider the following ooRexx program that exploits the JRE (the Java classes available via the Java
runtime environment, installed by OpenJDK):
/* purpose: demonstrate how to fetch and list all links with jsoup */
parse arg source -- command line argument: can be html, xml; a local file or URL
url? = source ~startsWith("http") -- do we need to parse a URL?
timeout = 10000 -- timeout: 10 sec (10000 msec)
if url? then src=.bsf~new("java.net.URL", source) -- create URL object
else src=.bsf~new("java.io.File", source) -- create File object
clzJsoup = bsf.importClass("org.jsoup.Jsoup") -- import Jsoup class
if url? then rootNode = clzJsoup~parse(src, 10000) -- timeout: 10 second
else rootNode = clzJsoup~parse(src)
allLinks = rootNode~select("a") -- get all a-elements
len=length(allLinks~size) -- get length of size for right-adjusting
say "there are" pp(allLinks~size) "links"
do counter c link over allLinks -- iterate over the collection (ArrayList)
-- say "#" c~right(len)":" pp(link~absURL('href')) "for" pp(link~text)
say "#" c~right(len)":" pp(link~attr('href')) "for" pp(link~text)
end
::requires "BSF.CLS" -- get ooRexx-Java bridge
/* purpose: demonstrate how to fetch and list all links with jsoup */
parse arg source -- command line argument: can be html, xml; a local file or URL
url? = source ~startsWith("http") -- do we need to parse a URL?
timeout = 10000 -- timeout: 10 sec (10000 msec)
if url? then src=.bsf~new("java.net.URL", source) -- create URL object
else src=.bsf~new("java.io.File", source) -- create File object
clzJsoup = bsf.importClass("org.jsoup.Jsoup") -- import Jsoup class
if url? then rootNode = clzJsoup~parse(src, 10000) -- timeout: 10 second
else rootNode = clzJsoup~parse(src)
allLinks = rootNode~select("a") -- get all a-elements
len=length(allLinks~size) -- get length of size for right-adjusting
say "there are" pp(allLinks~size) "links"
do counter c link over allLinks -- iterate over the collection (ArrayList)
-- say "#" c~right(len)":" pp(link~absURL('href')) "for" pp(link~text)
say "#" c~right(len)":" pp(link~attr('href')) "for" pp(link~text)
end
::requires "BSF.CLS" -- get ooRexx-Java bridge
The result of running the above program against http://openjdk.net
E:\WU\Lehrveranstaltungen\Materialien\BP2_AutoJava\254_AutoJava_jsoup_code>rexx jsoup_05.rxj
http://openjdk.org
there are [132] links
# 1: [https://www.oracle.com/technetwork/java/javase/overview/index.html] for [Java Platform,
Standard Edition]
# 2: [projects/jdk/20] for [latest open-source JDK]
# 3: [https://jdk.java.net/20] for [jdk.java.net/20]
# 4: [https://www.oracle.com/technetwork/java/javase/downloads/index.html] for [here]
# 5: [projects/amber] for [Amber]
# 6: [https://wiki.openjdk.org/display/loom/Main] for [Loom]
# 7: [projects/panama] for [Panama]
# 8: [https://wiki.openjdk.org/display/valhalla/Main] for [Valhalla]
# 9: [projects/jdk/19] for [the next version of Java and the JDK]
# 10: [https://dev.java] for [dev.java]
... cut ...
# 119: [/projects/tiered-attrib] for [Tiered Attribution]
# 120: [/projects/tsan] for [Tsan]
# 121: [/projects/type-annotations] for [Type Annotations]
# 122: [/projects/valhalla] for [Valhalla]
# 123: [/projects/verona] for [Verona]
# 124: [/projects/visualvm] for [VisualVM]
# 125: [/projects/wakefield] for [Wakefield]
# 126: [/projects/zero] for [Zero]
# 127: [/projects/zgc] for [ZGC]
# 128: [https://oracle.com] for []
# 129: [/legal/tou/] for [Terms of Use]
# 130: [/legal/gplv2+ce.html] for [GPLv2]
# 131: [https://www.oracle.com/us/legal/privacy/] for [Privacy]
# 132: [https://openjdk.org/legal/openjdk-trademark-notice.html] for [Trademarks]
This program runs on all versions of Java/OpenJDK unchanged.
With your currently intended warning all of a sudden all users of such programs/applications get
frightened for no good reason!
---rony
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk-dev/attachments/20230905/ea40998c/attachment-0001.htm>
More information about the jdk-dev
mailing list