Exemplo n.º 1
0
  private CvalInfo askLicenseServer(
      String productName, String productKey, String productVersion, CvalInfo info)
      throws UnreachableCvalServerException {

    int majorVersion = computeMajorVersion(productVersion);

    // If we have a valid license info here, it means that we got it from
    // cache.
    // We add a grace time when so as if the server is unreachable
    // we allow the user to use the product.
    if (info != null && info.getExpiredEpoch() != null && !"evaluation".equals(info.getType())) {
      long ts = info.getExpiredEpoch().getTime() + GRACE_DAYS_MSECS;
      info.setExpiredEpoch(new Date(ts));
    }

    boolean validCache =
        info != null
            && info.isValidInfo(productName, productKey)
            && info.isValidVersion(majorVersion)
            && !info.isLicenseExpired();

    // if we have a validCache we set the timeout smaller
    int timeout = validCache ? 2000 : 10000;

    try {
      CvalInfo srvinfo =
          parseJson(provider.askServer(productName + "-" + productVersion, productKey, timeout));
      if (srvinfo != null
          && srvinfo.isValidInfo(productName, productKey)
          && srvinfo.isValidVersion(majorVersion)) {
        // We always cache the info if it is valid although it is
        // expired
        cacheLicenseInfo(srvinfo);
        info = srvinfo;
      }
    } catch (FileNotFoundException e) {
      // 404
      return null;
    } catch (Exception e) {
      if (info == null) {
        throw new UnreachableCvalServerException(productName, e);
      }
    }
    return info;
  }
Exemplo n.º 2
0
    static String composeMessage(String title, String version, String key, CvalInfo info) {
      String msg = "";
      int majorVers = computeMajorVersion(version);

      if (info != null && !info.isValidVersion(majorVers)) {
        msg = getErrorMessage("invalid", title, majorVers);
      } else if (info != null && info.getMessage() != null) {
        msg = info.getMessage().replace("\\n", "\n");
      } else if (info != null && info.isLicenseExpired()) {
        String type = "evaluation".equals(info.getType()) ? "Evaluation license" : "License";
        msg = getErrorMessage("expired", title, majorVers, type);
      } else if (key == null) {
        msg = getErrorMessage("none", title, majorVers);
      } else {
        msg = getErrorMessage("invalid", title, majorVers);
      }
      return msg;
    }