Search in sources :

Example 86 with BeansException

use of org.springframework.beans.BeansException in project FredaBlog by yangjinlong86.

the class EncryptPropertyPlaceholderConfigurer method processProperties.

@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props) throws BeansException {
    try {
        String username = props.getProperty("username");
        if (StringUtils.isNotBlank(username)) {
            props.setProperty("username", EncryptUtil.decode(username));
        }
        String password = props.getProperty("password");
        if (StringUtils.isNotBlank(password)) {
            props.setProperty("password", EncryptUtil.decode(password));
        }
        super.processProperties(beanFactory, props);
    } catch (Exception e) {
        logger.error("encrypt error!", e);
        throw new BeanInitializationException(e.getMessage());
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) BeansException(org.springframework.beans.BeansException) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Example 87 with BeansException

use of org.springframework.beans.BeansException in project com.revolsys.open by revolsys.

the class BeanConfigurrer method processOverride.

/**
 * Process the given key as 'beanName.property' entry.
 */
protected void processOverride(final ConfigurableListableBeanFactory factory, final String key, Object value) {
    try {
        if (value instanceof BeanReference) {
            final BeanReference reference = (BeanReference) value;
            value = reference.getBean();
        }
        final Matcher matcher = BeanConfigurrer.KEY_PATTERN.matcher(key);
        if (matcher.matches()) {
            final String beanName = matcher.group(1);
            final String mapKey = matcher.group(2);
            final String propertyName = matcher.group(3);
            if (mapKey == null) {
                if (propertyName == null) {
                    if (factory.containsBean(beanName)) {
                        BeanDefinition beanDefinition = factory.getBeanDefinition(beanName);
                        try {
                            final ClassLoader classLoader = this.applicationContext.getClassLoader();
                            final String beanClassName = beanDefinition.getBeanClassName();
                            final Class<?> beanClass = Class.forName(beanClassName, true, classLoader);
                            if (Parameter.class.isAssignableFrom(beanClass)) {
                                while (beanDefinition.getOriginatingBeanDefinition() != null) {
                                    beanDefinition = beanDefinition.getOriginatingBeanDefinition();
                                }
                                final MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
                                PropertyValue propertyValue = new PropertyValue("value", value);
                                final PropertyValue typeValue = propertyValues.getPropertyValue("type");
                                if (typeValue != null) {
                                    try {
                                        final Class<?> typeClass;
                                        final Object typeValueObject = typeValue.getValue();
                                        if (typeValueObject instanceof Class<?>) {
                                            typeClass = (Class<?>) typeValueObject;
                                        } else {
                                            final String typeClassName = typeValueObject.toString();
                                            typeClass = Class.forName(typeClassName, true, classLoader);
                                        }
                                        final Object convertedValue = new SimpleTypeConverter().convertIfNecessary(value, typeClass);
                                        propertyValue = new PropertyValue("value", convertedValue);
                                    } catch (final Throwable e) {
                                        Logs.error(this, "Unable to set " + beanName + ".value=" + value, e);
                                    }
                                }
                                propertyValues.addPropertyValue(propertyValue);
                            }
                        } catch (final ClassNotFoundException e) {
                            Logs.error(this, "Unable to set " + beanName + ".value=" + value, e);
                        }
                    } else if (value != null) {
                        newParameterBeanDefinition(factory, beanName, value);
                    }
                } else {
                    setAttributeValue(factory, beanName, propertyName, value);
                    Logs.debug(this, "Property '" + key + "' set to value [" + value + "]");
                }
            } else if (propertyName == null) {
                setMapValue(factory, key, beanName, mapKey, value);
            } else {
                Logs.error(this, "Invalid syntax unable to set " + key + "=" + value);
            }
        }
    } catch (final BeansException ex) {
        final String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
        if (!this.ignoreInvalidKeys) {
            throw new BeanInitializationException(msg, ex);
        }
        Logs.debug(this, msg, ex);
    }
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) Matcher(java.util.regex.Matcher) PropertyValue(org.springframework.beans.PropertyValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) SimpleTypeConverter(org.springframework.beans.SimpleTypeConverter) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) BeanReference(com.revolsys.spring.BeanReference) BeansException(org.springframework.beans.BeansException)

Example 88 with BeansException

use of org.springframework.beans.BeansException in project archiva by apache.

the class DefaultWagonFactory method getWagon.

@Override
public Wagon getWagon(WagonFactoryRequest wagonFactoryRequest) throws WagonFactoryException {
    try {
        String protocol = StringUtils.startsWith(wagonFactoryRequest.getProtocol(), "wagon#") ? wagonFactoryRequest.getProtocol() : "wagon#" + wagonFactoryRequest.getProtocol();
        // wagon http client doesn't support that
        if (wagonFactoryRequest.getNetworkProxy() != null && wagonFactoryRequest.getNetworkProxy().isUseNtlm()) {
            protocol = protocol + "-ntlm";
        }
        Wagon wagon = applicationContext.getBean(protocol, Wagon.class);
        wagon.addTransferListener(debugTransferListener);
        configureUserAgent(wagon, wagonFactoryRequest);
        return wagon;
    } catch (BeansException e) {
        throw new WagonFactoryException(e.getMessage(), e);
    }
}
Also used : Wagon(org.apache.maven.wagon.Wagon) BeansException(org.springframework.beans.BeansException)

Example 89 with BeansException

use of org.springframework.beans.BeansException in project syncope by apache.

the class BulkActionResultColumn method populateItem.

@Override
public void populateItem(final Item<ICellPopulator<T>> item, final String componentId, final IModel<T> rowModel) {
    try {
        final Object id = BeanUtils.getPropertyDescriptor(rowModel.getObject().getClass(), keyFieldName).getReadMethod().invoke(rowModel.getObject(), new Object[0]);
        final Status status = results.getResults().containsKey(id.toString()) ? results.getResults().get(id.toString()) : Status.NOT_ATTEMPTED;
        item.add(new Label(componentId, new StringResourceModel(status.name(), item, new Model<>(status.name()))));
    } catch (BeansException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        LOG.error("Errore retrieving target id value", e);
    }
}
Also used : Status(org.apache.syncope.common.lib.to.BulkActionResult.Status) Label(org.apache.wicket.markup.html.basic.Label) StringResourceModel(org.apache.wicket.model.StringResourceModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeansException(org.springframework.beans.BeansException)

Example 90 with BeansException

use of org.springframework.beans.BeansException in project spring-integration by spring-projects.

the class AmqpOutboundChannelAdapterParserTests method testInt2718FailForOutboundAdapterChannelAttribute.

@Test
public void testInt2718FailForOutboundAdapterChannelAttribute() {
    try {
        new ClassPathXmlApplicationContext("AmqpOutboundChannelAdapterWithinChainParserTests-fail-context.xml", this.getClass()).close();
        fail("Expected BeanDefinitionParsingException");
    } catch (BeansException e) {
        assertTrue(e instanceof BeanDefinitionParsingException);
        assertTrue(e.getMessage().contains("The 'channel' attribute isn't allowed for " + "'amqp:outbound-channel-adapter' when it is used as a nested element"));
    }
}
Also used : BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Aggregations

BeansException (org.springframework.beans.BeansException)126 Test (org.junit.Test)24 ApplicationContext (org.springframework.context.ApplicationContext)22 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 BeanCreationException (org.springframework.beans.factory.BeanCreationException)11 HashMap (java.util.HashMap)10 BeanWrapper (org.springframework.beans.BeanWrapper)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 MalformedURLException (java.net.MalformedURLException)9 File (java.io.File)8 IOException (java.io.IOException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 List (java.util.List)7 Method (java.lang.reflect.Method)6 LinkedHashSet (java.util.LinkedHashSet)6