Package com.deviceatlas.carrier
Class CarrierApiWeb
java.lang.Object
com.deviceatlas.BaseDeviceAtlasApi
com.deviceatlas.carrier.CarrierApi
com.deviceatlas.carrier.CarrierApiWeb
- All Implemented Interfaces:
DeviceAtlasApi
A small extension to the core CarrierApi to permit passing of a javax.servlet.http.HttpServletRequest object.
The getProperties() and getProperty() methods in this class extract the most suitable client IP from a passed javax.servlet.http.HttpServletRequest object.
Example usage:
<%
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 javax.servlet.http.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();
}
-
Field Summary
Fields inherited from class com.deviceatlas.carrier.CarrierApi
HEADERS_TO_CHECK -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetProperties(javax.servlet.http.HttpServletRequest request) Get the Carrier properties for the given javax.servlet.http.HttpServletRequest object.getProperty(javax.servlet.http.HttpServletRequest request, String propertyName) Gets a specific Property for the IP found in the javax.servlet.http.HttpServletRequest object.Methods inherited from class com.deviceatlas.carrier.CarrierApi
getApiVersion, getDataFileCopyright, getDataFileCreationDate, getDataFileVersion, getDeviceAtlasApiVersion, getIp, getProperties, getProperties, getProperty, getProperty, getPropertyNames, isPublicIp, loadDataFromClassPath, loadDataFromFile, loadDataFromStreamMethods inherited from class com.deviceatlas.BaseDeviceAtlasApi
downloadAndLoadDataFile, downloadAndLoadDataFile, getDetectionLookupCount, isDataFileReload, resetDetectionLookupCount
-
Constructor Details
-
CarrierApiWeb
public CarrierApiWeb()
-
-
Method Details
-
getProperties
Get the Carrier properties for the given javax.servlet.http.HttpServletRequest object. The most suitable client IP is extracted and used to lookup the Carrier properties.- Parameters:
request- The request object to find the most suitable IP from.- Returns:
- The found properties or null of no properties found.
-
getProperty
Gets a specific Property for the IP found in the javax.servlet.http.HttpServletRequest object. The most suitable client IP is extracted from the javax.servlet.http.HttpServletRequest object. Note: if multiple properties are needed for the same IP it is more efficient to call getProperties() once rather than repeated calls to getProperty().- Parameters:
request- The request object to find the most suitable IP from.propertyName- The name of the property to return- Returns:
- The Property or null if no property found.
- Throws:
InvalidPropertyNameException- Thrown if the property name does not exist.
-