Search in sources :

Example 1 with ResponseWriterDelegator

use of org.qi4j.library.rest.server.restlet.ResponseWriterDelegator 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)

Aggregations

Properties (java.util.Properties)1 VelocityEngine (org.apache.velocity.app.VelocityEngine)1 NewObjectImporter (org.qi4j.api.service.importer.NewObjectImporter)1 AssemblyException (org.qi4j.bootstrap.AssemblyException)1 RequestReaderDelegator (org.qi4j.library.rest.server.restlet.RequestReaderDelegator)1 ResponseWriterDelegator (org.qi4j.library.rest.server.restlet.ResponseWriterDelegator)1 ValueCompositeObjectWrapper (org.qi4j.library.rest.server.restlet.freemarker.ValueCompositeObjectWrapper)1