public class Client
extends java.lang.Object
// HttpServletRequest request: Request object from Servlet container first use Client client = Client.getInstance(CacheProvider); following use Client client = Client.getInstance(); client.setLicenceKey("DeviceAtlas-licence-key"); try { Result results = client.getResult(request); } catch (Exception x) { // handle exceptions etc... } // The useragent used in the lookup String ua = results.getHeaders().get(ClientConstants.KEY_USERAGENT.toString()); // The source of the data - cache, cloud etc String dataSource = results.getSource(); // The actual device properties Properties properties = results.getProperties();
Mapheaders = new HashMap (); // get data by passing headers (headers named are not case sensitive and may include "_" or start with "HTTP_") headers.put("User-Agent", "Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95_8GB/15.0.015; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413"); headers.put("X-Profile", "http://nds.nokia.com/uaprof/NN95_8GB-1r100.xml"); headers.put("Accept", "text/html,text/css,multipart/mixed,application/java-archive, application/java"); headers.put("Accept-Language", "en-us,en;q=0.5"); Client client = Client.getInstance(); try { Result results = client.getResultByHeaders(headers); } catch (Exception x) { // handle exceptions etc... } // The useragent used in the lookup String ua = results.getHeaders().get(ClientConstants.KEY_USERAGENT.toString()); // The source of the data - cache, cloud etc String dataSource = results.getSource(); // The actual device properties Properties properties = results.getProperties();
Client client = Client.getInstance(); String ua = "Mozilla/5.0 (SymbianOS/9.2; U; Series60/3.1 NokiaN95_8GB/15.0.015; Profile/MIDP-2.0 Configuration/CLDC-1.1 ) AppleWebKit/413 (KHTML, like Gecko) Safari/413"; try { Result results = client.getResultByUserAgent(ua); } catch (Exception x) { // handle exceptions etc... } // The useragent used in the lookup String ua = results.getHeaders().get(ClientConstants.KEY_USERAGENT.toString())); // The source of the data - cache, cloud etc String dataSource = results.getSource(); // The actual device properties Properties properties = results.getProperties();Copyright (c) 2021 by DeviceAtlas Limited. All rights reserved.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
API_VERSION
Deprecated.
|
static java.lang.String |
CLIENT_COOKIE_HEADER
Deprecated.
|
static java.lang.String |
CLIENT_COOKIE_NAME
Deprecated.
|
static java.lang.String |
DA_HEADER_PREFIX
Deprecated.
|
static java.lang.String |
KEY_PROPERTIES
Deprecated.
|
static java.lang.String |
KEY_SOURCE
Deprecated.
|
static java.lang.String |
KEY_USERAGENT
Deprecated.
|
static java.lang.String |
SOURCE_CACHE
Deprecated.
|
static java.lang.String |
SOURCE_CLOUD
Deprecated.
|
static java.lang.String |
SOURCE_NONE
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
clearCache()
Clear all cached data.
|
java.lang.Object |
clone()
This throws an exception to prevent cloning this singleton.
|
boolean |
getAutoServerRanking()
Getter for auto server ranking.
|
int |
getAutoServerRankingLifetime()
Deprecated.
As of release 1.5 getAutoServerRankingLifetime() and
getAutoServerRankingLifetime() have been merged.
|
int |
getAutoServerRankingMaxFailures()
Getter for max server failures.
|
int |
getAutoServerRankingNumRequests()
When auto ranking end-points, this number of requests will be sent to each
end-point and the mean time will be used for ranking the end-point.
|
CacheService |
getCacheService()
Returns the cache layer
|
int |
getCloudServiceTimeout()
Getter for cloud service timeout.
|
java.lang.String |
getCloudUrl()
Get the last DeviceAtlas cloud service end-point (server) URL called to
get device properties
|
java.util.Map |
getDeviceData(javax.servlet.http.HttpServletRequest request)
Deprecated.
|
java.util.Map |
getDeviceData(java.util.Map<java.lang.String,java.lang.String> headers)
Deprecated.
|
java.util.Map |
getDeviceData(java.lang.String userAgent)
Deprecated.
|
java.util.Map |
getDeviceDataByHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Deprecated.
|
java.util.Map |
getDeviceDataByUserAgent(java.lang.String userAgent)
Deprecated.
|
DeviceIdentificatorService |
getDeviceIdentificatorService()
Returns the identificator layer
|
EndPoint[] |
getEndPoints()
Getter for cloud server list.
|
EndPointService |
getEndPointService()
Returns the endPoint layer
|
static Client |
getInstance() |
static Client |
getInstance(CacheProvider cacheProvider)
Get the instance for the Client
|
static Client |
getInstance(CacheService cacheService)
Get the instance for the Client
|
java.lang.String |
getLicenceKey()
Getter for DeviceAtlas cloud licence key.
|
int |
getPhaseOutLifetime()
Deprecated.
As of release 1.5 getServerPhaseOutLifetime() and
getAutoServerRankingLifetime() have been merged.
|
java.lang.String |
getRankingStatus() |
Result |
getResult(javax.servlet.http.HttpServletRequest request)
Get the cloud service data from the identificator layer
|
Result |
getResult(java.util.Map<java.lang.String,java.lang.String> headers)
Get the cloud service data from the identificator layer
|
Result |
getResult(java.lang.String userAgent)
Get the cloud service data from the identificator layer
|
Result |
getResultByHeaders(java.util.Map<java.lang.String,java.lang.String> headers)
Get the cloud service data from the identificator layer
|
Result |
getResultByUserAgent(java.lang.String userAgent)
Get the cloud service data from the identificator layer
|
boolean |
getSendExtraHeaders()
Getter for the sendExtraHeaders setting.
|
int |
getServerRankingLifetime()
Returns the server ranking cache lifetime
|
EndPoint[] |
getServersLatencies()
Get DeviceAtlas cloud end-point list.
|
EndPoint[] |
getServersLatencies(int numRequests)
Get endPoints and their service latencies.
|
boolean |
getUseCache()
Is device data being cached by the API or not.
|
boolean |
getUseClientCookie()
Getter for the useClientCookie setting.
|
static java.lang.String |
getVersion()
Get the API version
|
EndPoint[] |
rankServers()
If auto-ranking is on then rank the DeviceAtlas cloud end-points and put in cache.
|
void |
setAutoServerRanking(boolean autoServerRanking)
Setter for auto server ranking.
|
void |
setAutoServerRankingLifetime(int serverRankListLifetime)
Deprecated.
As of release 1.5 setAutoServerRankingLifeTime() and
setAutoServerRankingLifetime() have been merged.
|
void |
setAutoServerRankingMaxFailures(int autoServerRankingMaxFailures)
Setter for max server failures.
|
void |
setAutoServerRankingNumRequests(int autoServerRankingNumRequests)
When auto ranking end-points, this number of requests will be sent to each
end-point and the mean time will be used for ranking the end-point.
|
void |
setCloudServiceTimeout(int cloudServiceTimeout)
Setter for cloud service timeout.
|
void |
setCloudUrl(java.lang.String lastUsedCloudUrl)
Sets the last endpoint url used when call the service
|
void |
setEndPoints(EndPoint[] endPoints)
Setter for cloud server list.
|
void |
setLicenceKey(java.lang.String licenceKey)
Setter for DeviceAtlas cloud licence key.
|
void |
setPhaseOutLifetime(int serverRankListLifetime)
Deprecated.
As of release 1.5 setPhaseOutLifetime() and
setPhaseOutLifetime() have been merged.
|
void |
setProxy(java.net.Proxy proxy)
Sets the optional proxy for reaching cloud's service
|
void |
setSendExtraHeaders(boolean sendExtraHeaders)
Setter for the sendExtraHeaders setting.
|
void |
setServerRankingLifetime(int serverRankingListLifetime)
Sets the server ranking cache lifetime
|
void |
setUseCache(boolean useCache)
Setter to cache or not to cache device data.
|
void |
setUseClientCookie(boolean useClientCookie)
Setter for the useClientCookie setting.
|
void |
shutdown()
This should be called when shutting down your application.
|
@Deprecated public static final java.lang.String API_VERSION
@Deprecated public static final java.lang.String CLIENT_COOKIE_NAME
@Deprecated public static final java.lang.String KEY_USERAGENT
@Deprecated public static final java.lang.String KEY_SOURCE
@Deprecated public static final java.lang.String KEY_PROPERTIES
@Deprecated public static final java.lang.String SOURCE_CACHE
@Deprecated public static final java.lang.String SOURCE_CLOUD
@Deprecated public static final java.lang.String SOURCE_NONE
@Deprecated public static final java.lang.String DA_HEADER_PREFIX
@Deprecated public static final java.lang.String CLIENT_COOKIE_HEADER
public static Client getInstance(CacheService cacheService) throws CacheException
cacheService
- CacheService object with the cache providerCacheException
- This occurs if the Cache could not be initialized properly.public static Client getInstance(CacheProvider cacheProvider) throws CacheException
cacheProvider
- CacheProvider object with the cache providerCacheException
- This occurs if the Cache could not be initialized properly.public static Client getInstance() throws CacheException
CacheException
public java.lang.String getCloudUrl()
public void setCloudUrl(java.lang.String lastUsedCloudUrl)
lastUsedCloudUrl
- public java.lang.String getRankingStatus()
public EndPoint[] getEndPoints() throws ClientException
ClientException
- when an exception from the Cloud instance side appearsCacheException
- when cache fails to be writtenpublic void setEndPoints(EndPoint[] endPoints)
endPoints
- An array of EndPoint objects, each object is a DeviceAtlas cloud end-pointpublic boolean getAutoServerRanking()
public void setAutoServerRanking(boolean autoServerRanking)
autoServerRanking
- true = the API must auto rank DeviceAtlas end-points.
false = the API should use the built-in EndPoint array or one which is provided to it.public int getCloudServiceTimeout()
public void setCloudServiceTimeout(int cloudServiceTimeout)
cloudServiceTimeout
- Time in seconds.public int getAutoServerRankingMaxFailures()
public void setAutoServerRankingMaxFailures(int autoServerRankingMaxFailures)
autoServerRankingMaxFailures
- End-point fail tolerance during auto ranking.public int getAutoServerRankingNumRequests()
public void setAutoServerRankingNumRequests(int autoServerRankingNumRequests)
autoServerRankingNumRequests
- Number or requests per end-point during auto-ranking.public int getServerRankingLifetime()
public void setServerRankingLifetime(int serverRankingListLifetime)
serverRankingListLifetime
- @Deprecated public int getPhaseOutLifetime()
@Deprecated public void setPhaseOutLifetime(int serverRankListLifetime)
@Deprecated public int getAutoServerRankingLifetime()
@Deprecated public void setAutoServerRankingLifetime(int serverRankListLifetime)
public CacheService getCacheService()
public EndPointService getEndPointService()
public DeviceIdentificatorService getDeviceIdentificatorService()
public java.lang.String getLicenceKey()
public void setLicenceKey(java.lang.String licenceKey)
licenceKey
- The licence key issued to gain access to DeviceAtlas Cloud.public static java.lang.String getVersion()
@Deprecated public java.util.Map getDeviceData(javax.servlet.http.HttpServletRequest request) throws ClientException
request
- ClientException
@Deprecated public java.util.Map getDeviceData(java.lang.String userAgent) throws ClientException
userAgent
- ClientException
@Deprecated public java.util.Map getDeviceData(java.util.Map<java.lang.String,java.lang.String> headers) throws ClientException
headers
- ClientException
@Deprecated public java.util.Map getDeviceDataByUserAgent(java.lang.String userAgent) throws ClientException
userAgent
- ClientException
@Deprecated public java.util.Map getDeviceDataByHeaders(java.util.Map<java.lang.String,java.lang.String> headers) throws ClientException
headers
- ClientException
public Result getResult(javax.servlet.http.HttpServletRequest request) throws ClientException
request
- ClientException
public Result getResult(java.lang.String userAgent) throws ClientException
userAgent
- ClientException
public Result getResult(java.util.Map<java.lang.String,java.lang.String> headers) throws ClientException
headers
- ClientException
public Result getResultByUserAgent(java.lang.String userAgent) throws ClientException
userAgent
- ClientException
public Result getResultByHeaders(java.util.Map<java.lang.String,java.lang.String> headers) throws ClientException
headers
- ClientException
public void setProxy(java.net.Proxy proxy)
proxy
- public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- when tries to clone using the
singleton patternpublic EndPoint[] getServersLatencies()
public EndPoint[] getServersLatencies(int numRequests)
numRequests
- Number of times to request from serverpublic EndPoint[] rankServers() throws CacheException
CacheException
- when an error checking server latencies appearspublic boolean getUseClientCookie()
public void setUseClientCookie(boolean useClientCookie)
useClientCookie
- true = use device data which is created by the
DeviceAtlas client side component if existspublic boolean getUseCache()
public void setUseCache(boolean useCache)
useCache
- true = cache data after getting device data from DeviceAtlas cloudpublic void clearCache()
public void shutdown()
public boolean getSendExtraHeaders()
public void setSendExtraHeaders(boolean sendExtraHeaders)
sendExtraHeaders
- TRUE if to send extra headers, FALSE to just
send essential headers.