Update 4 files
- /src/main/java/com/license/bean/LicenseInfo.java - /src/main/java/com/license/utils/HaspUtil.java - /src/main/java/com/license/controller/LicenseController.java - /src/main/resources/application.properties
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
package com.license.utils;
|
||||
import Aladdin.Hasp;
|
||||
import Aladdin.HaspStatus;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.log.Log;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
|
||||
public class HaspUtil {
|
||||
private static final Log log = Log.get();
|
||||
/** Runtime query scope */
|
||||
protected final static String KEY_SCOPE = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
||||
protected final static String KEY_SCOPE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
+ "<haspscope>\n"
|
||||
+ "<license_manager hostname=\"localhost\" />\n"
|
||||
+ "</haspscope>\n";
|
||||
@@ -33,7 +31,7 @@ public class HaspUtil {
|
||||
|
||||
protected final static String KEY_C2V_FORMAT = "<haspformat format=\"updateinfo\"/>";
|
||||
|
||||
protected final static String KEY_ID_FORMAT = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
||||
protected final static String KEY_ID_FORMAT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
|
||||
"<haspformat root=\"haspscope\">\n" +
|
||||
" <hasp>\n" +
|
||||
" <attribute name=\"id\" />\n" +
|
||||
@@ -112,11 +110,10 @@ public class HaspUtil {
|
||||
int status = hasp.getLastError();
|
||||
log.info("query license status: {}", status);
|
||||
if(status == HaspStatus.HASP_STATUS_OK) {
|
||||
String licenseInfo = hasp.getSessionInfo(LICENSE_STATUS);
|
||||
String licenseInfo = hasp.getSessionInfo(ALL_FORMAT);
|
||||
status = hasp.getLastError();
|
||||
// log.info("license status: {}", status);
|
||||
if (status != HaspStatus.HASP_STATUS_OK) {
|
||||
|
||||
log.error("Error: updateLicense Fails with status code :{}", StrUtil.toString(HaspStatusEnum.getHaspStatusByStatus(status)));
|
||||
}
|
||||
return licenseInfo;
|
||||
}else if (status == HaspStatus.HASP_FEATURE_EXPIRED){
|
||||
@@ -158,41 +155,22 @@ public class HaspUtil {
|
||||
*/
|
||||
public static String readC2V(String vendorCode, Integer featureId) {
|
||||
Hasp hasp = new Hasp(featureId);
|
||||
String infos = "";
|
||||
hasp.login(vendorCode);
|
||||
int status = hasp.getLastError();
|
||||
// log.info("license status: {}", status);
|
||||
if(status == HaspStatus.HASP_STATUS_OK) {
|
||||
//如果已经安装过license ,读取指纹和 hasp id
|
||||
String licenseInfo = hasp.getSessionInfo(KEY_C2V_FORMAT);
|
||||
|
||||
// String info = hasp.getSessionInfo(KEY_ID_FORMAT);
|
||||
// Document document = XmlUtil.parseXml(info);
|
||||
// Element rootEle = document.getDocumentElement();
|
||||
// Element haspElement=XmlUtil.getElement(rootEle,"hasp");
|
||||
// String id = haspElement.getAttribute("id");
|
||||
// String licenseInfo = hasp.getInfo("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
|
||||
// "<haspscope>\n" +
|
||||
// " <hasp " +
|
||||
// "id= \"" + id +"\""+
|
||||
// "/>\n" +
|
||||
// "</haspscope>",KEY_C2V_FORMAT,vendorCode);
|
||||
status = hasp.getLastError();
|
||||
log.info("getLicense c2v license status: {}", status);
|
||||
if (status != HaspStatus.HASP_STATUS_OK) {
|
||||
log.error("Error: Download Fails with status code :{}",status);
|
||||
}
|
||||
return licenseInfo;
|
||||
}else {
|
||||
log.info("login status:"+status);
|
||||
infos = hasp.getInfo(KEY_SCOPE, KEY_C2V_FORMAT, vendorCode);
|
||||
if(infos == null || infos.equals("")) {
|
||||
hasp = new Hasp(featureId);
|
||||
String infos = hasp.getInfo(KEY_SCOPE, KEY_VIEW, vendorCode);
|
||||
infos = hasp.getInfo(KEY_SCOPE, KEY_VIEW, vendorCode);
|
||||
status = hasp.getLastError();
|
||||
log.info("getLicense c2v license status: {}", status);
|
||||
if(status != HaspStatus.HASP_STATUS_OK) {
|
||||
log.error("Error: getLicense c2v Fails with status code :{}",status);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
return infos;
|
||||
}
|
||||
|
||||
public static int verify(String vendorCode, Integer fetureId) {
|
||||
@@ -206,6 +184,4 @@ public class HaspUtil {
|
||||
hasp.logout();
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user