51DegreesTM

Device detection with Java offline or Web application

Engineering

4/15/2015 2:33 PM

Development

How to integrate the API and implement the auto update.

51Degrees is the fastest and most efficient device detection solution to date that also has a low memory footprint and an easy auto update functionality built into the API. The most common use for the Java library is with Servlets. But what if you have an offline project that requires auto update functionality or a custom Web server? Check out how easy it is to integrate the API and use the automatic device data file updates.

Introduction

The Servlet implementation of our Java device detection API takes care of quite a few things for you. It manages temporary files, checks for the device data update if you provide a licence key. When integrating the API with your online or offline project it is is important to take these factors in to account.

Summary

The project consists of server and client. Both are independent of each other. Client makes a request to the server and expects a custom HTTP header called "Type" to be returned by the server. Server implements a thread pool with each request being added to the work queue and processed independently. Each thread sets a custom HTTP header called 'Type' that contains DeviceType derived by invoking the 51Degrees device detection functionality.

The detector module implements both the detection and the auto update functionality. Auto update makes use of a timer to initiate the auto update task which in turn downloads the new data file and propagates the updated data to the Provider object.

Implementing Client

The sole purpose of the client in this context is to make requests to the server to emulate some user activity. Changing the number of threads in the thread pool you can influence the requests per second the server will have to deal with. Client consists of 3 classes:

  • Client.java used to set up and process a queue of Request objects to be executed by the thread pool.
  • ConnectionSupportClass.java used to download the file with million user agent strings from 51Degrees.com, uncompress the file and organise the user agents in to an array list.