public class CarrierApiWeb extends CarrierApi
A small extension to the core CarrierApi to permit passing of a HttpServletRequest object.
The getProperties() and getProperty() methods in this class extract the most suitable client IP from a passed HttpServletRequest object.
<%
CarrierApiWeb carrierApi = new CarrierApiWeb();
// loading data can be slow - it is recommended to store loaded API in the
// ServletContext or wrap in a Singleton.
carrierApi.loadDataFromFile("/path/to/sample.dat");
// get all properties from the HTTPServletRequest object
Properties props = carrierApi.getProperties(request);
// .... use the properties ....
if(props.containsKey("mobileNetworkOperator") {
String operatorName = props.get("mobileNetworkOperator").asString();
}
// get a single property
Property countryProp = carrierApi.getProperty("countryCode");
if(countryProp != null) {
String countryCode = countryProp.asString();
}
HEADERS_TO_CHECK| Constructor and Description |
|---|
CarrierApiWeb() |
| Modifier and Type | Method and Description |
|---|---|
Properties |
getProperties(javax.servlet.http.HttpServletRequest request)
Get the Carrier properties for the given HttpServletRequest object.
|
Property |
getProperty(javax.servlet.http.HttpServletRequest request,
java.lang.String propertyName)
Gets a specific Property for the IP found in the HttpServletRequest
object.
|
getApiVersion, getDataFileCopyright, getDataFileCreationDate, getDataFileVersion, getDeviceAtlasApiVersion, getIp, getProperties, getProperties, getProperty, getProperty, getPropertyNames, isPublicIp, loadDataFromClassPath, loadDataFromFile, loadDataFromStreamdownloadAndLoadDataFile, downloadAndLoadDataFile, getDetectionLookupCount, isDataFileReload, resetDetectionLookupCountpublic Properties getProperties(javax.servlet.http.HttpServletRequest request)
request - The request object to find the most suitable IP from.public Property getProperty(javax.servlet.http.HttpServletRequest request, java.lang.String propertyName)
request - The request object to find the most suitable IP from.propertyName - The name of the property to returnInvalidPropertyNameException - Thrown if the property name does not exist.Copyright © 2023 DeviceAtlas Limited. All rights reserved.