Skip to main content

Nashorn - Network Access via URLs

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2013-10-18

Is it currently possible to access the network using with Nashorn?

Very standard code (e.g. new URL(url).getContent() that works fine in the normal JVM does not seem to have a content handler, gives a mime-type missing error, and otherwise does not work.

Existing application code libraries which currently work fine in the JVM also seem to fail in the same way within Nashorn.

However, loading files via getClassLoader().getResource() does work so the problem seems to be when trying to access the network to any host, including localhost on a non-privileged port.

I've tried adjusting the security policy to be very lenient (permit all) both in java.policy and programatically via Policy.setPolicy() with a custom policy, but no apparent change.

Is it supposed to work right now? I have an critical path project which depends on this, so any insider help would most appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2013-10-18


[will@localhost ext]$ java -version
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b108)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b50, mixed mode)

I'm using a duck typing strategy with the angular $http object and need a server-side implementation. One version of the url code looks simply like:

$http.success = function(callback) {
console.log("URL: "+this.url);
var url = new;
var conn = url.openConnection();
console.log("CONTENT: "+conn.getContent());,conn);
return this;

The URL used looks like:

Creating loader
Loading execution: 27701236-3540-4c24-b37e-8665d57058d7
URL: http://localhost:9040/api/v1/model/execution/27701236-3540-4c24-b37e-866...

The root cause for this code is:

aused by: no content-type
at jdk.nashorn.internal.scripts.Script$\^eval\_._L17(:24)
at jdk.nashorn.internal.scripts.Script$\^eval\_._L1$_L64(:73)
at jdk.nashorn.internal.scripts.Script$\^eval\_.runScript(:6)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(

Adding any of...


...does not help.

Reading the stream does not return any content.

Joined: 2013-10-18


The apache commons library works fine, so it's only an issue with defaults. Just wrap the code in a nashorn visible package and solve any separate authentication issue.

$http.success = function(callback) {
console.log("URL: "+this.url);
var content =;
console.log("CONTENT: "+content);,JSON.parse(content));
return this;

..."PROXY: "+url);
HttpGet get = new HttpGet(url);
DefaultHttpClient client = new DefaultHttpClient();
try {
HttpResponse response = client.execute(get);
BufferedReader in = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
StringBuilder content = new StringBuilder();
String line = null;
while ((line = in.readLine()) != null) {

10/18/2013 08:22:17 INFO [040-exec-6]: HttpUtils( 59): PROXY: http://localhost:9040/api/v1/model/execution/27701236-3540-4c24-b37e-866...
10/18/2013 08:22:17 INFO [040-exec-7]: TokenAuthenticationFilter( 82): Token authenticated: 559612ad386cda0dabebba61e4e3c845 system (
10/18/2013 08:22:17 INFO [040-exec-4]: TokenAuthenticationFilter( 82): Token authenticated: 559612ad386cda0dabebba61e4e3c845 system (
10/18/2013 08:22:17 INFO [040-exec-6]: HttpUtils( 73): RESPONSE: 880 (200,OK)
"id" : "27701236-3540-4c24-b37e-8665d57058d7",

...feel free to either answer this one more fully or close.