Search in sources :

Example 31 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.

the class RestServerAssembler method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    Properties props = new Properties();
    try {
        props.load(getClass().getResourceAsStream("/velocity.properties"));
        VelocityEngine velocity = new VelocityEngine(props);
        module.importedServices(VelocityEngine.class).importedBy(INSTANCE).setMetaInfo(velocity);
    } catch (Exception e) {
        throw new AssemblyException("Could not load velocity properties", e);
    }
    freemarker.template.Configuration cfg = new freemarker.template.Configuration();
    cfg.setClassForTemplateLoading(AbstractResponseWriter.class, "");
    cfg.setObjectWrapper(new ValueCompositeObjectWrapper());
    module.importedServices(freemarker.template.Configuration.class).setMetaInfo(cfg);
    module.importedServices(MetadataService.class);
    module.importedServices(ResponseWriterDelegator.class).identifiedBy("responsewriterdelegator").importedBy(NEW_OBJECT).visibleIn(Visibility.layer);
    module.objects(ResponseWriterDelegator.class);
    module.importedServices(RequestReaderDelegator.class).identifiedBy("requestreaderdelegator").importedBy(NEW_OBJECT).visibleIn(Visibility.layer);
    module.objects(RequestReaderDelegator.class);
    module.importedServices(InteractionConstraintsService.class).importedBy(NewObjectImporter.class).visibleIn(Visibility.application);
    module.objects(InteractionConstraintsService.class);
    // Standard response writers
    Iterable<Class<?>> writers = ClassScanner.findClasses(DefaultResponseWriter.class);
    Specification<Class<?>> responseWriterClass = isAssignableFrom(ResponseWriter.class);
    Specification<Class<?>> isNotAnAbstract = not(hasModifier(Modifier.ABSTRACT));
    Iterable<Class<?>> candidates = filter(and(isNotAnAbstract, responseWriterClass), writers);
    for (Class<?> responseWriter : candidates) {
        module.objects(responseWriter);
    }
    // Standard request readers
    module.objects(DefaultRequestReader.class);
}
Also used : VelocityEngine(org.apache.velocity.app.VelocityEngine) ValueCompositeObjectWrapper(org.qi4j.library.rest.server.restlet.freemarker.ValueCompositeObjectWrapper) ResponseWriterDelegator(org.qi4j.library.rest.server.restlet.ResponseWriterDelegator) Properties(java.util.Properties) AssemblyException(org.qi4j.bootstrap.AssemblyException) AssemblyException(org.qi4j.bootstrap.AssemblyException) NewObjectImporter(org.qi4j.api.service.importer.NewObjectImporter) RequestReaderDelegator(org.qi4j.library.rest.server.restlet.RequestReaderDelegator)

Example 32 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.

the class Qi4jApplicationBootstrapListener method createNewApplication.

private Application createNewApplication(ServletContext context) {
    Energy4Java qi4j = new Energy4Java();
    // Try create assembler
    final ApplicationAssembler assembler = createAssembler();
    if (assembler != null) {
        try {
            return qi4j.newApplication(assembler);
        } catch (AssemblyException e) {
            throw new IllegalStateException(e);
        }
    }
    return null;
}
Also used : AssemblyException(org.qi4j.bootstrap.AssemblyException) ApplicationAssembler(org.qi4j.bootstrap.ApplicationAssembler) Energy4Java(org.qi4j.bootstrap.Energy4Java)

Example 33 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.

the class WebHttpShiroTest method assemble.

@Override
public void assemble(ModuleAssembly module) throws AssemblyException {
    try {
        ModuleAssembly configModule = module;
        new EntityTestAssembler().assemble(configModule);
        // START SNIPPET: assembly
        new JettyServiceAssembler().withConfig(configModule, Visibility.layer).assemble(module);
        // END SNIPPET: assembly
        port = FreePortFinder.findFreePortOnLoopback();
        JettyConfiguration config = module.forMixin(JettyConfiguration.class).declareDefaults();
        config.hostName().set("127.0.0.1");
        config.port().set(port);
        // START SNIPPET: assembly
        new HttpShiroAssembler().withConfig(configModule, Visibility.layer).assemble(module);
        // END SNIPPET: assembly
        configModule.forMixin(ShiroIniConfiguration.class).declareDefaults().iniResourcePath().set("classpath:web-shiro.ini");
    } catch (IOException ex) {
        throw new AssemblyException("Unable to find free port to bind to", ex);
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) AssemblyException(org.qi4j.bootstrap.AssemblyException) JettyConfiguration(org.qi4j.library.http.JettyConfiguration) ShiroIniConfiguration(org.qi4j.library.shiro.ini.ShiroIniConfiguration) HttpShiroAssembler(org.qi4j.library.shiro.web.assembly.HttpShiroAssembler) EntityTestAssembler(org.qi4j.test.EntityTestAssembler) JettyServiceAssembler(org.qi4j.library.http.JettyServiceAssembler) IOException(java.io.IOException)

Example 34 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.

the class AbstractEntityStorePerformanceTest method whenCreateEntityWithComplexTypeInBatchThenRecordIterationsPerSecond.

@Test
public void whenCreateEntityWithComplexTypeInBatchThenRecordIterationsPerSecond() throws Exception {
    try {
        Assembler assembler = new Assembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                module.entities(ComplexProduct.class);
            }
        };
        createQi4jRuntime(assembler);
        profile(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Report report = new Report(storeName);
                report.start("createEntityInBulkWithComplexType");
                int bulk = 0;
                UnitOfWork uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithComplexType " + bulk));
                for (int i = 0; i < ITERATIONS; i++) {
                    ComplexProduct product = uow.newEntity(ComplexProduct.class);
                    String id = product.identity().get();
                    if (i % 1000 == 0) {
                        uow.complete();
                        bulk++;
                        uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithComplexType " + bulk));
                    }
                }
                uow.complete();
                report.stop(ITERATIONS);
                writeReport(report);
                return null;
            }
        });
    } finally {
        cleanUp();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Assembler(org.qi4j.bootstrap.Assembler) IOException(java.io.IOException) AssemblyException(org.qi4j.bootstrap.AssemblyException) Test(org.junit.Test)

Example 35 with AssemblyException

use of org.qi4j.bootstrap.AssemblyException in project qi4j-sdk by Qi4j.

the class AbstractEntityStorePerformanceTest method whenCreateEntityWithSinglePropertyInBatchThenRecordIterationsPerSecond.

@Test
public void whenCreateEntityWithSinglePropertyInBatchThenRecordIterationsPerSecond() throws Exception {
    try {
        Assembler assembler = new Assembler() {

            @Override
            public void assemble(ModuleAssembly module) throws AssemblyException {
                module.entities(SimpleProduct.class);
            }
        };
        createQi4jRuntime(assembler);
        profile(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                Report report = new Report(storeName);
                report.start("createEntityInBulkWithSingleProperty");
                int bulk = 0;
                UnitOfWork uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithSingleProperty " + bulk));
                for (int i = 0; i < ITERATIONS; i++) {
                    SimpleProduct product = uow.newEntity(SimpleProduct.class);
                    String id = product.identity().get();
                    if (i % 1000 == 0) {
                        uow.complete();
                        bulk++;
                        uow = module.newUnitOfWork(newUsecase("createEntityInBulkWithSingleProperty " + bulk));
                    }
                }
                uow.complete();
                report.stop(ITERATIONS);
                writeReport(report);
                return null;
            }
        });
    } finally {
        cleanUp();
    }
}
Also used : ModuleAssembly(org.qi4j.bootstrap.ModuleAssembly) UnitOfWork(org.qi4j.api.unitofwork.UnitOfWork) Assembler(org.qi4j.bootstrap.Assembler) IOException(java.io.IOException) AssemblyException(org.qi4j.bootstrap.AssemblyException) Test(org.junit.Test)

Aggregations

AssemblyException (org.qi4j.bootstrap.AssemblyException)38 ModuleAssembly (org.qi4j.bootstrap.ModuleAssembly)27 Test (org.junit.Test)23 Module (org.qi4j.api.structure.Module)14 SingletonAssembler (org.qi4j.bootstrap.SingletonAssembler)14 IOException (java.io.IOException)10 UnitOfWork (org.qi4j.api.unitofwork.UnitOfWork)10 ApplicationAssembler (org.qi4j.bootstrap.ApplicationAssembler)10 Assembler (org.qi4j.bootstrap.Assembler)10 ApplicationAssemblyFactory (org.qi4j.bootstrap.ApplicationAssemblyFactory)9 Application (org.qi4j.api.structure.Application)8 ApplicationAssembly (org.qi4j.bootstrap.ApplicationAssembly)8 Energy4Java (org.qi4j.bootstrap.Energy4Java)8 LayerAssembly (org.qi4j.bootstrap.LayerAssembly)5 EntityTestAssembler (org.qi4j.test.EntityTestAssembler)5 AmbiguousTypeException (org.qi4j.api.composite.AmbiguousTypeException)4 ApplicationDescriptor (org.qi4j.api.structure.ApplicationDescriptor)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 JettyConfiguration (org.qi4j.library.http.JettyConfiguration)2