Pass dynamic params via JNLP
Asked Answered
C

2

9

I am using JavaScript in order to execute JNLP which in the end will execute my client.

I am trying to pass parameters via JavaScript execution to the JNLP and having those parameters via JNLP inside my client.

The JavaScript is executing this URL for instance:

http://localhost:8080/MyJnlp.jnlp?login=14hhh765p&pass=ggyyktff

Now my JNLP will try to get the parameters in the <application-desc name tag this way:

<application-desc name="..." main-class="com.main.execute" >
        <argument>-nosplash</argument>
        <argument>-q</argument>
    <argument><%=request.getParameter("login")%></argument>
    <argument><%=request.getParameter("pass")%></argument>
</application-desc>

But it didn't work.

I couldn't retrieve those parameters in my client code this way:

login=getParamsFromJnlp("login")
..

public String getParamsFromJnlp(String key) {
    return System.getProperty(key);
}

The JNLP is inside APACHE2.2

Any idea what's wrong?

Canopus answered 5/12, 2012 at 10:53 Comment(4)
The parameters will be passed as arguments in your main method. I dont know much about apache 2.2, but how do you access the "-nosplash" and "-q" arguments?Kirima
They work fine. the thing is that I want to take params from the query string which executes the JNLP and send them to the command line args in my clientCanopus
you might need to set codebase attribute: check if my answer here applies: #12861947Kirima
Not sure I understood how to add the codebase attribute. could you pass here a full answer please? I remine you the jnlp is placed straight on the Apache server. i dont have any jsp's here..Canopus
K
10

To be able to insert the http-parameters into the argument of your application, the .jnlp file need to be 'constructed' dynamicly on request, because it is not until then you know which http-parameters that will be used.

The way java-web-start works is that it will download the .jnlp several times, but the apart from the first time it will download the file from the url specified in the codebase and href attributes of the jnlp element.

So it is not enough to add the argument-element dynamicly in the element, you also need to add it to the codebase/href attributes

<jnlp spec="1.0+" 
      codebase=<%=request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ request.getContextPath() + "/" %> 
      href="jnlpfile.jnlp&#063;username=<%=request.getParameter("username")%>&clienttoken=<%=request.getParameter("clienttoken")%>">

    ...
    <application-desc main-class="test.MainClass">
       <argument><%=request.getParameter("username")%></argument>
    </application-desc>
</jnlp>
Kirima answered 5/12, 2012 at 12:34 Comment(5)
And I can do this without needing any jsp page?Canopus
I tried it and I got exception: BadFieldException[ The field <jnlp>codebase has an invalid value: <%=request.getScheme(),<%=request.getScheme()]Canopus
Nope, sorry forgot to say this still requires jsp. the only way i know how to do what you want to do is by generating the jnlp dynamicly. Using jsp, php or some other equivalent.Kirima
So where I am going to place this jsp file? I am using Apache.Canopus
I think you need to go for apache tomcat or some other server that supports jsp and servlets :/ #31132 My guess is that you wont be able to achieve what you want to do with apache only :( Atleast not that i knowKirima
S
1

Are you sure if the response type of the JSP is "application/x-java-jnlp-file"?

If not, Please mention it at the top of the JSP and check.

<% response.setContentType("application/x-java-jnlp-file"); %>
Ship answered 5/12, 2012 at 11:7 Comment(2)
I think I dont get it. where the JSP takes place in this scenario? I am executing this via: main-class="com.main.execute and I get straight to this class..Canopus
And on which response are you speaking about?Canopus

© 2022 - 2024 — McMap. All rights reserved.