use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.
the class HttpClientFactoryImpl method activate.
@Activate
protected void activate(Map<String, Object> config) throws Exception {
boolean useSSL = PropertiesUtil.toBoolean(config.get(PROP_USE_SSL), DEFAULT_USE_SSL);
String scheme = useSSL ? "https" : "http";
String hostname = PropertiesUtil.toString(config.get(PROP_HOST_DOMAIN), null);
int port = PropertiesUtil.toInteger(config.get(PROP_GATEWAY_PORT), 0);
if (hostname == null || port == 0) {
throw new IllegalArgumentException("Configuration not valid. Both host and port must be provided.");
}
baseUrl = String.format("%s://%s:%s", scheme, hostname, port);
int connectTimeout = PropertiesUtil.toInteger(config.get(PROP_CONNECT_TIMEOUT), DEFAULT_CONNECT_TIMEOUT);
int soTimeout = PropertiesUtil.toInteger(config.get(PROP_SO_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
HttpClientBuilder builder = httpClientBuilderFactory.newBuilder();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(connectTimeout).setSocketTimeout(soTimeout).build();
builder.setDefaultRequestConfig(requestConfig);
boolean disableCertCheck = PropertiesUtil.toBoolean(config.get(PROP_DISABLE_CERT_CHECK), DEFAULT_DISABLE_CERT_CHECK);
if (useSSL && disableCertCheck) {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
}).build();
builder.setHostnameVerifier(new AllowAllHostnameVerifier()).setSslcontext(sslContext);
}
httpClient = builder.build();
executor = Executor.newInstance(httpClient);
String username = PropertiesUtil.toString(config.get(PROP_USERNAME), null);
String password = PropertiesUtil.toString(config.get(PROP_PASSWORD), null);
if (username != null && password != null) {
HttpHost httpHost = new HttpHost(hostname, port, useSSL ? "https" : "http");
executor.auth(httpHost, username, password).authPreemptive(httpHost);
}
}
use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.
the class QuicklyFilter method activate.
@Activate
protected final void activate(final Map<String, String> config) throws IOException {
InputStream inputStream = null;
try {
inputStream = getClass().getResourceAsStream(HTML_FILE);
appHTML = IOUtils.toString(inputStream, "UTF-8");
} finally {
IOUtils.closeQuietly(inputStream);
}
}
use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.
the class ColorConversionImpl method activate.
@Activate
protected void activate(Map<String, Object> properties) throws Exception {
String profileName = PropertiesUtil.toString(properties.get(PROP_CMKY_PROFILE), DEFAULT_CMYK_PROFILE);
InputStream iccData = getClass().getClassLoader().getResourceAsStream("icc/cmyk/" + profileName + ".icc");
ICC_Profile profile = ICC_Profile.getInstance(iccData);
cmykColorSpace = new ICC_ColorSpace(profile);
}
use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.
the class EnsurePropertyIndex method activate.
@Activate
@SuppressWarnings("squid:S3776")
protected void activate(Map<String, Object> properties) throws RepositoryException {
log.warn("EnsurePropertyIndex is deprecated. Please switch to EnsureOakIndex immediately.");
if (capabilityHelper.isOak()) {
final String name = PropertiesUtil.toString(properties.get(PROP_INDEX_NAME), null);
IndexDefinition def = new IndexDefinition();
def.propertyName = PropertiesUtil.toString(properties.get(PROP_PROPERTY_NAME), null);
def.async = PropertiesUtil.toBoolean(properties.get(PROP_ASYNC), DEFAULT_ASYNC);
def.unique = PropertiesUtil.toBoolean(properties.get(PROP_UNIQUE), DEFAULT_UNIQUE);
def.declaringNodeTypes = PropertiesUtil.toStringArray(properties.get(PROP_NODE_TYPES), new String[0]);
if (name == null || def.propertyName == null) {
log.warn("Incomplete configure; name or property name is null.");
return;
}
Session session = null;
try {
session = repository.loginService(EnsureOakIndexJobHandler.SERVICE_NAME, null);
Node oakIndexContainer = session.getNode(PATH_OAK_INDEX);
if (oakIndexContainer.hasNode(name)) {
Node indexNode = oakIndexContainer.getNode(name);
if (needsUpdate(indexNode, def)) {
log.info("updating index {}", name);
updateIndex(indexNode, def);
} else {
log.debug("index {} does not need updating", name);
}
} else {
log.info("creating index {}", name);
createOrUpdateIndex(oakIndexContainer.addNode(name, NT_QID), def);
}
session.save();
} catch (RepositoryException e) {
log.error("Unable to create index", e);
} finally {
if (session != null) {
session.logout();
}
}
} else {
log.info("Cowardly refusing to create indexes on non-Oak instance.");
}
}
use of org.apache.felix.scr.annotations.Activate in project acs-aem-commons by Adobe-Consulting-Services.
the class DuckDuckGoDocsOperationImpl method activate.
@Activate
protected void activate(Map<String, String> config) {
ProductInfo productInfo = null;
for (ProductInfo i : productInfoService.getInfos()) {
String shortName = i.getShortName();
// currently, this is always 'CQ' but let's futureproof a bit
if (shortName.equalsIgnoreCase("cq") || shortName.equalsIgnoreCase("aem")) {
productInfo = i;
break;
}
}
if (productInfo != null) {
// there's a bug in 6.1 GA which causes productInfo.getShortVersion() to return 6.0,
// so let's use this longer form.
aemVersion = String.format("%s-%s", productInfo.getVersion().getMajor(), productInfo.getVersion().getMinor());
}
log.debug("AEM Version: {}", aemVersion);
log.debug("Product Name: {}", productName);
}
Aggregations