简体   繁体   中英

How should I configure my JNLP file with JAR files for an Amazon S3 bucket (dynamic IP address CDN)?

I have an Amazon S3 bucket that holds my .jar files for my Java application. And I have a web server that dynamically creates and serves up a JNLP file that points to this Amazon S3 bucket for the codebase.

The JNLP seems to be able to download the .jar files correctly from my Amazon S3 bucket. But when trying to launch, I get the following exception:

ExitException[ 3]java.io.IOException: Cannot find cached resource for URL: http://s3.amazonaws.com/....     
      at sun.plugin2.applet.JNLP2Manager.prepareLaunchFile(Unknown Source)  
      at sun.plugin2.applet.JNLP2Manager.loadJarFiles(Unknown Source)   
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)  
      at java.lang.Thread.run(Unknown Source)

Does Java cache the .jar files with the IP address? Earlier in the java log, the following is printed: "cache: CacheEntry IP mismatch: 207.171.189.80 != 207.171.187.117". Both IPs resolve to S3.

I'm kind of surprised I'm getting this issue and would think this is a common problem but cannot find a good solution. If I stick the IP address in the JNLP file:

<jnlp spec="1.0" xmlns:jfx="http://javafx.com" codebase="http://207.171.189.80/...

instead of:

<jnlp spec="1.0" xmlns:jfx="http://javafx.com" codebase="http://s3.amazonaws.com/...

it works everytime. Otherwise, it usually breaks with the above exception.

Does anyone know a good solution for this? Thanks.

Does the s3 hostname based version of your JNLP file sometimes work? If yes - I expect the cause is the short time-to-live values on Amazon's S3 hostnames.

Right now "A" records expire after only 30 seconds. This could mean that between HTTP requests to S3 for each JAR file, the DNS cache expires. So the next JAR request will cause another DNS lookup.

I noticed that DNS for S3 returns only one IP address, but it then rotates after 30 seconds.

% dig s3.amazonaws.com
;; ANSWER SECTION:
s3.amazonaws.com.        229        IN CNAME   s3.a-geo.amazonaws.com.
s3.a-geo.amazonaws.com.  213        IN CNAME   s3-1.amazonaws.com.
s3-1.amazonaws.com.      28         IN A       176.32.100.200

I'm not sure about JNLP, but generally Java is very picky about ensuring that JAR files are all loaded from the same "source". I'd guess Java, in this context, wants the "source" to mean "same IP address".

Worst case, you could try dynamically generating your JNLP, putting it into S3 in real time, then directing your clients to get the full bundle from there?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM