Search in sources :

Example 6 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class ServiceAssemblyImpl method newServiceModel.

@SuppressWarnings({ "raw", "unchecked" })
ServiceModel newServiceModel(StateDeclarations stateDeclarations, AssemblyHelper helper) {
    try {
        buildComposite(helper, stateDeclarations);
        List<Class<? extends Activator<?>>> activatorClasses = Iterables.toList(Iterables.<Class<? extends Activator<?>>>flatten(activators, activatorsDeclarations(types)));
        return new ServiceModel(types, visibility, metaInfo, new ActivatorsModel(activatorClasses), mixinsModel, stateModel, compositeMethodsModel, identity, instantiateOnStartup);
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : Activator(org.qi4j.api.activation.Activator) ServiceModel(org.qi4j.runtime.service.ServiceModel) ActivatorsModel(org.qi4j.runtime.activation.ActivatorsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 7 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class ApplicationModel method newInstance.

@Override
public ApplicationInstance newInstance(Qi4j runtime, Object... importedServiceInstances) throws InvalidApplicationException {
    MetaInfo instanceMetaInfo = new MetaInfo(metaInfo);
    for (Object importedServiceInstance : importedServiceInstances) {
        instanceMetaInfo.set(importedServiceInstance);
    }
    ApplicationInstance applicationInstance = new ApplicationInstance(this, (Qi4jRuntime) runtime, instanceMetaInfo);
    // Create layer instances
    Map<LayerModel, LayerInstance> layerInstanceMap = new HashMap<>();
    Map<LayerModel, List<LayerInstance>> usedLayers = new HashMap<>();
    for (LayerModel layer : layers) {
        List<LayerInstance> usedLayerInstances = new ArrayList<>();
        usedLayers.put(layer, usedLayerInstances);
        UsedLayersInstance usedLayersInstance = layer.usedLayers().newInstance(usedLayerInstances);
        LayerInstance layerInstance = layer.newInstance(applicationInstance, usedLayersInstance);
        applicationInstance.addLayer(layerInstance);
        layerInstanceMap.put(layer, layerInstance);
    }
    // Resolve used layer instances
    for (LayerModel layer : layers) {
        List<LayerInstance> usedLayerInstances = usedLayers.get(layer);
        for (LayerModel usedLayer : layer.usedLayers().layers()) {
            LayerInstance layerInstance = layerInstanceMap.get(usedLayer);
            if (layerInstance == null) {
                throw new InvalidApplicationException("Could not find used layer:" + usedLayer.name());
            }
            usedLayerInstances.add(layerInstance);
        }
    }
    return applicationInstance;
}
Also used : HashMap(java.util.HashMap) MetaInfo(org.qi4j.api.common.MetaInfo) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 8 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class ValueAssemblyImpl method newValueModel.

ValueModel newValueModel(StateDeclarations stateDeclarations, AssemblyHelper helper) {
    try {
        associationsModel = new AssociationsModel();
        manyAssociationsModel = new ManyAssociationsModel();
        namedAssociationsModel = new NamedAssociationsModel();
        buildComposite(helper, stateDeclarations);
        ValueModel valueModel = new ValueModel(types, visibility, metaInfo, mixinsModel, (ValueStateModel) stateModel, compositeMethodsModel);
        return valueModel;
    } catch (Exception e) {
        throw new InvalidApplicationException("Could not register " + types, e);
    }
}
Also used : ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) ValueModel(org.qi4j.runtime.value.ValueModel) NamedAssociationsModel(org.qi4j.runtime.association.NamedAssociationsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) ManyAssociationsModel(org.qi4j.runtime.association.ManyAssociationsModel) AssociationsModel(org.qi4j.runtime.association.AssociationsModel) NamedAssociationsModel(org.qi4j.runtime.association.NamedAssociationsModel) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Example 9 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class JettyConfigurationHelper method configureSsl.

static void configureSsl(SslConnectionFactory sslConnFactory, SecureJettyConfiguration config) {
    SslContextFactory ssl = sslConnFactory.getSslContextFactory();
    boolean needBouncyCastle = false;
    // KeyStore
    String keystoreType = config.keystoreType().get();
    String keystorePath = config.keystorePath().get();
    String keystorePassword = config.keystorePassword().get();
    ssl.setKeyStoreType(keystoreType);
    if ("PKCS12".equals(keystoreType)) {
        // WARN This one needs BouncyCastle on the classpath
        ssl.setKeyStoreProvider("BC");
        needBouncyCastle = true;
    }
    ssl.setKeyStorePath(keystorePath);
    ssl.setKeyStorePassword(keystorePassword);
    // Certificate alias
    String certAlias = config.certAlias().get();
    if (certAlias != null) {
        ssl.setCertAlias(certAlias);
    }
    // TrustStore
    String truststoreType = config.truststoreType().get();
    String truststorePath = config.truststorePath().get();
    String truststorePassword = config.truststorePassword().get();
    if (truststoreType != null && truststorePath != null) {
        ssl.setTrustStoreType(truststoreType);
        if ("PKCS12".equals(truststoreType)) {
            ssl.setTrustStoreProvider("BC");
            needBouncyCastle = true;
        }
        ssl.setTrustStorePath(truststorePath);
        ssl.setTrustStorePassword(truststorePassword);
    }
    // Need / Want Client Auth
    Boolean want = config.wantClientAuth().get();
    if (want != null) {
        ssl.setWantClientAuth(want);
    }
    Boolean need = config.needClientAuth().get();
    if (need != null) {
        ssl.setNeedClientAuth(need);
    }
    // Algorithms
    String secureRandomAlgo = config.secureRandomAlgorithm().get();
    if (secureRandomAlgo != null) {
        ssl.setSecureRandomAlgorithm(secureRandomAlgo);
    }
    String cipherExcludesConfigString = config.excludeCipherSuites().get();
    if (cipherExcludesConfigString != null) {
        String[] cipherExcludes = cipherExcludesConfigString.split(COMA);
        if (cipherExcludes.length > 0) {
            ssl.setExcludeCipherSuites(cipherExcludes);
        }
    }
    String cipherIncludesConfigString = config.includeCipherSuites().get();
    if (cipherIncludesConfigString != null) {
        String[] cipherIncludes = cipherIncludesConfigString.split(COMA);
        if (cipherIncludes.length > 0) {
            ssl.setIncludeCipherSuites(cipherIncludes);
        }
    }
    // SSL Handling
    Boolean cacheSslSessions = config.cacheSslSessions().get();
    if (cacheSslSessions != null) {
        ssl.setSessionCachingEnabled(cacheSslSessions);
    }
    ssl.setRenegotiationAllowed(config.allowRenegotiation().get());
    // Validation Flags
    Integer maxCertPathLength = config.maxCertPathLength().get();
    if (maxCertPathLength != null) {
        ssl.setMaxCertPathLength(maxCertPathLength);
    }
    ssl.setValidateCerts(config.validateServerCert().get());
    ssl.setValidatePeerCerts(config.validatePeerCerts().get());
    // Validation CRL
    String crlFilePath = config.crlFilePath().get();
    if (crlFilePath != null && crlFilePath.length() > 0) {
        ssl.setCrlPath(crlFilePath);
    }
    ssl.setEnableCRLDP(config.enableCRLDP().get());
    // Validation OCSP
    ssl.setEnableOCSP(config.enableOCSP().get());
    String ocspURL = config.ocspResponderURL().get();
    if (ocspURL != null) {
        ssl.setOcspResponderURL(ocspURL);
    }
    // Load BouncyCastle ?
    if (needBouncyCastle) {
        Provider bc = Security.getProvider("BC");
        if (bc == null) {
            try {
                Security.addProvider((Provider) Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider").newInstance());
            } catch (Exception ex) {
                throw new InvalidApplicationException("Need to open a PKCS#12 but was unable to register BouncyCastle, check your classpath", ex);
            }
        }
    }
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) Provider(java.security.Provider)

Example 10 with InvalidApplicationException

use of org.qi4j.api.common.InvalidApplicationException in project qi4j-sdk by Qi4j.

the class AbstractQi4jServletBootstrap method contextInitialized.

@Override
public final void contextInitialized(ServletContextEvent sce) {
    try {
        ServletContext context = sce.getServletContext();
        LOGGER.trace("Assembling Application");
        qi4j = new Energy4Java();
        applicationModel = qi4j.newApplicationModel(this);
        LOGGER.trace("Instanciating and activating Application");
        application = applicationModel.newInstance(qi4j.api());
        api = qi4j.api();
        beforeApplicationActivation(application);
        application.activate();
        afterApplicationActivation(application);
        LOGGER.trace("Storing Application in ServletContext");
        context.setAttribute(Qi4jServletSupport.APP_IN_CTX, application);
    } catch (Exception ex) {
        if (application != null) {
            try {
                beforeApplicationPassivation(application);
                application.passivate();
                afterApplicationPassivation(application);
            } catch (Exception ex1) {
                LOGGER.warn("Application not null and could not passivate it.", ex1);
            }
        }
        throw new InvalidApplicationException("Unexpected error during ServletContext initialization, see previous log for errors.", ex);
    }
}
Also used : ServletContext(javax.servlet.ServletContext) Energy4Java(org.qi4j.bootstrap.Energy4Java) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException) InvalidApplicationException(org.qi4j.api.common.InvalidApplicationException)

Aggregations

InvalidApplicationException (org.qi4j.api.common.InvalidApplicationException)10 MetaInfo (org.qi4j.api.common.MetaInfo)3 AssociationsModel (org.qi4j.runtime.association.AssociationsModel)3 ManyAssociationsModel (org.qi4j.runtime.association.ManyAssociationsModel)3 NamedAssociationsModel (org.qi4j.runtime.association.NamedAssociationsModel)3 ActivatorsModel (org.qi4j.runtime.activation.ActivatorsModel)2 ValueModel (org.qi4j.runtime.value.ValueModel)2 ParameterizedType (java.lang.reflect.ParameterizedType)1 Type (java.lang.reflect.Type)1 TypeVariable (java.lang.reflect.TypeVariable)1 Provider (java.security.Provider)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ServletContext (javax.servlet.ServletContext)1 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)1 Activator (org.qi4j.api.activation.Activator)1 CollectionType (org.qi4j.api.type.CollectionType)1 EnumType (org.qi4j.api.type.EnumType)1 MapType (org.qi4j.api.type.MapType)1