Java Pipeline
Introduction
This repository contains all the projects required to build the Java implementation of the 51Degrees Pipeline API.
The specification is also available on GitHub and is recommended reading if you wish to understand the concepts and design of this API.
Reference documentation for the Java implementation can be found on the Java API documentation page.
Pre-requisites
The tested versions page shows the JDK versions that we currently test against. The software may run fine against other versions, but additional caution should be applied.
Contents
- pipeline.common - Some shared library classes.
- pipeline.caching - 51Degrees' caching interfaces and high-performance LRU implementation.
- pipeline.core - The core software that comprises the Pipeline API.
- pipeline.engines - Shared functionality that is available to all 'engines' (specialized 'flow elements')
- pipeline.engines.fiftyone - Functionality that is specific to 51Degrees engines.
- pipeline.cloudrequestengine - An engine that is used to retrieve data from 51Degrees' cloud API.
- pipeline.derivedproperty - The Derived Property Element, which produces new properties from the properties other elements produce, following rules written in a script. Every Derived Property Element in a Pipeline writes into the same Element Data, so two of them must not be members of the same parallel group.
Installation
Packages can be found on Maven under the group com.51degrees.
Alternatively clone this git repository and in the root run mvn install to build and install the packages locally.
Native library access
pipeline.engines.fiftyone contains LibLoader, which calls System.load to load the native libraries used by the on-premise engines. System.load is a restricted method (JEP 472): Java 24 and 25 warn once per calling module, and a later release will refuse the call and throw IllegalCallerException.
There are two ways to grant the permission.
On the classpath
This is the default layout and needs no changes to how you package or deploy:
Everything on the classpath belongs to the unnamed module, so ALL-UNNAMED is the only name the JVM will accept there. This is a rule of the module system, not something these packages can improve on.
Naming 51Degrees code alone
If granting native access to every jar on the classpath is too broad, move only pipeline.engines.fiftyone onto the module path and leave your application and all other dependencies - including the other four 51Degrees jars - on the classpath:
The same jar must not appear on both paths, so keep it in a directory of its own rather than in the one the classpath wildcard covers.
All five packages carry a module name, so any of them can be moved to the module path the same way, but only fiftyone.pipeline.engines.fiftyone needs to be:
| Package | Module name |
| pipeline.common | fiftyone.common |
| pipeline.caching | fiftyone.caching |
| pipeline.core | fiftyone.pipeline.core |
| pipeline.engines | fiftyone.pipeline.engines |
| pipeline.engines.fiftyone | fiftyone.pipeline.engines.fiftyone |
The names come from an Automatic-Module-Name manifest entry, so the jars are ordinary non-modular jars, build identically on every JDK from 8 upwards, and impose nothing on consumers who stay on the classpath.
Device detection users need to grant access to a second module as well. The JNI native declarations live in device-detection.hash.engine.on-premise, and JEP 472 checks binding them against the module that declares them - see the device-detection-java README.
Configuring builders from the module path
PipelineBuilder.buildFromConfiguration discovers element builders by scanning the class path, which does not include the module path. When a builder ships in a jar you have moved to the module path, name it by its fully qualified class name instead of its short name:
This affects SequenceElementBuilder, SetHeadersElementBuilder and ShareUsageBuilder, which ship inside pipeline.engines.fiftyone. Short names continue to work for every builder on the class path.
Web integration
pipeline.web provides PipelineFilter, a servlet filter, and pipeline.web.mvc provides FiftyOneInterceptor, a Spring MVC interceptor. Each creates one Flow Data for each request, processes it, and closes it when the request ends. Application code reads it through FlowDataProviderCore or FlowDataProvider.
Flow Data and threads
A Flow Data cannot be used by two threads at once. A servlet or a controller handles each request on one thread, so reading the Flow Data there is safe. An application that hands work from a request to another thread or task reads the values that work needs from the Flow Data on the request's thread, into its own variables, and passes those values, not the Flow Data. The Flow Data is closed when the request ends, so work that outlives the request must not keep it either. A Flow Data is not safe to use from several threads at once, and an application that shares one across threads is responsible for any locking.
This controller, based on the clientside-element-mvc example, hands a value to an executor.
Tests
Most packages contain tests which use junit and mockito. These tests can be run using maven by calling: mvn test
Examples
There are several examples available in the pipeline.developer-examples folder that demonstrate how to make use of the Pipeline API in isolation. These are described in the table below. If you want examples that demonstrate how to use 51Degrees products such as device detection, then these are available in the corresponding repository and on our website.
| Example | Description |
| pipeline.developer-examples.flowelement | Shows how to create a custom flow element that returns star sign based on a supplied date of birth. |
| pipeline.developer-examples.onpremise-engine | Shows how to modify SimpleFlowElement to make use of the 'engine' functionality and use a custom data file to map dates to star signs rather than relying on hard coded data. |
| pipeline.developer-examples.clientside-element | Shows how to modify SimpleFlowElement to request the data of birth from the user using client-side JavaScript. |
| pipeline.developer-examples.clientside-element-mvc | An example project showing how to use the code from SimpleClientSideElement in a Java web application using the Model-View-Controller Pattern. |
| pipeline.developer-examples.cloud-engine | Shows how to modify SimpleFlowElement to perform the star sign lookup via a cloud service rather than locally. The endpoint and resource key come from _51DEGREES_CLOUD_ENDPOINT and _51DEGREES_RESOURCE_KEY when set, otherwise the star sign service the example was written for. |
| pipeline.developer-examples.usage-sharing | Shows how to share usage with 51Degrees. This helps us to keep our products up to date and accurate. |
| pipeline.developer-examples.fodid | Shows how to read a 51Did, and, in a web demo, how a browser creates and verifies one against the 51Degrees cloud and the server redeems the encrypted result, so that the creator context proves the identifier is being presented by the browser it was created on. The module README describes the flow, the environment variables, what a run costs and the redeem call to copy into your own server. |
Pointing the cloud examples at another host
Every example that calls the 51Degrees cloud takes its endpoint from the _51DEGREES_CLOUD_ENDPOINT environment variable, which is the cloud API base including the /api/v4/ segment and defaults to https://cloud.51degrees.com/api/v4/ (the cloud-engine example defaults to the star sign service it was written for, as its row above says). This is the same variable the cloud request engine in this repository honours, so setting it once points every example, and any pipeline built with the engine, at the same place. The resource key comes from _51DEGREES_RESOURCE_KEY.
A host other than cloud.51degrees.com would be used to (a) use an on premise web server, or (b) use a privately hosted version of the 51Degrees cloud for performance reasons. This is the private hosting option of the cloud service. Both run the same service, so the examples work unchanged.
