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();
%>