Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate JNLP dynamically

I need to pass argument to JNLP dynamically for which I tried using a servlet which extends JnlpDownloadServlet and then includes a jsp which has all the JNLP XML written into it.

But when I invoke the downloaded JNLP I get BadFieldException.

Servlet

public class TestServlet extends JnlpDownloadServlet {  
public void service(ServletRequest req, ServletResponse res)  throws ServletException, IOException {  
HttpServletRequest request = (HttpServletRequest) req;
res.setContentType("application/x-java-jnlp-file");
request.getRequestDispatcher("/jnlp.jsp").include(request, res);  
}  

jnlp.jsp

Used for dumping dynamic JNLP:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %> href="test.jnlp">
  <information>
   <title>Demo</title>
   <vendor>Sun Microsystems, Inc.</vendor>
  </information>
  <security>
   <all-permissions/>
  </security>
  <resources>
   <j2se version="1.6+" href="http://java.sun.com/products/autodl/j2se"/>
   <jar href="lib/test.jar" main="true" />
  </resources>
  <application-desc name="Dynamic Tree Demo Application" main-class="org.Test" width="300"   height="300">
       <argument><%=request.getParameter("arg1")%></argument>  
       <argument><%=request.getParameter("arg2")%></argument>
  </application-desc>
  <update check="background"/>
</jnlp>

I cannot see the request parameters being received correctly in downloaded JNLP but the above request.getScheme and request.getServerName seem to be working fine. Because of argument value not being received correctly I get BadFieldException when JNLP tries to execute.

How to solve this?

like image 741
Harshdeep Avatar asked Jun 14 '12 18:06

Harshdeep


2 Answers

Logically, href="test.jnlp" should be something like href="test.jnlp?arg1=blah&arg2=tah".

AFAIU the JWS client will reach back to the server using the exact coodebase/href stated in the JNLP.

Also, definitely listen to what bestsss has to say.

like image 82
Andrew Thompson Avatar answered Oct 31 '22 09:10

Andrew Thompson


Maybe to old for being useful but I actually patched the Sun servlet code. There is a Class JnlpFileHandler where the actual substitutions are done.... Just saying... ;-) If anyone is interested I can give you the code including a little explanation. I did not waste too much tima at it but all I can say is that I truly hope the rest of SUN's code is written in a LOT more respect to OO principles...

like image 1
Lawrence Avatar answered Oct 31 '22 08:10

Lawrence