Search in sources :

Example 21 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project spring-security by spring-projects.

the class WebTestUtils method getSpringSecurityFilterChain.

private static Filter getSpringSecurityFilterChain(ServletContext servletContext) {
    Filter result = (Filter) servletContext.getAttribute(BeanIds.SPRING_SECURITY_FILTER_CHAIN);
    if (result != null) {
        return result;
    }
    WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
    if (webApplicationContext != null) {
        try {
            return webApplicationContext.getBean(AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME, Filter.class);
        } catch (NoSuchBeanDefinitionException notFound) {
        }
    }
    return null;
}
Also used : CsrfFilter(org.springframework.security.web.csrf.CsrfFilter) SecurityContextPersistenceFilter(org.springframework.security.web.context.SecurityContextPersistenceFilter) Filter(javax.servlet.Filter) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 22 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project aries by apache.

the class SpringTest method testSpringBundle.

@Test
public void testSpringBundle() throws Exception {
    Bundle bundles = context().getBundleByName("org.apache.aries.blueprint.testbundles");
    assertNotNull(bundles);
    bundles.start();
    BlueprintContainer container = startBundleBlueprint("org.apache.aries.blueprint.testbundles");
    List list = (List) container.getComponentInstance("springList");
    System.out.println(list);
    BeanCItf beanC = (BeanCItf) list.get(4);
    assertEquals(1, beanC.getInitialized());
    try {
        beanC.doSomething();
        fail("Should have thrown an exception because the transaction manager is not defined");
    } catch (NoSuchBeanDefinitionException e) {
    // expected
    }
}
Also used : BlueprintContainer(org.osgi.service.blueprint.container.BlueprintContainer) Helper.mvnBundle(org.apache.aries.blueprint.itests.Helper.mvnBundle) CoreOptions.mavenBundle(org.ops4j.pax.exam.CoreOptions.mavenBundle) Bundle(org.osgi.framework.Bundle) List(java.util.List) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) BeanCItf(org.apache.aries.blueprint.testbundles.BeanCItf) Test(org.junit.Test)

Example 23 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cloudstack by apache.

the class UsageEventUtils method publishUsageEvent.

private static void publishUsageEvent(String usageEventType, Long accountId, Long zoneId, String resourceType, String resourceUUID) {
    String configKey = "publish.usage.events";
    String value = s_configDao.getValue(configKey);
    boolean configValue = Boolean.parseBoolean(value);
    if (!configValue)
        return;
    try {
        s_eventBus = ComponentContext.getComponent(EventBus.class);
    } catch (NoSuchBeanDefinitionException nbe) {
        // no provider is configured to provide events bus, so just return
        return;
    }
    Account account = s_accountDao.findById(accountId);
    DataCenterVO dc = s_dcDao.findById(zoneId);
    // if account has been deleted, this might be called during cleanup of resources and results in null pointer
    if (account == null)
        return;
    // if an invalid zone is passed in, create event without zone UUID
    String zoneUuid = null;
    if (dc != null)
        zoneUuid = dc.getUuid();
    Event event = new Event(Name, EventCategory.USAGE_EVENT.getName(), usageEventType, resourceType, resourceUUID);
    Map<String, String> eventDescription = new HashMap<String, String>();
    eventDescription.put("account", account.getUuid());
    eventDescription.put("zone", zoneUuid);
    eventDescription.put("event", usageEventType);
    eventDescription.put("resource", resourceType);
    eventDescription.put("id", resourceUUID);
    String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    event.setDescription(eventDescription);
    try {
        s_eventBus.publish(event);
    } catch (EventBusException e) {
        s_logger.warn("Failed to publish usage event on the the event bus.");
    }
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) Account(com.cloud.user.Account) HashMap(java.util.HashMap) Event(org.apache.cloudstack.framework.events.Event) EventBusException(org.apache.cloudstack.framework.events.EventBusException) EventBus(org.apache.cloudstack.framework.events.EventBus) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 24 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cloudstack by apache.

the class ActionEventUtils method publishOnEventBus.

private static void publishOnEventBus(long userId, long accountId, String eventCategory, String eventType, Event.State state, String description) {
    String configKey = Config.PublishActionEvent.key();
    String value = s_configDao.getValue(configKey);
    boolean configValue = Boolean.parseBoolean(value);
    if (!configValue)
        return;
    try {
        s_eventBus = ComponentContext.getComponent(EventBus.class);
    } catch (NoSuchBeanDefinitionException nbe) {
        // no provider is configured to provide events bus, so just return
        return;
    }
    // get the entity details for which ActionEvent is generated
    String entityType = null;
    String entityUuid = null;
    CallContext context = CallContext.current();
    //Get entity Class(Example - VirtualMachine.class) from the event Type eg. - VM.CREATE
    Class<?> entityClass = EventTypes.getEntityClassForEvent(eventType);
    if (entityClass != null) {
        //Get uuid from id
        Object param = context.getContextParameter(entityClass);
        if (param != null) {
            try {
                entityUuid = getEntityUuid(entityClass, param);
                entityType = entityClass.getName();
            } catch (Exception e) {
                s_logger.debug("Caught exception while finding entityUUID, moving on");
            }
        }
    }
    org.apache.cloudstack.framework.events.Event event = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, eventCategory, eventType, EventTypes.getEntityForEvent(eventType), entityUuid);
    Map<String, String> eventDescription = new HashMap<String, String>();
    Project project = s_projectDao.findByProjectAccountId(accountId);
    Account account = s_accountDao.findById(accountId);
    User user = s_userDao.findById(userId);
    // if account has been deleted, this might be called during cleanup of resources and results in null pointer
    if (account == null)
        return;
    if (user == null)
        return;
    if (project != null)
        eventDescription.put("project", project.getUuid());
    eventDescription.put("user", user.getUuid());
    eventDescription.put("account", account.getUuid());
    eventDescription.put("event", eventType);
    eventDescription.put("status", state.toString());
    eventDescription.put("entity", entityType);
    eventDescription.put("entityuuid", entityUuid);
    //Put all the first class entities that are touched during the action. For now atleast put in the vmid.
    populateFirstClassEntities(eventDescription);
    eventDescription.put("description", description);
    String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    event.setDescription(eventDescription);
    try {
        s_eventBus.publish(event);
    } catch (EventBusException e) {
        s_logger.warn("Failed to publish action event on the the event bus.");
    }
}
Also used : Account(com.cloud.user.Account) User(com.cloud.user.User) HashMap(java.util.HashMap) EventBus(org.apache.cloudstack.framework.events.EventBus) CallContext(org.apache.cloudstack.context.CallContext) EventBusException(org.apache.cloudstack.framework.events.EventBusException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) Date(java.util.Date) Project(com.cloud.projects.Project) EventBusException(org.apache.cloudstack.framework.events.EventBusException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 25 with NoSuchBeanDefinitionException

use of org.springframework.beans.factory.NoSuchBeanDefinitionException in project cloudstack by apache.

the class UserVmStateListener method pubishOnEventBus.

private void pubishOnEventBus(String event, String status, VirtualMachine vo, VirtualMachine.State oldState, VirtualMachine.State newState) {
    String configKey = Config.PublishResourceStateEvent.key();
    String value = _configDao.getValue(configKey);
    boolean configValue = Boolean.parseBoolean(value);
    if (!configValue)
        return;
    try {
        s_eventBus = ComponentContext.getComponent(EventBus.class);
    } catch (NoSuchBeanDefinitionException nbe) {
        // no provider is configured to provide events bus, so just return
        return;
    }
    String resourceName = getEntityFromClassName(VirtualMachine.class.getName());
    org.apache.cloudstack.framework.events.Event eventMsg = new org.apache.cloudstack.framework.events.Event(ManagementService.Name, EventCategory.RESOURCE_STATE_CHANGE_EVENT.getName(), event, resourceName, vo.getUuid());
    Map<String, String> eventDescription = new HashMap<String, String>();
    eventDescription.put("resource", resourceName);
    eventDescription.put("id", vo.getUuid());
    eventDescription.put("old-state", oldState.name());
    eventDescription.put("new-state", newState.name());
    eventDescription.put("status", status);
    String eventDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z").format(new Date());
    eventDescription.put("eventDateTime", eventDate);
    eventMsg.setDescription(eventDescription);
    try {
        s_eventBus.publish(eventMsg);
    } catch (org.apache.cloudstack.framework.events.EventBusException e) {
        s_logger.warn("Failed to publish state change event on the the event bus.");
    }
}
Also used : HashMap(java.util.HashMap) EventBus(org.apache.cloudstack.framework.events.EventBus) Date(java.util.Date) Event(com.cloud.vm.VirtualMachine.Event) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)64 Test (org.junit.Test)27 BeanCreationException (org.springframework.beans.factory.BeanCreationException)18 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)15 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)14 HashMap (java.util.HashMap)8 EventBus (org.apache.cloudstack.framework.events.EventBus)8 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)8 SimpleDateFormat (java.text.SimpleDateFormat)7 Date (java.util.Date)7 EventBusException (org.apache.cloudstack.framework.events.EventBusException)7 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)7 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)6 ConfigurableBeanFactory (org.springframework.beans.factory.config.ConfigurableBeanFactory)6 BeanFactory (org.springframework.beans.factory.BeanFactory)5 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)5 ArrayList (java.util.ArrayList)4 Account (com.cloud.user.Account)3 Method (java.lang.reflect.Method)3 ApplicationContext (org.springframework.context.ApplicationContext)3