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);
}
}
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;
}
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);
}
}
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);
}
}
}
}
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);
}
}
Aggregations