Skip to main content

OpenFeature Provider for Java SDK

Last updated on

Integrate your Java applications with Harness FME using the Java OpenFeature ProviderAn OpenFeature Provider wraps the Harness FME SDK, acting as a bridge between the OpenFeature SDK and the FME SDK. It translates OpenFeature function calls into operations handled by the FME SDK., a standardized, vendor-agnostic feature flagging API. This provider implements the OpenFeature specification and bridges the OpenFeature SDK with the Harness FME Java SDK.

This page walks you through installing, configuring, and using the Java OpenFeature provider to evaluate feature flagsA conditional toggle that wraps a section of code, enabling it to be selectively turned on or off remotely (down to an individual user) without a new code deployment. Feature flags decouple deploys from releases and support canary rollouts, A/B testing, and instant kill switches. in your Java applications.

Before you begin

Before you begin, ensure you have the following:

  • A valid Harness FME SDK key for your project
  • A Java environment running version 11 or later
  • Access to your Maven build configuration

Version compatibility

ComponentMinimum Version
Java11+
@splitsoftware/split-openfeature-provider-java≥ 1.2.1
OpenFeature Java SDK≥ 1.0.0

Install the provider and dependencies

Add the Harness FME OpenFeature provider dependency to your Maven build configuration.

<dependency>
<groupId>io.split.openfeature</groupId>
<artifactId>split-openfeature-provider</artifactId>
<version>1.2.1</version>
</dependency>

Initialize the provider

You can instantiate and register the provider using your Harness FME SDK key.

import dev.openfeature.sdk.OpenFeatureAPI;
import io.split.openfeature.SplitProvider;

OpenFeatureAPI api = OpenFeatureAPI.getInstance();
api.setProviderAndWait(new SplitProvider("<YOUR_API_KEY>"));

Alternatively, if you want more control or need advanced initialization, you can create a SplitClient and provide it directly:

import dev.openfeature.sdk.OpenFeatureAPI;
import io.split.openfeature.SplitProvider;
import io.split.client.SplitClient;
import io.split.client.SplitClientConfig;
import io.split.client.SplitFactoryBuilder;

OpenFeatureAPI api = OpenFeatureAPI.getInstance();


SplitClientConfig config = SplitClientConfig.builder()
.setBlockUntilReadyTimeout(10000)
.build();
SplitClient splitClient = SplitFactoryBuilder.build("<YOUR_API_KEY>", config).client();
api.setProviderAndWait(new SplitProvider(splitClient));

Construct an evaluation context

Provide an evaluation contextThe Evaluation Context holds contextual information used during flag evaluation. It can include static data (like application or host identifiers) and dynamic data (such as a client IP address), which can be passed explicitly or propagated automatically. with a targeting keyA unique identifier used to target specific users or entities when evaluating feature flags. It helps determine which variation of a flag should be served based on predefined rules and conditions. to evaluate flags. The evaluation context passes targeting information such as user IDs, email addresses, or plan types for flag targeting.

For example:

Client client = api.getClient("CLIENT_NAME");

EvaluationContext context = new MutableContext("<TARGETING_KEY>");
Boolean boolValue = client.getBooleanValue("boolFlag", false, context);

If the same targeting key is reused across evaluations, set the context at the client or API level:

EvaluationContext context = new MutableContext("<TARGETING_KEY>");
client.setEvaluationContext(context)

Or globally:

EvaluationContext context = new MutableContext("<TARGETING_KEY>");
OpenFeatureAPI.getInstance().setEvaluationContext(context)

Once the context is set at the client or API level, you don’t need to provide it for each evaluation.

Evaluate with details

Use the get*Details(...) APIs to get flag values and metadata (such as variant, reason, error code, and configuration). The FME treatment configuration is returned as a raw JSON string under flagMetadata["config"].

For example:

// boolean/string/number/object all have *Details variants:
FlagEvaluationDetails<String> details =
client.getStringDetails("my-flag", "fallback", ctx);

String jsonConfig = details.getFlagMetadata().getString("config"); // ← Split treatment config

Track events

The Harness FME OpenFeature provider supports tracking user actions or conversion eventsA record of user or system behavior (such as a page visit, button click, or transaction) associated with a unique key and timestamp. Events are not tied to a specific flag; FME's attribution engine links them to flag evaluations after the fact. directly from your Java application.

To enable event tracking, your evaluation context must include the following:

  • A non-empty targetingKey
  • A trafficType (for example, "user" or "account")
  • A non-blank event name

Optionally, you can include a numeric value and additional event properties. For more information, see Sending Events.

For example:

MutableContext ctx = new MutableContext("user-123");
ctx.add("trafficType", new Value("user"));

TrackingEventDetails details = new MutableTrackingEventDetails(19.99)
.add("plan", new Value("pro"))
.add("coupon", new Value("WELCOME10"));

client.track("checkout.completed", ctx, details);

For more information, go to the Harness FME Java OpenFeature Provider GitHub repository.