diff --git a/gravitee-node-license/src/main/java/io/gravitee/node/license/LicenseService.java b/gravitee-node-license/src/main/java/io/gravitee/node/license/LicenseService.java index f9fd51566..0a04909c2 100644 --- a/gravitee-node-license/src/main/java/io/gravitee/node/license/LicenseService.java +++ b/gravitee-node-license/src/main/java/io/gravitee/node/license/LicenseService.java @@ -28,7 +28,6 @@ import java.util.*; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import javax0.license3j.Feature; import javax0.license3j.License; import javax0.license3j.io.LicenseReader; import org.slf4j.Logger; @@ -182,8 +181,10 @@ public void loadLicense() throws Exception { reader = new LicenseReader(new ByteArrayInputStream(licenseContent)); license = reader.read(); - this.dump(); + this.printLicenseInfo(); this.verify(); + } catch (IllegalArgumentException iae) { + logger.error("License file is not valid", iae); } catch (IOException ioe) { logger.error("License file can not be read", ioe); } @@ -216,13 +217,18 @@ private byte[] getLicenseContent() { private String getLicenseFile() { String licenseFile = System.getProperty(GRAVITEE_LICENSE_PROPERTY); if (licenseFile == null || licenseFile.isEmpty()) { - licenseFile = System.getProperty(GRAVITEE_HOME_PROPERTY) + File.separator + "license" + File.separator + "license.key"; + licenseFile = System.getProperty(GRAVITEE_HOME_PROPERTY) + File.separator + "license" + File.separator + GRAVITEE_LICENSE_KEY; } return licenseFile; } private void verify() throws Exception { + if (license == null) { + logger.debug("License will not be verified as it has not been loaded"); + return; + } + boolean valid = license.isOK(key); if (!valid) { @@ -235,16 +241,6 @@ private void verify() throws Exception { stopNode(); } - // Apply additional checks according to the node implementation - //License3JLicense license3JLicense = new License3JLicense(license); - - /* - if (!isValid(license3JLicense)) { - logger.error("License does not allow you to use {}. Please contact GraviteeSource to ask for a valid license.", node.name()); - stopNode(); - } - */ - Date expiration = license.get(LICENSE_EXPIRE_AT).getDate(); long remainingDays = Math.round((expiration.getTime() - System.currentTimeMillis()) / (double) 86400000); @@ -253,11 +249,13 @@ private void verify() throws Exception { } } - private void dump() { - // Print features - logger.info("License informations: "); - Map features = license.getFeatures(); - features.forEach((name, feature) -> logger.info("\t{}: {}", name, feature.valueString())); + private void printLicenseInfo() { + StringBuilder sb = new StringBuilder(); + sb.append("License information: \n"); + license + .getFeatures() + .forEach((name, feature) -> sb.append("\t").append(name).append(": ").append(feature.valueString()).append("\n")); + logger.info(sb.toString()); } private class LicenseChecker extends TimerTask { @@ -267,7 +265,7 @@ public void run() { try { LicenseService.this.verify(); } catch (Exception e) { - e.printStackTrace(); + logger.error("An error occurred while checking license", e); } } } @@ -320,8 +318,8 @@ public void run() { } Thread.yield(); } - } catch (Throwable e) { - // Log or rethrow the error + } catch (Exception e) { + logger.debug("An error occurred while watching license file", e); } } diff --git a/pom.xml b/pom.xml index 2cdb45169..4cbc2ede0 100644 --- a/pom.xml +++ b/pom.xml @@ -273,6 +273,7 @@ 12.13.0 1.6.1 + ${skip.validation}