tags:

views:

28

answers:

2

I have a JSP that spits out a JNLP file as shown below. Work son localhost, when deployed to a remote server, Java Web Start errors out with an exception -

Unable to load resource: http : // localhost:8080/jnlp/myjnlp.jnlp

ExitException[ 3]com.sun.deploy.net.FailedDownloadException: Unable to load resource: http: // localhost:8080/jnlp/myjnlp.jnlp
 at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
 at com.sun.javaws.Launcher.updateFinalLaunchDesc(Unknown Source)
 at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
 at com.sun.javaws.Launcher.prepareToLaunch(Unknown Source)
 at com.sun.javaws.Launcher.launch(Unknown Source)
 at com.sun.javaws.Main.launchApp(Unknown Source)
 at com.sun.javaws.Main.continueInSecureThread(Unknown Source)
 at com.sun.javaws.Main$1.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)

The included JNLP file is getting its codebase line replaced based on server's URL. Attaching a debugger to the JSP show sthe correct codebase line with server's IP /Host name.

Don't understand where the localhost comes from ?

<%@ page import="java.io.*" %>
<%@ page contentType="application/x-java-jnlp-file" language="java" %>
<%
  response.setHeader("Cache-Control", "no-cache");
  response.setHeader("Pragma", "no-cache");
  response.setDateHeader("Expires", -1);
  response.setContentType("application/x-java-jnlp-file");

// Generating the codebase for the JNLP. This URL will be used for downloading this jsp and the jar
  StringBuffer jspUrlsb = request.getRequestURL();
  String url = jspUrlsb.substring(0,jspUrlsb.lastIndexOf("/"));
  url = url.substring(0,url.lastIndexOf("/"));
  String jnlpCodebase =  url+ "/jnlp/";

  String tool = request.getParameter("tool");
  tool = tool==null || tool.length()==0 ? "myjnlp" : tool;

  String jnlpFile =  tool+".jnlp";
  response.setHeader("Content-Disposition", "filename=\""+jnlpFile+"\";");


  String path = config.getServletContext().getRealPath(request.getContextPath());

  FileInputStream fis = new FileInputStream(new File(path,"/jnlp/"+jnlpFile));
  InputStreamReader isr = new InputStreamReader(fis);
  BufferedReader br = new BufferedReader(isr);

  String line = null;
  while ((line = br.readLine()) != null) {  //consuming the stream
    if (line.startsWith("<jnlp")) {
      line =  "<jnlp  codebase=\""+jnlpCodebase+"\" href=\""+jnlpFile+"\" spec=\"6.0+\">";
    }
%>
    <%=line%>
<%
  }
  br.close();
  isr.close();
  fis.close();
%>
A: 

Don't understand where the localhost comes from ?

I believe it comes from the JNLP file that is cached locally. There are various ways to test this theory, some more reliable than others.

1) Try the web version on a PC never used in testing on the localhost.

For the development machine itself.

2) Uninstall the application from the Java Cache before launching the 'live' web based version. Or..

3) Move the cache entirely, for the purposes of each test.


As two asides..

I was not clear from the code snippets above whether the JNLP href was being written to the response. If it is, remove it. It is usually both unnecessary and counterproductive to include the href in a dynamically generated JNLP.

Please edit your post to format the input/output, code/code snippets, HTML/XML as code.

Andrew Thompson
I tried all that but didn't work, hardwiring the codeBase was the only way out :-(
Rachel Burns
A: 

Despite using Java 6u21 i was forced to hardwire the codebase. This was supposed to have been fixed in update 18+ but didn't work for me. After hardwiring the codebase URL it works.

Rachel Burns