use of org.alfresco.service.license.LicenseException in project alfresco-repository by Alfresco.
the class RepositoryDescriptorDAOImpl method updateLicenseKey.
@Override
public void updateLicenseKey(final byte[] key) {
try {
final NodeRef descriptorRef = getDescriptorNodeRef(true);
if (descriptorRef == null) {
// Should not get this as 'true' was used.
throw new LicenseException("Failed to find system descriptor");
}
if (key == null) {
this.nodeService.setProperty(descriptorRef, ContentModel.PROP_SYS_VERSION_EDITION, null);
} else {
final ContentWriter writer = this.contentService.getWriter(descriptorRef, ContentModel.PROP_SYS_VERSION_EDITION, true);
final InputStream is = new ByteArrayInputStream(key);
writer.setMimetype(MimetypeMap.MIMETYPE_BINARY);
writer.putContent(is);
}
} catch (final RuntimeException e) {
if (logger.isDebugEnabled()) {
logger.debug("getLicenseKey: ", e);
}
throw new LicenseException("Failed to save license", e);
} catch (final Error e) {
if (logger.isDebugEnabled()) {
logger.debug("getLicenseKey: ", e);
}
throw e;
}
}
use of org.alfresco.service.license.LicenseException in project alfresco-repository by Alfresco.
the class RepositoryDescriptorDAOImpl method getLicenseKey.
@Override
public byte[] getLicenseKey() {
byte[] key = null;
try {
final NodeRef descriptorRef = getDescriptorNodeRef(true);
if (descriptorRef == null) {
// Should not get this as 'true' was used.
throw new LicenseException("Failed to find system descriptor");
}
if (logger.isDebugEnabled()) {
logger.debug("getLicenseKey: descriptorRef=" + descriptorRef);
}
final ContentReader reader = this.contentService.getReader(descriptorRef, ContentModel.PROP_SYS_VERSION_EDITION);
boolean exists = reader != null && reader.exists();
if (exists) {
ByteArrayOutputStream os = null;
try {
os = new ByteArrayOutputStream();
reader.getContent(os);
key = os.toByteArray();
} finally {
if (os != null) {
try {
os.close();
} catch (IOException ignore) {
// We have more to worry about if we ever get here.
logger.debug("getLicenseKey: Error closing ByteArrayOutputStream", ignore);
}
}
}
} else {
if (logger.isDebugEnabled()) {
// reader should never be null. An exception is thrown by getReader if it is.
logger.debug("getLicenseKey: reader " + (reader == null ? "is null" : " file does " + (exists ? "" : "NOT ") + "exist"));
}
}
} catch (final LicenseException e) {
throw e;
} catch (final RuntimeException e) {
if (logger.isDebugEnabled()) {
logger.debug("getLicenseKey: ", e);
}
throw new LicenseException("Failed to load license", e);
} catch (final Error e) {
if (logger.isDebugEnabled()) {
logger.debug("getLicenseKey: ", e);
}
throw e;
}
if (logger.isDebugEnabled()) {
logger.debug("getLicenseKey: key " + (key == null ? "is null" : "length=" + key.length));
}
return key;
}
use of org.alfresco.service.license.LicenseException in project alfresco-repository by Alfresco.
the class DescriptorServiceImpl method bootstrap.
private void bootstrap() {
logger.debug("onBootstrap");
// We force write mode
RetryingTransactionHelper helper = transactionService.getRetryingTransactionHelper();
helper.setForceWritable(true);
// create the initial installed descriptor
RetryingTransactionCallback<Descriptor> getDescriptorCallback = new RetryingTransactionCallback<Descriptor>() {
public Descriptor execute() {
return installedRepoDescriptorDAO.getDescriptor();
}
};
Descriptor installed = helper.doInTransaction(getDescriptorCallback, false, false);
if (installed != null) {
installedRepoDescriptor = installed;
} else {
installedRepoDescriptor = new UnknownDescriptor();
}
/*
* Initialize license service if on classpath.
* If no class exists a dummy license service is used.
* Make the LicenseService available in the context.
*/
licenseService = (LicenseService) constructSpecialService("org.alfresco.enterprise.license.LicenseComponent");
if (licenseService == null) {
// No license server code - install a dummy license service instead
licenseService = new NOOPLicenseService();
}
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext instanceof ConfigurableApplicationContext) {
((ConfigurableApplicationContext) applicationContext).getBeanFactory().registerSingleton("licenseService", licenseService);
}
// Register HeartBeat with LicenseService
licenseService.registerOnLicenseChange((LicenseChangeHandler) hbDataCollectorService);
// Now listen for future license changes
licenseService.registerOnLicenseChange(this);
try {
// Verify license has side effect of loading any new licenses
licenseService.verifyLicense();
} catch (LicenseException e) {
// Swallow Licence Exception Here
// Don't log error: It'll be reported by other means
}
;
}
Aggregations