Search in sources :

Example 16 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class DefaultStreamCachingTest method testStreamCaching.

public void testStreamCaching() throws Exception {
    AbstractApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "org/apache/camel/spring/streamCaching.xml" });
    CamelContext camelContext = appContext.getBean("camelContext", CamelContext.class);
    assertFalse("StreamCaching should not be enabled", camelContext.isStreamCaching());
    // we're done so let's properly close the application context
    IOHelper.close(appContext);
}
Also used : CamelContext(org.apache.camel.CamelContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 17 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project centipede by paulhoule.

the class StaticCentipedeShellTest method lazyEvaluationIsLazy.

@Test
public void lazyEvaluationIsLazy() {
    ApplicationContext c = newContext(objectCountingContext(), true);
    assertEquals(0, ObjectThatCountsClassInstances.get());
    Object that = c.getBean("l");
    assertEquals(1, ObjectThatCountsClassInstances.get());
    Object another = c.getBean("e");
    assertEquals(2, ObjectThatCountsClassInstances.get());
    ((AbstractApplicationContext) c).close();
    assertEquals(0, ObjectThatCountsClassInstances.get());
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) Test(org.junit.Test)

Example 18 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project centipede by paulhoule.

the class StaticCentipedeShellTest method eagerEvaluationIsEager.

@Test
public void eagerEvaluationIsEager() {
    ApplicationContext c = newContext(objectCountingContext(), false);
    assertEquals(2, ObjectThatCountsClassInstances.get());
    ((AbstractApplicationContext) c).close();
    assertEquals(0, ObjectThatCountsClassInstances.get());
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) Test(org.junit.Test)

Example 19 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project camel by apache.

the class Main method createDefaultApplicationContext.

protected AbstractApplicationContext createDefaultApplicationContext() {
    ApplicationContext parentContext = getParentApplicationContext();
    AnnotationConfigApplicationContext acApplicationContext = new AnnotationConfigApplicationContext();
    if (parentContext != null) {
        acApplicationContext.setParent(parentContext);
    }
    if (getConfigClasses() != null) {
        Class<?>[] configClasses = getConfigClasses(getConfigClasses());
        for (Class<?> cls : configClasses) {
            acApplicationContext.register(cls);
        }
    }
    if (getConfigClass() != null) {
        for (Class<?> cls : getConfigClass()) {
            acApplicationContext.register(cls);
        }
    }
    if (getBasedPackages() != null) {
        String[] basePackages = getBasedPackages().split("(;|,)");
        for (String basePackage : basePackages) {
            basePackage = basePackage.trim();
            acApplicationContext.scan(basePackage);
        }
    }
    acApplicationContext.refresh();
    return acApplicationContext;
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext)

Example 20 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project OpenMEAP by OpenMEAP.

the class AdminServlet method service.

@SuppressWarnings("unchecked")
@Override
public void service(HttpServletRequest request, HttpServletResponse response) {
    logger.trace("Entering service()");
    try {
        DocumentProcessor documentProcessor = null;
        logger.debug("Request uri: {}", request.getRequestURI());
        logger.debug("Request url: {}", request.getRequestURL());
        logger.debug("Query string: {}", request.getQueryString());
        if (logger.isDebugEnabled()) {
            logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap()));
        }
        if (request.getParameter("logout") != null) {
            logger.trace("Executing logout");
            request.getSession().invalidate();
            response.sendRedirect(request.getContextPath() + "/interface/");
        }
        if (request.getParameter("refreshContext") != null && context instanceof AbstractApplicationContext) {
            logger.trace("Refreshing context");
            ((AbstractApplicationContext) context).refresh();
        }
        // support for clearing the persistence context
        if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) {
            logger.trace("Clearing the persistence context");
            ModelServiceImpl ms = (ModelServiceImpl) ((AbstractApplicationContext) context).getBean("modelService");
            ms.clearPersistenceContext();
        }
        // default to the mainOptionPage, unless otherwise specified
        String pageBean = null;
        if (request.getParameter(FormConstants.PAGE_BEAN) != null)
            pageBean = request.getParameter(FormConstants.PAGE_BEAN);
        else
            pageBean = FormConstants.PAGE_BEAN_MAIN;
        logger.debug("Using page bean: {}", pageBean);
        documentProcessor = (DocumentProcessor) context.getBean(pageBean);
        ModelManager mgr = getModelManager();
        Map<Object, Object> map = new HashMap<Object, Object>();
        // TODO: I'm not really happy with this hacky work-around for the login form not being in actual request scope
        if (documentProcessor.getProcessesFormData()) {
            GlobalSettings settings = mgr.getGlobalSettings();
            map = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), settings.getTemporaryStoragePath(), request);
            map.put("userPrincipalName", new String[] { request.getUserPrincipal().getName() });
            AuthorizerImpl authorizer = (AuthorizerImpl) context.getBean("authorizer");
            authorizer.setRequest(request);
        }
        response.setContentType(FormConstants.CONT_TYPE_HTML);
        Map<Object, Object> defaultTemplateVars = new HashMap<Object, Object>();
        defaultTemplateVars.put("request", new BeanModel(request, new DefaultObjectWrapper()));
        documentProcessor.setTemplateVariables(defaultTemplateVars);
        documentProcessor.handleProcessAndRender(map, response.getWriter());
        response.getWriter().flush();
        response.getWriter().close();
    } catch (IOException te) {
        throw new RuntimeException(te);
    }
    logger.trace("Leaving service()");
}
Also used : BeanModel(freemarker.ext.beans.BeanModel) DocumentProcessor(com.openmeap.web.DocumentProcessor) HashMap(java.util.HashMap) AuthorizerImpl(com.openmeap.AuthorizerImpl) DefaultObjectWrapper(freemarker.template.DefaultObjectWrapper) GlobalSettings(com.openmeap.model.dto.GlobalSettings) IOException(java.io.IOException) ModelManager(com.openmeap.model.ModelManager) ModelServiceImpl(com.openmeap.model.ModelServiceImpl) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext)

Aggregations

AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)27 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 Test (org.junit.Test)6 ApplicationContext (org.springframework.context.ApplicationContext)6 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)3 ComponentLifecycle (com.cloud.utils.component.ComponentLifecycle)2 GlobalSettings (com.openmeap.model.dto.GlobalSettings)2 Method (java.lang.reflect.Method)2 AfterClass (org.junit.AfterClass)2 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)2 StopWatch (org.springframework.util.StopWatch)2 AuthorizerImpl (com.openmeap.AuthorizerImpl)1 InvalidPropertiesException (com.openmeap.model.InvalidPropertiesException)1 ModelManager (com.openmeap.model.ModelManager)1 ModelServiceImpl (com.openmeap.model.ModelServiceImpl)1 ClusterNode (com.openmeap.model.dto.ClusterNode)1 MapPayloadEvent (com.openmeap.model.event.MapPayloadEvent)1 Result (com.openmeap.services.dto.Result)1 JSONObject (com.openmeap.thirdparty.org.json.me.JSONObject)1