User-agent-utils

The user-agent-utils java library can be used to parse HTTP requests in real-time or to analyze log files and gather information about the user-agent.

Warning: This project is end-of-life and does not get updated any longer!
As alternative have a look at the Browscap project and its implementations.

Features

Fast detection of:

By not trying to identify hundreds or even thousands of different clients and operating systems it tries to offer a compromise between performance and usability. Other libraries (some commercial) offer a more detailed detection.

Download

For the latest release, go to https://github.com/HaraldWalker/user-agent-utils/tree/release-1.21
For the latest snapshot version, go to https://github.com/HaraldWalker/user-agent-utils

Maven

Add dependency:

<dependency>
   <groupId>eu.bitwalker</groupId>
   <artifactId>UserAgentUtils</artifactId>
   <version>1.21</version>
</dependency>

If you need more frequent updates, using the snapshot version is another option:

<dependency>
   <groupId>eu.bitwalker</groupId>
   <artifactId>UserAgentUtils</artifactId>
   <version>1.22-SNAPSHOT</version>
</dependency>

Usage

Pass the user-agent string from the request as parameter to the parser.

UserAgent userAgent = UserAgent.parseUserAgentString(request.getHeader("User-Agent"));

FAQ

Can I add new browsers or operating systems?

Unfortunately not directly. This library uses enums to represent browsers and operating systems to make using it easy and readable. Unfortunately the use of enums also has some disadvantages. You can make a pull request on trunk for a new browser or operating system if all tests are still passing.  The purpose of this library was and is not to detect every possible version.

Where can I report bugs or make feature requests?

This project is not accepting issues or change requests any longer. Feel free to fork it, make your own changes and release updates yourself.

How can I improve the performance of the user-agent parsing?

When handling requests on a web-server, consider if you need both the browser and operating system or if one of the two gives you enough information. As the parsing uses an ordered tree structure, performance depends a lot on the type of clients making the requests. The most common browsers and operating systems will be parsed faster than exotic ones. Consider caching the results temporarily.

Are there other libraries like this?

When I started this project in 2010 there were no other libraries offering the features I was looking for. Currently there are both open source as well as commercial solutions.

Should I use this library for my web-project?

Depends on your use case. Libraries like these depend on the user-agent string a client like a web-browser sends with a request but many of those clients actually lie about their true identity. That makes it a guessing game with a certain error rate. On websites it is a better approach to detect features using a javascript library like Modernizr.
This library is useful in situations where you can not use javascript to learn more about the client.

Implementing libraries

Grails Browser Detection Plugin

Products and projects that use this library

RapidClipse Framework
Comcast Dawg
ARI Commerce
MOLGENIS