What's Covered
This tutorial demonstrates how to extend the BaseServlet to use device detection capabilities. The BaseServlet gives access to the 51Degrees WebProvider class that manages temporary data files whilst providing the same device detection capabilities as the Core provider. You need to run this example from a Java Web project servlet. Maven project on github contains a full version of this example, ready to run.
The BaseServlet takes care of instantiating the provider and managing the data file. If you wish to use device detection but do not want to extend the BaseServlet provided by 51Degrees, you will need to manually instantiate the provider and implement the mechanisms to manage temporary files for using automatic updates with StreamMode. Other services like the image optimiser and bandwidth monitoring can still be accessed by configuring listeners. See Web.xml configuration for further details.
Code and Explanation
Returns a page with predefined properties, match metrics information and a list of the relevant HTTP headers used for the detection.
Device detection functionality becomes available upon extending the 51Degrees BaseServlet from the WebApp module.
public class Example extends BaseServlet {
This example servlet outputs a similar page to that of the other 51Degrees APIs.
WebApp module provides access to the WebProvider which extends the Core Provider, hence allowing access to the same set of features you can use for offline device detection. To access property:
Property pr = super.getProvider(request).dataSet.get("IsMobile");
The WebProvider’s role is to manage the temporary data files. In the Servlet environment it is not always possible to stop device detection to update the data file, by using temporary files the master file can be kept free of write locks.
As of version 3.2 the Lite data file is no longer embedded in the API. Please remember to specify the BINARY_FILE_PATH in the Web.xml and ensure the data file is placed there.
Summary
This tutorial demonstrated how to extend the BaseServlet to access device detection capabilities. The example produced a sample page with a pre-defined set of properties displaying match metrics, relevant headers plus a table with properties and values. Properties include both Lite and Premium properties.
Using Premium and Enterprise data gives you access to considerably more properties as well as features like automatic data updates:
Feature | Lite | Premium | Enterprise |
---|---|---|---|
Automatic Data Updates | No | Weekly | Daily |
JavaScript | Yes | Yes | Yes |
Image Optimiser | Yes | Yes | Yes |
Client Side Overrides | No | No | Yes |
PerformanceMonitoring | No | No | Yes |