Skip to content

About

Device Detection, IP Intelligence, Human Confidence, and Identifiers for Java, all in one 51Degrees cloud service. User-Agent and Client Hints parsing, crawler detection, and IP geolocation also run on-premise. Includes a 51Did reader. Continues pipeline-java, device-detection-java, and ip-intelligence-java.

Topics

Resources

Contributing

Stars

26 stars

Watchers

0 watching

Forks

Repository files navigation

51Degrees Device Detection and IP Intelligence for Java

51Degrees

Java packages for the Pipeline API, Device Detection, IP Intelligence and Location

Our User-Agent parser for Java supports Device Detection, browser detection, mobile detection, and crawler detection on-premise or in the cloud. IP Intelligence adds IP geolocation, including IP to country data.

It reads User-Agent and User-Agent Client Hints, HTTP request headers that carry browser and device information. For cloud bot detection, Human Confidence reports confidence that a person is viewing the page.

Install

Each product is a separate Maven Central package. For Device Detection, cloud or on-premise:

<!-- Make sure to select the latest version from https://mvnrepository.com/artifact/com.51degrees/pipeline.device-detection -->
<dependency>
    <groupId>com.51degrees</groupId>
    <artifactId>device-detection</artifactId>
    <version>4.5.x</version>
</dependency>

The product guides below list the other packages. To build from source, see Getting the code.

Try the User-Agent tester and IP tester. For cloud use, create a Resource Key.

Created from pipeline-java, device-detection-java, ip-intelligence-java, location-java, device-detection-java-examples, and ip-intelligence-java-examples, this repository continues their work.

Product Read first Documentation
Pipeline API pipeline/README.md Guide and Java API
Device Detection device-detection/README.md Guide and Java API
IP Intelligence ip-intelligence/README.md Guide and Java API
Location location/README.md Guide and Java API

What is where

Path Contents
pipeline The Pipeline API packages, com.51degrees:pipeline.*
device-detection The Device Detection packages, com.51degrees:device-detection*
ip-intelligence The IP Intelligence packages, com.51degrees:ip-intelligence*
location The Location packages, com.51degrees:geo-location*
examples/device-detection Console and web examples for Device Detection
examples/ip-intelligence Console and web examples for IP Intelligence, including the mixed examples that run both products
cxx Submodule of 51degrees-cxx, with the C and C++ code the on-premise engines are built from and the data submodule in cxx/data
pom.xml The reactor that builds everything here. It is never published
ci The scripts the shared 51Degrees CI workflows call

Getting the code

git clone --recurse-submodules https://github.com/51Degrees/51degrees-java.git
cd 51degrees-java

The free data files come from the data repository, which is the cxx/data submodule. Each one is listed there as a .link file, and a script downloads them all into place:

cxx/data/get-data-files.sh

On Windows, run cxx\data\get-data-files.ps1 in PowerShell instead. The examples run the script themselves for a free file they need that is missing.

In a clone made before the data repository was added, delete the cxx/device-detection-data and cxx/ip-intelligence-data folders once cxx no longer includes them, because Git leaves a removed submodule's folder on disk.

Building

You need JDK 17 and either Maven 3.8 or later or the mvnw wrapper in this folder. The build compiles for Java 8, and javac 21 and later warn that Java 8 is obsolete, so JDK 17 is the one to build with. The packages it makes run on Java 8 or later. The two on-premise engines compile their native library during the build, which needs CMake 3.24 or later and a C++ toolchain: Visual Studio with the C++ workload on Windows, GCC or Clang elsewhere.

The build shows every warning from the C and C++ compilers, the linker, javac and PMD, and does not stop on one. The builds 51Degrees runs set the environment variable _51DEGREES_WARNINGS_AS_ERRORS to true, in any case, and there each of those warnings is an error. Set it to build the same way. The two engine CMakeLists.txt files also take -D_51DEGREES_WARNINGS_AS_ERRORS=ON or OFF, which takes the place of the variable for the native build.

From this folder:

mvn install -DskipTests

That builds every package in dependency order, so a change to pipeline is seen by device-detection in the same build. To skip the native libraries, for example on a machine without a C++ toolchain, add -DskipNativeBuild=true. To build one product and what it depends on, name its folder:

mvn install -DskipTests -pl device-detection -am

Tests

mvn surefire:test

The cloud tests need a Resource Key with every property, in the _51DEGREES_RESOURCE_KEY_BESPOKE environment variable, and are skipped without one. A test that runs an example gives the example that key as _51DEGREES_RESOURCE_KEY, which is the name the examples read. The on-premise tests need the free data files, which the script in Getting the code downloads. For the Enterprise IP Intelligence data file, see ip-intelligence/README.md.

Every environment variable name that the packages, tests, examples and CI scripts define starts _51DEGREES_, apart from the few that only CI uses, which ci/check-environment-variable-names.ps1 lists and checks. Tests find data files by searching from the root of this repository, so run Maven from here rather than from inside a package folder.

On JDK 9 and later the build compiles against the Java 8 API, so the packages run on Java 8. To run the tests on another JDK than the one Maven runs on, give Surefire its java with -Djvm=<path to java>, and add -Dfiftyone.testJava=8 when that is Java 8, which leaves out the browser tests that need Java 11:

mvn surefire:test -Djvm=/path/to/jdk-8/bin/java -Dfiftyone.testJava=8

Examples

The examples reference the packages published to Maven Central, which is how a project of your own uses them. To build and run them against the libraries in this repository instead, activate the dev profile:

mvn install -DskipTests -Pdev

Regenerating the SWIG wrappers

The C++ wrappers Java_Hash_Engine.cpp and Java_Ipi_Engine.cpp are generated and must not be edited by hand. They include the C++ headers through cxx/, so SWIG needs the root of this repository on its include path. Build either engine with SWIG 4.5.1 and -DRebuildSwig=ON, from this folder:

cmake -S device-detection/device-detection.hash.engine.on-premise/src/main/cxx -B build-swig -DRebuildSwig=ON

Every SWIG warning is an error. After SWIG runs, the build replaces each base class conversion SWIG writes in the wrapper with one that copies the pointer with memcpy. The vector proxies are final, so the this-escape annotation SWIG's own std_vector.i puts on two of their constructors is removed, and the build stops if any proxy still turns a javac warning off. The committed files are replaced only when all of that succeeds. The IP Intelligence engine also has RegenSwig.ps1 beside its interface file, which does the same.

Versions

Each package has its own version, and a release publishes only the packages that changed since their last release and the packages that depend on them. A change only to documentation, tests, examples or the descriptive parts of a pom.xml, such as its links, releases nothing. Each is tagged with its name and version, such as pipeline.core/4.5.131. ci/README.md describes how CI works out what to release.

History

Earlier repository What it held
pipeline-java The Pipeline API
device-detection-java Device Detection
ip-intelligence-java IP Intelligence
location-java Location
device-detection-java-examples Device Detection examples
ip-intelligence-java-examples IP Intelligence examples

The folders pipeline, device-detection, ip-intelligence, location and the two example folders were brought in from the separate repositories pipeline-java, device-detection-java, ip-intelligence-java, location-java, device-detection-java-examples and ip-intelligence-java-examples with git subtree add, without --squash, so every commit keeps its original SHA. The history of a file before the import is under its old path, so read it from the imported commit, for example git log aff7c544 -- pom.xml for what is now pipeline/pom.xml.

License

European Union Public Licence v1.2

Find out more

About

Device Detection, IP Intelligence, Human Confidence, and Identifiers for Java, all in one 51Degrees cloud service. User-Agent and Client Hints parsing, crawler detection, and IP geolocation also run on-premise. Includes a 51Did reader. Continues pipeline-java, device-detection-java, and ip-intelligence-java.

Topics

Resources

Contributing

Stars

26 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages