use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class OsgiUtil method getCfg.
/**
* Get a mandatory, non-blank value from a dictionary.
*
* @throws ConfigurationException
* key does not exist or its value is blank
*/
public static String getCfg(Dictionary d, String key) throws ConfigurationException {
Object p = d.get(key);
if (p == null)
throw new ConfigurationException(key, "does not exist");
String ps = p.toString();
if (StringUtils.isBlank(ps))
throw new ConfigurationException(key, "is blank");
return StringUtils.trimToEmpty(ps);
}
use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method updated.
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary properties) throws ConfigurationException {
Option<String> formats;
Option<String> smilOrder;
if (properties == null) {
formats = Option.none();
smilOrder = Option.none();
} else {
formats = OsgiUtil.getOptCfg(properties, STREAMING_FORMATS_KEY);
smilOrder = OsgiUtil.getOptCfg(properties, SMIL_ORDER_KEY);
}
if (formats.isSome()) {
setSupportedFormats(formats.get());
} else {
setDefaultSupportedFormats();
}
logger.info("The supported streaming formats are: {}", StringUtils.join(supportedAdaptiveFormats, ","));
if (smilOrder.isNone() || SMIL_ASCENDING_VALUE.equals(smilOrder.get())) {
logger.info("The videos in the SMIL files will be sorted in ascending bitrate order");
isSmilOrderDescending = false;
} else if (SMIL_DESCENDING_VALUE.equals(smilOrder.get())) {
isSmilOrderDescending = true;
logger.info("The videos in the SMIL files will be sorted in descending bitrate order");
} else {
throw new ConfigurationException(SMIL_ORDER_KEY, format("Illegal value '%s'. Valid options are '%s' and '%s'", smilOrder.get(), SMIL_ASCENDING_VALUE, SMIL_DESCENDING_VALUE));
}
distributeJobLoad = LoadUtil.getConfiguredLoadValue(properties, DISTRIBUTE_JOB_LOAD_KEY, DEFAULT_DISTRIBUTE_JOB_LOAD, serviceRegistry);
retractJobLoad = LoadUtil.getConfiguredLoadValue(properties, RETRACT_JOB_LOAD_KEY, DEFAULT_RETRACT_JOB_LOAD, serviceRegistry);
}
use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class SmtpService method updated.
/**
* Callback from the OSGi <code>ConfigurationAdmin</code> on configuration changes.
*
* @param properties
* the configuration properties
* @throws ConfigurationException
* if configuration fails
*/
@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
// Production or test mode
String optMode = StringUtils.trimToNull((String) properties.get(OPT_MAIL_MODE));
if (optMode != null) {
try {
Mode mode = Mode.valueOf(optMode);
setProductionMode(Mode.production.equals(mode));
} catch (Exception e) {
logger.error("Error parsing smtp service mode '{}': {}", optMode, e.getMessage());
throw new ConfigurationException(OPT_MAIL_MODE, e.getMessage());
}
}
logger.info("Smtp service is in {} mode", isProductionMode() ? "production" : "test");
// Mail transport protocol
String optMailTransport = StringUtils.trimToNull((String) properties.get(OPT_MAIL_TRANSPORT));
if (StringUtils.isNotBlank(optMailTransport))
setMailTransport(optMailTransport);
// The mail host is mandatory
String propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX;
String mailHost = (String) properties.get(propName);
if (StringUtils.isBlank(mailHost))
throw new ConfigurationException(propName, "is not set");
setHost(mailHost);
// Mail port
propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_PORT_SUFFIX;
String mailPort = (String) properties.get(propName);
if (StringUtils.isNotBlank(mailPort))
setPort(Integer.parseInt(mailPort));
// TSL over SMTP support
propName = OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_TLS_ENABLE_SUFFIX;
setSsl(BooleanUtils.toBoolean((String) properties.get(propName)));
// Mail user
String mailUser = (String) properties.get(OPT_MAIL_USER);
if (StringUtils.isNotBlank(mailUser))
setUser(mailUser);
// Mail password
String mailPassword = (String) properties.get(OPT_MAIL_PASSWORD);
if (StringUtils.isNotBlank(mailPassword))
setPassword(mailPassword);
// Mail sender
String mailFrom = (String) properties.get(OPT_MAIL_FROM);
if (StringUtils.isNotBlank(mailFrom))
setSender(mailFrom);
// Mail debugging
setDebug(BooleanUtils.toBoolean((String) properties.get(OPT_MAIL_DEBUG)));
configure();
// Test
String mailTest = StringUtils.trimToNull((String) properties.get(OPT_MAIL_TEST));
if (mailTest != null && Boolean.parseBoolean(mailTest)) {
logger.info("Sending test message to {}", mailFrom);
try {
sendTestMessage(mailFrom);
} catch (MessagingException e) {
logger.error("Error sending test message to " + mailFrom + ": " + e.getMessage());
while (e.getNextException() != null) {
Exception ne = e.getNextException();
logger.error("Error sending test message to " + mailFrom + ": " + ne.getMessage());
if (ne instanceof MessagingException)
e = (MessagingException) ne;
else
break;
}
throw new ConfigurationException(OPT_MAIL_PREFIX + mailTransport + OPT_MAIL_HOST_SUFFIX, "Failed to send test message to " + mailFrom);
}
}
}
use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class TimelinePreviewsServiceImpl method updated.
/**
* {@inheritDoc}
*
* @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
*/
@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
if (properties == null) {
return;
}
logger.debug("Configuring the timeline previews service");
// Horizontal resolution
if (properties.get(OPT_RESOLUTION_X) != null) {
String res = (String) properties.get(OPT_RESOLUTION_X);
try {
resolutionX = Integer.parseInt(res);
logger.info("Horizontal resolution set to {} pixels", resolutionX);
} catch (Exception e) {
throw new ConfigurationException(OPT_RESOLUTION_X, "Found illegal value '" + res + "' for timeline previews horizontal resolution");
}
}
// Vertical resolution
if (properties.get(OPT_RESOLUTION_Y) != null) {
String res = (String) properties.get(OPT_RESOLUTION_Y);
try {
resolutionY = Integer.parseInt(res);
logger.info("Vertical resolution set to {} pixels", resolutionY);
} catch (Exception e) {
throw new ConfigurationException(OPT_RESOLUTION_Y, "Found illegal value '" + res + "' for timeline previews vertical resolution");
}
}
// Output file format
if (properties.get(OPT_OUTPUT_FORMAT) != null) {
String format = (String) properties.get(OPT_OUTPUT_FORMAT);
try {
outputFormat = format;
logger.info("Output file format set to \"{}\"", outputFormat);
} catch (Exception e) {
throw new ConfigurationException(OPT_OUTPUT_FORMAT, "Found illegal value '" + format + "' for timeline previews output file format");
}
}
// Output mimetype
if (properties.get(OPT_MIMETYPE) != null) {
String type = (String) properties.get(OPT_MIMETYPE);
try {
mimetype = type;
logger.info("Mime type set to \"{}\"", mimetype);
} catch (Exception e) {
throw new ConfigurationException(OPT_MIMETYPE, "Found illegal value '" + type + "' for timeline previews mimetype");
}
}
timelinepreviewsJobLoad = LoadUtil.getConfiguredLoadValue(properties, TIMELINEPREVIEWS_JOB_LOAD_KEY, DEFAULT_TIMELINEPREVIEWS_JOB_LOAD, serviceRegistry);
}
use of org.osgi.service.cm.ConfigurationException in project opencast by opencast.
the class AbstractUrlSigningProvider method updated.
@SuppressWarnings("rawtypes")
@Override
public void updated(Dictionary properties) throws ConfigurationException {
getLogger().info("Updating {}", toString());
if (properties == null) {
getLogger().warn("{} is unconfigured", toString());
return;
}
// Clear the current set of keys
keys.clear();
String key = null;
String keyId = null;
String url = null;
String organization = null;
int i = 1;
while (true) {
// Create the configuration prefixes
key = new StringBuilder(KEY_PREFIX).append(".").append(i).toString();
keyId = new StringBuilder(ID_PREFIX).append(".").append(i).toString();
url = new StringBuilder(URL_PREFIX).append(".").append(i).toString();
organization = new StringBuilder(ORGANIZATION_PREFIX).append(".").append(i).toString();
getLogger().debug("Looking for configuration of {}, {}, {} and {}", key, keyId, url, organization);
// Read the key, keyId and url values
String keyValue = StringUtils.trimToNull((String) properties.get(key));
String keyIdValue = StringUtils.trimToNull((String) properties.get(keyId));
String urlValue = StringUtils.trimToNull((String) properties.get(url));
String organizationValue = StringUtils.trimToNull((String) properties.get(organization));
// Note: organization is optional
if (keyValue == null || keyIdValue == null || urlValue == null) {
getLogger().debug("Unable to configure key with id '{}' and url matcher '{}' because the id, key or url is missing. Stopping to look for new keys.", keyIdValue, urlValue);
break;
}
if (organizationValue == null) {
// organization is optimal. Set it to default
organizationValue = ANY_ORGANIZATION;
getLogger().debug("No organization set for key id {}, using default organization {}", keyIdValue, organizationValue);
}
// Store the key
try {
addKeyEntry(keyIdValue, urlValue, keyValue, organizationValue);
getLogger().info("{} will handle uris that start with '{}' with the key id '{}'", toString(), urlValue, keyIdValue);
} catch (IllegalStateException e) {
throw new ConfigurationException(urlValue, e.getMessage());
}
i++;
}
// Has the rewriter been fully configured
if (keys.size() == 0) {
getLogger().info("{} configured to not sign any urls.", toString());
return;
}
}
Aggregations