JGridstart/Java user agents

From PDP/Grid Wiki
Revision as of 10:20, 14 April 2010 by Wvengen@nikhef.nl (talk | contribs) (add user agent note)
Jump to navigationJump to search

It is possible to detect on the server-side something about the user's Java environment by inspecting the request headers that Java sends. There are differences when a connection is made from the Java program using URLConnection, or when a Java Web Start application is being downloaded.

Java Web Start

Vendor HTTP Header
User-Agent UA-Java-Version
Sun JNLP/1.5 javaws/1.5.0_19 (b02) J2SE/1.5.0_19 1.5.0_19
Sun JNLP/6.0 javaws/1.6.0_17 (b04) Java/1.6.0_17 1.6.0_17
OpenJDK Java/1.6.0_0 (not supplied)

URLConnection

Vendor HTTP header User-Agent
Sun Java/1.5.0_19
Sun Java/1.6.0_17
OpenJDK Java/1.6.0_0

Setting the user-agent from Java

jGridstart sets the user-agent so that it can be recognised by the web server, including its version number. This is done by setting the system property http.agent (Java still appends something like Java/1.6.0_10 to it).

There is a little problem with java web start. When the system property http.agent is set from within a java web start application, it is not actually used when a http connection is made. This can be remedied by either setting the property from the JNLP file, or by setting the request property User-Agent on the URLConnection. jGridstart uses this as a workaround:

 static URLConnection URLopenConnection(URL url) throws IOException {
   URLConnection conn = url.openConnection();
   if (conn instanceof HttpURLConnection) {
     String agent = System.getProperty("http.agent") +
                      " Java/"+System.getProperty("java.version");
     if (agent != null)
       ((HttpURLConnection)conn).setRequestProperty("User-Agent", agent);
   }
   return conn;
 }

See also specifics under Java Web Start.