public class DeviceApiWeb extends DeviceApi
A small extension to the core DeviceApi to permit passing of an HttpServletRequest object.
When detecting a user's device in real-time on a website in a servlet container it is strongly recommend to use the DeviceApiWeb library and getProperties as shown bellow.
The getProperties of DeviceApiWeb, automatically detects the availability of the client side properties and will use them for detection. If you want to have a more accurate detection (especially for apple devices) or have the client side properties included in the property sets, simply include the DeviceAtlas Client-side component JavaScript library in the web pages.
The getProperties() method in this class extracts the most suitable headers from a passed HttpServletRequest object.
DeviceApiWeb deviceApi = new DeviceApiWeb(); // loading data is expensive and slow - it is recommended to store loaded API in the servlet context try { deviceApi.loadDataFromFile("/path/to/datafile.json"); // get all properties from the HTTPServletRequest object Properties properties = deviceApi.getProperties(request); // .... use the properties .... if (properties.contains("mobileDevice", true)) { if (properties.containsKey("model")) { String deviceModel = properties.get("model").asString(); } } } catch (...
API_VERSION
Constructor and Description |
---|
DeviceApiWeb()
Constructs a DeviceApiWeb instance with default config.
|
DeviceApiWeb(Config config)
Constructs a DeviceApiWeb instance with custom config.
|
Modifier and Type | Method and Description |
---|---|
Properties |
getProperties(javax.servlet.http.HttpServletRequest request)
Get the Device properties for the given HttpServletRequest object.
|
getApiVersion, getDataCreationIso8601, getDataCreationTimestamp, getDataVersion, getDeviceAtlasApiVersion, getProperties, getProperties, getProperties, getProperties, getPropertyNames, loadDataFromClassPath, loadDataFromFile, loadDataFromStream
downloadAndLoadDataFile, downloadAndLoadDataFile, getDetectionLookupCount, isDataFileReload, resetDetectionLookupCount
public DeviceApiWeb()
Config
.Config
public DeviceApiWeb(Config config)
config
- An instance of Config, you can change the DeviceAtlas API config
by creating an instance or Config and setting your custom config values
then passing the instance to the DeviceApiWeb constructor.Config
public Properties getProperties(javax.servlet.http.HttpServletRequest request) throws ClientPropertiesException
Config
.
Depending on the config the properties may include User-Agent dynamic
properties and language/locale properties.request
- The request object to find the most suitable headers.ClientPropertiesException
Copyright © 2023 DeviceAtlas Limited. All rights reserved.