Looking for a Java User Agent String Parser

Bill picture Bill · Sep 29, 2009 · Viewed 21.9k times · Source

Does anyone know of a great library in java for parsing user agent strings? We have written a custom one, but this seems like a common problem for many people. I would guess there is a good library available somewhere.

For example, the user agent string...

"Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.21 Safari/532.0"

... cryptically announces the arrival of a Windows Vista PC using Chrome on our site.

I've seen libraries in python and ruby. Anything in java out there?

Answer

before picture before · May 8, 2012

Yet try a new library that is updated monthly and available in The Central Repository: http://uadetector.sourceforge.net/

It is another wrapper for user-agent-string.info, but with a much more solid and tested implementation compared to the other ones.

I'm working on a stable API 1.0 which I want to release at the end of this year. After the release of API 1.0 you don't have to recompile anything. You only switch the uadetector-resources.jar in your applications lib dir. The feature 'updated monthly' means, if you want an integration tested 'UAS data' file, for which you have the guarantee that it runs with the defined core, than this one fit your needs. But if you are not interested in updating a JAR (that is tested by me), then you can use the OnlineUserAgentStringParser with the risk, that the implementation doesn't fit to run with the automatically downloaded XML. I'm not interested in releasing more 'uadetector-core' bundles as needed, especially when the API in version 1.0 is released.

Another solution for a client might be that he maintains the 'UAS data' for it's own, when he works with the OnlineUserAgentStringParser and customize the properties file to set the right URL.