Search in sources :

Example 56 with Activate

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);
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) TrustStrategy(org.apache.http.conn.ssl.TrustStrategy) AllowAllHostnameVerifier(org.apache.http.conn.ssl.AllowAllHostnameVerifier) HttpHost(org.apache.http.HttpHost) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) SSLContext(javax.net.ssl.SSLContext) SSLContextBuilder(org.apache.http.conn.ssl.SSLContextBuilder) Activate(org.apache.felix.scr.annotations.Activate)

Example 57 with Activate

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);
    }
}
Also used : InputStream(java.io.InputStream) Activate(org.apache.felix.scr.annotations.Activate)

Example 58 with Activate

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);
}
Also used : ICC_ColorSpace(java.awt.color.ICC_ColorSpace) InputStream(java.io.InputStream) ICC_Profile(java.awt.color.ICC_Profile) Activate(org.apache.felix.scr.annotations.Activate)

Example 59 with Activate

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.");
    }
}
Also used : Node(javax.jcr.Node) RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Activate(org.apache.felix.scr.annotations.Activate)

Example 60 with Activate

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);
}
Also used : ProductInfo(com.adobe.granite.license.ProductInfo) Activate(org.apache.felix.scr.annotations.Activate)

Aggregations

Activate (org.apache.felix.scr.annotations.Activate)153 ConfigurationException (org.osgi.service.cm.ConfigurationException)31 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 BundleContext (org.osgi.framework.BundleContext)19 File (java.io.File)15 OsgiWhiteboard (org.apache.jackrabbit.oak.osgi.OsgiWhiteboard)12 URL (java.net.URL)11 Hashtable (java.util.Hashtable)11 ServiceReference (org.osgi.framework.ServiceReference)11 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)9 HashSet (java.util.HashSet)8 IOException (java.io.IOException)7 HashMap (java.util.HashMap)7 Map (java.util.Map)6 Session (javax.jcr.Session)5 StandardMBean (javax.management.StandardMBean)5 Whiteboard (org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard)5 Filter (org.osgi.framework.Filter)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4