Search in sources :

Example 1 with AbstractApplicationContext

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

the class ServiceManagementServlet method service.

@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Result result = null;
    PrintWriter os = new PrintWriter(response.getOutputStream());
    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()));
    }
    String action = request.getParameter(UrlParamConstants.ACTION);
    if (action == null) {
        action = "";
    }
    if (!authenticates(request)) {
        logger.error("Request failed to authenticate ", request);
        result = new Result(Result.Status.FAILURE, "Authentication failed");
        sendResult(response, os, result);
        return;
    }
    if (action.equals(ModelEntityEventAction.MODEL_REFRESH.getActionName())) {
        logger.trace("Processing refresh");
        result = refresh(request, response);
        sendResult(response, os, result);
        return;
    } else if (action.equals(ClusterNodeRequest.HEALTH_CHECK)) {
        logger.trace("Cluster node health check");
        result = healthCheck(request, response);
        sendResult(response, os, result);
        return;
    }
    GlobalSettings settings = modelManager.getGlobalSettings();
    ClusterNode clusterNode = modelManager.getClusterNode();
    if (clusterNode == null) {
        throw new RuntimeException("openmeap-services-web needs to be configured as a cluster node in the settings of the admin interface.");
    }
    Map<Method, String> validationErrors = clusterNode.validate();
    if (validationErrors != null) {
        throw new RuntimeException(new InvalidPropertiesException(clusterNode, validationErrors));
    }
    if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) {
        logger.trace("Clearing persistence context");
        clearPersistenceContext();
    } else if (action.equals(ModelEntityEventAction.ARCHIVE_UPLOAD.getActionName())) {
        logger.trace("Processing archive upload - max file size: {}, storage path prefix: {}", settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix());
        archiveUploadHandler.setFileSystemStoragePathPrefix(clusterNode.getFileSystemStoragePathPrefix());
        Map<Object, Object> paramMap = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix(), request);
        result = handleArchiveEvent(archiveUploadHandler, new MapPayloadEvent(paramMap), paramMap);
    } else if (action.equals(ModelEntityEventAction.ARCHIVE_DELETE.getActionName())) {
        logger.trace("Processing archive delete - max file size: {}, storage path prefix: {}", settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix());
        archiveDeleteHandler.setFileSystemStoragePathPrefix(clusterNode.getFileSystemStoragePathPrefix());
        Map<Object, Object> paramMap = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix(), request);
        result = handleArchiveEvent(archiveDeleteHandler, new MapPayloadEvent(paramMap), paramMap);
    }
    sendResult(response, os, result);
}
Also used : ClusterNode(com.openmeap.model.dto.ClusterNode) GlobalSettings(com.openmeap.model.dto.GlobalSettings) MapPayloadEvent(com.openmeap.model.event.MapPayloadEvent) Method(java.lang.reflect.Method) Result(com.openmeap.services.dto.Result) InvalidPropertiesException(com.openmeap.model.InvalidPropertiesException) GenericRuntimeException(com.openmeap.util.GenericRuntimeException) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) JSONObject(com.openmeap.thirdparty.org.json.me.JSONObject) Map(java.util.Map) PrintWriter(java.io.PrintWriter)

Example 2 with AbstractApplicationContext

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

the class StaticCentipedeShellTest method defaultEvaluationIsDefinedInFiles.

@Test
public void defaultEvaluationIsDefinedInFiles() {
    ApplicationContext c = newContext(objectCountingContext());
    assertEquals(1, ObjectThatCountsClassInstances.get());
    Object that = c.getBean("l");
    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 3 with AbstractApplicationContext

use of org.springframework.context.support.AbstractApplicationContext in project spring-framework by spring-projects.

the class QuartzSchedulerLifecycleTests method destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang.

// SPR-6354
@Test
public void destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang() {
    AbstractApplicationContext context = new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", this.getClass());
    assertNotNull(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder"));
    StopWatch sw = new StopWatch();
    sw.start("lazyScheduler");
    context.destroy();
    sw.stop();
    assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 4 with AbstractApplicationContext

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

the class AnotherCamelProxyTest method testAnotherCamelProxy.

public void testAnotherCamelProxy() throws Exception {
    // START SNIPPET: e1
    AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/AnotherCamelProxyTest.xml");
    MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
    String reply = sender.hello("Camel");
    assertEquals("Bye Camel", reply);
    // we're done so let's properly close the application context
    IOHelper.close(ac);
// END SNIPPET: e1
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext)

Example 5 with AbstractApplicationContext

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

the class CamelProxyTest method testCamelProxy.

public void testCamelProxy() throws Exception {
    AbstractApplicationContext ac = new ClassPathXmlApplicationContext("org/apache/camel/spring/config/CamelProxyTest.xml");
    MyProxySender sender = ac.getBean("myProxySender", MyProxySender.class);
    String reply = sender.hello("World");
    assertEquals("Hello World", reply);
    // test sending inOnly message
    MyProxySender anotherSender = ac.getBean("myAnotherProxySender", MyProxySender.class);
    SpringCamelContext context = ac.getBeansOfType(SpringCamelContext.class).values().iterator().next();
    MockEndpoint result = resolveMandatoryEndpoint(context, "mock:result", MockEndpoint.class);
    result.expectedBodiesReceived("Hello my friends!");
    anotherSender.greeting("Hello my friends!");
    result.assertIsSatisfied();
    result.reset();
    // test sending inOnly message with other sender
    MyProxySender myProxySenderWithCamelContextId = ac.getBean("myProxySenderWithCamelContextId", MyProxySender.class);
    result.expectedBodiesReceived("Hello my friends again!");
    myProxySenderWithCamelContextId.greeting("Hello my friends again!");
    result.assertIsSatisfied();
    // we're done so let's properly close the application context
    IOHelper.close(ac);
}
Also used : AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) SpringCamelContext(org.apache.camel.spring.SpringCamelContext)

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