← Country website blocking
SERVER-SIDE COUNTRY RULES · JAVA

Apply country rules in Java.

Look up the request country, apply your policy and decide before sending protected content.

1. Install and configure

Build the extracted pom.xml project using Java 17 and Maven, then add its source/module and declared Jackson dependency to your application. The code below belongs in an existing Servlet/Spring filter; visitorIp, request, response and chain come from that filter. Validate compilation and wiring in your Java application.

Download Java SDK

Set ORIGOOO_API_KEY on your server. Use a secret key with lookup scope and the API origin https://orig.ooo. These SDKs are source downloads, not public package-registry releases.

2. Apply the rule before your response

This example blocks US and GB, allows other matched countries, and denies when location is unknown. Choose the unknown behaviour for your own service before deployment.

import ooo.orig.Origooo;
import java.time.Duration;
import java.util.Set;

var client = new Origooo(System.getenv("ORIGOOO_API_KEY"),
    "https://orig.ooo", Duration.ofSeconds(2), Duration.ofMinutes(5));
var policy = new Origooo.Policy(Set.of(), Set.of("US", "GB"), "deny");

// In your Servlet/Spring filter before invoking the next handler:
String country = null;
try {
    // Resolve visitorIp with the SDK's configured proxy-chain helper.
    country = client.lookup(visitorIp).countryCode();
} catch (InterruptedException error) {
    Thread.currentThread().interrupt();
} catch (java.io.IOException | IllegalArgumentException error) {
    // Leave country unknown; the configured policy decides.
}
if (!policy.decide(country).equals("allow")) {
    response.setStatus(403);
    return;
}
chain.doFilter(request, response);

Java setup and framework guide →

3. Verify your request path

  1. Verify an allowed country reaches your application handler.
  2. Verify a blocked country returns 403 before protected content is rendered.
  3. Simulate a timeout, 429, missing country and invalid IP; verify your explicit unknown policy.
  4. Confirm untrusted forwarded headers cannot change the visitor IP.
  5. Keep administrator/health-route exceptions in trusted application code.

Choose when to use this

Use server policies for regional service availability and applications with a defined country policy. For an offer or message that merely appears or disappears, use the browser decision element. Browser hiding does not prevent downloading content already sent to the client.

The API supplies approximate geography. VPNs, mobile networks and proxies affect the result. Treat a country rule as one input to your application, not proof of residence.

Complete Java reference → · Error handling · Request speed and credits

YOUR NEXT BUILD STARTS HERE

Get your free API key.

1,000 monthly credits. No credit card required.

Account services are not connected in this preview. Explore the dashboard or download the implementation from your workspace.
Read the integration guide

Production accounts require verified email. Google OAuth and Paddle need deployment credentials.