tags:

views:

578

answers:

5

I want to distribute a webstart application which uses RMI.

I want to avoid to ask the user the address of the RMI server, because the website that distributes the application is also the RMI server.

Furthermore, I don't know the address of the server at build time, therefore the address must be added with ad hoc configuration to the JNLP, or the address must be provided at execution time. This is the preferred way: is it possible to do so?

+1  A: 

I haven't used Java RMI exactly (I've only used Java Web Start with Hessian binary protocol for doing something like RMI), but at least the part of passing the server address to the Web Start client app should be easy. When you generate the JNLP file in your application, add the address as a property:

<jnlp>
  [...]
  <resources>
    [...]
    <property name="serverAddress" value="..." />
  </resources>
</jnlp>

Then, in client code read that property:

String serverAddress = System.getProperty("serverAddress");

I assume here the website that distributes the application knows its own address :)

Edit (with the additional limitation of not knowing address at build time): Hmm, Is the website distributing the app a dynamic or static one?

  1. dynamic: either generate whole JNLP dynamically (with a JSP page or dom4j or whatever), or read the "template" JNLP XML file and replace the real server address in place
  2. static: I guess the person who deploys the site has to manually configure the right address in the JNLP file?
Jonik
Thanks! I changed the question according to your answer to more completely reflect my needs.
michelemarcon
And in conjunction with the JnlpDownloadServlet (http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/downloadservletguide.html), you can easily write: ... value="$$codebase".
Tobias Schulte
A: 

I use variable placeholders in my jnlp:

...
<application-desc>
    <argument>{host}</argument>
    <argument>{port}</argument>
</application-desc>
...

And use an Interceptor servlet to replace these at run time as the JNLP is served to the client.

+1  A: 

Where I work we do exactly this, and put the hostname of the RMI registry in the JNLP as per Jonik's answer. In Java 6u10 or u11 Sun closed several security holes with Webstart, including an issue with dynamic JNLP. In order to satisfy all the security warnings you must place an identical copy of your JNLP in the main jar of your program. This is to prevent third parties injecting extra jars or parameters into your code. Programs will run without it, but users will be shown a trust notice.

We do know the address at build time, but had other dynamic JNLP issues and so had to resort to providing a JNLP and a JAR for each possible runtime set-up. This was more of a deployment headache for us, rather than an issue for customers, but if you're signing your distribution then it's worth knowing.

banjollity
+1  A: 

The JDK includes source code (in the samples/jnlp/servlet directory) for a servlet that inserts appropriate values into the JNLP file. You can use this to insert the host name into the JNLP file.

Dan Dyer
A: 

I have the same issue, and the concept of the Interceptor servlet is a clean approach. But how did you do this... Did you had any issues with the JNLP download servlet?

WesleyN