This discussion is archived
2 Replies Latest reply: Mar 20, 2012 2:51 PM by EJP RSS

Trasnfering data from a JNLP call to swing dynamically

698529 Newbie
Currently Being Moderated
Is there a way to transfer the content of a parameter from jnlp request to the swing application dynamically?

Like:

jnlp url: http://javawebstart/foo.jnlp?ticket=123

And from inside my swing application I could retrieve the value of the parameter ticket?

Thanks. Mauro

Edited by: Mauro Flores on 20/03/2012 06:02
  • 1. Re: Trasnfering data from a JNLP call to swing dynamically
    698529 Newbie
    Currently Being Moderated
    Compiling the information of the sites below

    http://docs.oracle.com/javase/6/docs/technotes/guides/javaws/developersguide/syntax.html#resources
    http://www.coderanch.com/t/200653/JNLP-Web-Start/java/create-Dynamic-jnlp-files

    I got a solution:


    =======
    jnlp servlet
    =======
    public void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
    InputStream din;
    String ticket = req.getParameter("ticket");
    din = this.getClass().getResourceAsStream("teste.jnlp");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte b[] = new byte[1024];
    while (din.read(b) > 0) {
    baos.write(b);
    }
    din.close();
    String jnlpString = new String(b);
    baos.close();
    jnlpString = jnlpString.replace("${ticket}", ticket);
    String attachment = "inline; filename=\"temp-unique-jnlp-" + System.currentTimeMillis() + ".jnlp\"";
    response.setContentType("application/x-java-jnlp-file");
    response.setHeader("Cache-Control", "max-age=30");
    response.setHeader("Content-disposition", attachment);
    OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream());
    out.write(jnlpString);
    out.flush();
    out.close();
    }


    ========
    teste.jnlp file
    ========
    <jnlp spec="1.0+" codebase="http://localhost:7001/xyz">
         <information>
              <title>teste</title>
              <description>Teste</description>
              <offline-allowed />
         </information>
         <security>
              <all-permissions />
         </security>
         <resources>
              <j2se version="1.4+" java-vm-args="nome"/>
              <jar href="jnlpteste.jar" />
         </resources>
         <application-desc main-class="teste.JNLPTest">
         <argument>${ticket}</argument>
    </application-desc>
    </jnlp>

    ==========
    swing applicaton
    ==========

    public class JNLPTest {
    public static void main(String args[]) {

    JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    String txt;
    if (args.length > 0) {
    txt = args[0];
    } else {
    txt = "";
    }

    JLabel label = new JLabel("Ticket: " + txt);
    content.add(label, BorderLayout.CENTER);
    frame.setSize(200, 200);
    frame.setVisible(true);
    }
    }
  • 2. Re: Trasnfering data from a JNLP call to swing dynamically
    EJP Guru
    Currently Being Moderated
    String jnlpString = new String(b);
    That should be:

    String jnlpString = new String(baos.toArray());

    And it should be after baos.close().

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points