Skip to main content
This guide demonstrates how to integrate Avalex license validation into a Java application (Java 11+). It uses the built-in java.net.http.HttpClient and java.security.MessageDigest libraries, requiring zero third-party dependencies.

Prerequisites

  • Java 11 or newer (utilizes native java.net.http.HttpClient).

Full Working Example

The following class is self-contained and ready to run in any Java 11+ application. Adjust AVALEX_API_URL and PRODUCT_ID to match your deployment environment.

Code Walkthrough

1. HWID Generation (getHwid) Uses Java’s System.getProperty to gather machine details (os.name, user.name, os.arch), hashes them with MessageDigest.getInstance("SHA-256"), and formats the output into a uppercase 32-character hex string. 2. Asynchronous HTTP POST Request Uses java.net.http.HttpClient with a 5-second connection timeout to call POST /licenses/validate. 3. Status Handling & Rate Limiting Inspects HTTP status code:
  • 200 OK: Parses JSON response for "valid": true.
  • 429 Too Many Requests: Logs a rate-limit warning and returns false.
  • Other / Transport Error: Catches exceptions and returns false.
Cache successful validation results locally using an encrypted storage mechanism to support a 24–72 hour offline grace period.