Search in sources :

Example 11 with ComponentException

use of org.osgi.service.component.ComponentException in project felix by apache.

the class ComponentFactoryImpl method newInstance.

/* (non-Javadoc)
    * @see org.osgi.service.component.ComponentFactory#newInstance(java.util.Dictionary)
    */
public ComponentInstance newInstance(Dictionary<String, ?> dictionary) {
    final SingleComponentManager<S> cm = createComponentManager();
    log(LogService.LOG_DEBUG, "Creating new instance from component factory {0} with configuration {1}", new Object[] { getComponentMetadata().getName(), dictionary }, null);
    cm.setFactoryProperties(dictionary);
    // configure the properties
    cm.reconfigure(m_configuration, false, null);
    // enable
    cm.enableInternal();
    ComponentInstance instance;
    if (getComponentMetadata().isPersistentFactoryComponent()) {
        instance = new ModifyComponentInstance<S>(cm);
    } else {
        instance = cm.getComponentInstance();
        if (instance == null || instance.getInstance() == null) {
            // activation failed, clean up component manager
            cm.dispose(ComponentConstants.DEACTIVATION_REASON_DISPOSED);
            throw new ComponentException("Failed activating component");
        }
    }
    synchronized (m_componentInstances) {
        m_componentInstances.put(cm, cm);
    }
    return instance;
}
Also used : ComponentInstance(org.osgi.service.component.ComponentInstance) ExtFactoryComponentInstance(org.apache.felix.scr.component.ExtFactoryComponentInstance) ComponentException(org.osgi.service.component.ComponentException)

Example 12 with ComponentException

use of org.osgi.service.component.ComponentException in project fabric8 by jboss-fuse.

the class FabricDetectingGateway method createDetectingGateway.

protected DetectingGateway createDetectingGateway() {
    DetectingGateway gateway = new DetectingGateway();
    VertxService vertxService = getVertxService();
    LoadBalancer serviceLoadBalancer = LoadBalancers.createLoadBalancer(loadBalancerType, stickyLoadBalancerCacheSize);
    gateway.setVertx(vertxService.getVertx());
    gateway.setPort(port);
    gateway.setServiceMap(serviceMap);
    gateway.setShutdownTacker(shutdownTacker);
    gateway.setServiceLoadBalancer(serviceLoadBalancer);
    gateway.setDefaultVirtualHost(defaultVirtualHost);
    ArrayList<Protocol> protocols = new ArrayList<Protocol>();
    if (isStompEnabled()) {
        protocols.add(new StompProtocol());
    }
    if (isMqttEnabled()) {
        protocols.add(new MqttProtocol());
    }
    if (isAmqpEnabled()) {
        protocols.add(new AmqpProtocol());
    }
    if (isOpenWireEnabled()) {
        protocols.add(new OpenwireProtocol());
    }
    if (isHttpEnabled()) {
        protocols.add(new HttpProtocol());
    }
    if (isSslEnabled()) {
        SslConfig sslConfig = new SslConfig();
        if (Strings.isNotBlank(sslAlgorithm)) {
            sslConfig.setAlgorithm(sslAlgorithm);
        }
        if (Strings.isNotBlank(keyAlias)) {
            sslConfig.setKeyAlias(keyAlias);
        }
        if (Strings.isNotBlank(keyPassword)) {
            sslConfig.setKeyPassword(keyPassword);
        }
        if (Strings.isNotBlank(keyStorePassword)) {
            sslConfig.setKeyStorePassword(keyStorePassword);
        }
        if (keyStoreURL != null) {
            sslConfig.setKeyStoreURL(keyStoreURL);
        }
        if (Strings.isNotBlank(sslProtocol)) {
            sslConfig.setProtocol(sslProtocol);
        }
        if (Strings.isNotBlank(sslStoreType)) {
            sslConfig.setStoreType(sslStoreType);
        }
        if (Strings.isNotBlank(trustStorePassword)) {
            sslConfig.setTrustStorePassword(trustStorePassword);
        }
        if (trustStoreURL != null) {
            sslConfig.setTrustStoreURL(trustStoreURL);
        }
        if (Strings.isNotBlank(enabledCipherSuites)) {
            sslConfig.setEnabledCipherSuites(enabledCipherSuites);
        }
        if (Strings.isNotBlank(disabledCypherSuites)) {
            sslConfig.setDisabledCypherSuites(disabledCypherSuites);
        }
        gateway.setSslConfig(sslConfig);
        // validating configuration
        try {
            SSLContext sslContext = SSLContext.getInstance(sslConfig.getProtocol());
            sslContext.init(sslConfig.getKeyManagers(), sslConfig.getTrustManagers(), null);
        } catch (Exception e) {
            throw new ComponentException(e);
        }
        protocols.add(new SslProtocol());
    }
    if (protocols.isEmpty()) {
        return null;
    }
    gateway.setProtocols(protocols);
    return gateway;
}
Also used : DetectingGateway(io.fabric8.gateway.handlers.detecting.DetectingGateway) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) VertxService(io.fabric8.gateway.fabric.support.vertx.VertxService) ArrayList(java.util.ArrayList) LoadBalancer(io.fabric8.gateway.loadbalancer.LoadBalancer) SSLContext(javax.net.ssl.SSLContext) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) ComponentException(org.osgi.service.component.ComponentException) ShutdownException(io.fabric8.common.util.ShutdownTracker.ShutdownException) SslConfig(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) ComponentException(org.osgi.service.component.ComponentException) MqttProtocol(io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol) SslProtocol(io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol) StompProtocol(io.fabric8.gateway.handlers.detecting.protocol.stomp.StompProtocol) AmqpProtocol(io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol) HttpProtocol(io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol) OpenwireProtocol(io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol) Protocol(io.fabric8.gateway.handlers.detecting.Protocol)

Example 13 with ComponentException

use of org.osgi.service.component.ComponentException in project opencast by opencast.

the class IndexServiceImplTest method setupCommonCatalogUIAdapter.

private Tuple<CommonEventCatalogUIAdapter, VCell<Option<MetadataCollection>>> setupCommonCatalogUIAdapter(Workspace workspace) throws org.osgi.service.cm.ConfigurationException {
    // Create Common Event Catalog UI Adapter
    final VCell<Option<MetadataCollection>> metadataCell = VCell.ocell();
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = new CommonEventCatalogUIAdapter() {

        @Override
        public Catalog storeFields(MediaPackage mediaPackage, MetadataCollection metadata) {
            metadataCell.set(Option.some(metadata));
            return super.storeFields(mediaPackage, metadata);
        }
    };
    Properties episodeCatalogProperties = new Properties();
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/episode-catalog.properties");
        episodeCatalogProperties.load(in);
    } catch (IOException e) {
        throw new ComponentException(e);
    } finally {
        IoSupport.closeQuietly(in);
    }
    commonEventCatalogUIAdapter.updated(PropertiesUtil.toDictionary(episodeCatalogProperties));
    commonEventCatalogUIAdapter.setWorkspace(workspace);
    return Tuple.tuple(commonEventCatalogUIAdapter, metadataCell);
}
Also used : InputStream(java.io.InputStream) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ComponentException(org.osgi.service.component.ComponentException) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) Option(org.opencastproject.util.data.Option) DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) IOException(java.io.IOException) Properties(java.util.Properties)

Example 14 with ComponentException

use of org.osgi.service.component.ComponentException in project opencast by opencast.

the class CatalogAdapterUtil method getCatalogProperties.

/**
 * Get the catalog properties from the given file
 *
 * @param sourceClass
 *          Source from where the the method is called
 * @param sourceFile
 *          the path to the source file
 * @return the catalog {@link Properties}
 */
public static Properties getCatalogProperties(Class<?> sourceClass, String sourceFile) {
    Properties episodeCatalogProperties = new Properties();
    InputStream in = null;
    try {
        in = sourceClass.getResourceAsStream(sourceFile);
        episodeCatalogProperties.load(in);
    } catch (IOException e) {
        throw new ComponentException(e);
    } finally {
        IoSupport.closeQuietly(in);
    }
    return episodeCatalogProperties;
}
Also used : InputStream(java.io.InputStream) ComponentException(org.osgi.service.component.ComponentException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 15 with ComponentException

use of org.osgi.service.component.ComponentException in project opencast by opencast.

the class MetadataListTest method setUp.

@Before
public void setUp() throws Exception {
    episodeDublinCoreCatalogUIAdapter = new CommonEventCatalogUIAdapter();
    Properties episodeCatalogProperties = new Properties();
    InputStream in = null;
    try {
        in = getClass().getResourceAsStream("/episode-catalog.properties");
        episodeCatalogProperties.load(in);
    } catch (IOException e) {
        throw new ComponentException(e);
    } finally {
        IoSupport.closeQuietly(in);
    }
    episodeDublinCoreCatalogUIAdapter.updated(PropertiesUtil.toDictionary(episodeCatalogProperties));
}
Also used : InputStream(java.io.InputStream) ComponentException(org.osgi.service.component.ComponentException) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) IOException(java.io.IOException) Properties(java.util.Properties) Before(org.junit.Before)

Aggregations

ComponentException (org.osgi.service.component.ComponentException)16 List (java.util.List)7 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 Properties (java.util.Properties)3 ArrayList (java.util.ArrayList)2 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)2 ComponentInstance (org.osgi.service.component.ComponentInstance)2 Listener (com.google.common.util.concurrent.Service.Listener)1 State (com.google.common.util.concurrent.Service.State)1 ShutdownException (io.fabric8.common.util.ShutdownTracker.ShutdownException)1 VertxService (io.fabric8.gateway.fabric.support.vertx.VertxService)1 DetectingGateway (io.fabric8.gateway.handlers.detecting.DetectingGateway)1 Protocol (io.fabric8.gateway.handlers.detecting.Protocol)1 AmqpProtocol (io.fabric8.gateway.handlers.detecting.protocol.amqp.AmqpProtocol)1 HttpProtocol (io.fabric8.gateway.handlers.detecting.protocol.http.HttpProtocol)1 MqttProtocol (io.fabric8.gateway.handlers.detecting.protocol.mqtt.MqttProtocol)1 OpenwireProtocol (io.fabric8.gateway.handlers.detecting.protocol.openwire.OpenwireProtocol)1 SslConfig (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslConfig)1 SslProtocol (io.fabric8.gateway.handlers.detecting.protocol.ssl.SslProtocol)1