use of org.springframework.beans.factory.BeanCreationException in project BroadleafCommerce by BroadleafCommerce.
the class AbstractRemoveBeanPostProcessor method postProcessBeforeInitialization.
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (beanName.equals(targetRef)) {
if (bean instanceof ListFactoryBean || bean instanceof List) {
Object beanToRemove = applicationContext.getBean(beanRef);
try {
List sourceList;
if (bean instanceof ListFactoryBean) {
Field field = ListFactoryBean.class.getDeclaredField("sourceList");
field.setAccessible(true);
sourceList = (List) field.get(bean);
} else {
sourceList = (List) bean;
}
Iterator itr = sourceList.iterator();
while (itr.hasNext()) {
Object member = itr.next();
if (member.equals(beanToRemove)) {
itr.remove();
}
}
} catch (Exception e) {
throw new BeanCreationException(e.getMessage());
}
} else if (bean instanceof SetFactoryBean || bean instanceof Set) {
Object beanToRemove = applicationContext.getBean(beanRef);
try {
Set sourceSet;
if (bean instanceof SetFactoryBean) {
Field field = SetFactoryBean.class.getDeclaredField("sourceSet");
field.setAccessible(true);
sourceSet = (Set) field.get(bean);
} else {
sourceSet = (Set) bean;
}
List tempList = new ArrayList(sourceSet);
Iterator itr = tempList.iterator();
while (itr.hasNext()) {
Object member = itr.next();
if (member.equals(beanToRemove)) {
itr.remove();
}
}
sourceSet.clear();
sourceSet.addAll(tempList);
} catch (Exception e) {
throw new BeanCreationException(e.getMessage());
}
} else if (bean instanceof MapFactoryBean || bean instanceof Map) {
try {
Map sourceMap;
if (bean instanceof MapFactoryBean) {
Field field = MapFactoryBean.class.getDeclaredField("sourceMap");
field.setAccessible(true);
sourceMap = (Map) field.get(bean);
} else {
sourceMap = (Map) bean;
}
Object key;
if (mapKey != null) {
key = mapKey;
} else {
key = applicationContext.getBean(mapKeyRef);
}
Map referenceMap = new LinkedHashMap(sourceMap);
for (Object sourceKey : referenceMap.keySet()) {
if (sourceKey.equals(key)) {
sourceMap.remove(key);
}
}
} catch (Exception e) {
throw new BeanCreationException(e.getMessage());
}
} else {
throw new IllegalArgumentException("Bean (" + beanName + ") is specified as a merge target, " + "but is not" + " of type ListFactoryBean, SetFactoryBean or MapFactoryBean");
}
}
return bean;
}
use of org.springframework.beans.factory.BeanCreationException in project citrus-samples by christophd.
the class EndpointConfig method httpClient.
@Bean
public HttpClient httpClient() {
try {
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(), new TrustSelfSignedStrategy()).build();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslcontext, NoopHostnameVerifier.INSTANCE);
return HttpClients.custom().setSSLSocketFactory(sslSocketFactory).setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor()).build();
} catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new BeanCreationException("Failed to create http client for ssl connection", e);
}
}
use of org.springframework.beans.factory.BeanCreationException in project kork by spinnaker.
the class DynomiteClientDelegateFactory method convertSpringProperties.
/**
* Spring config parsing is v. dumb. It will start making any iterable a map after a certain
* depth, so this method massages the data into something we can actually use.
*/
@SuppressWarnings("unchecked")
private DynomiteDriverProperties convertSpringProperties(Map<String, Object> properties) {
Map<String, Object> props = new HashMap<>(properties);
Map<String, Object> springHosts = (Map<String, Object>) properties.get("hosts");
if (springHosts == null) {
throw new BeanCreationException("Dynomite hosts must be set");
}
props.put("hosts", new ArrayList<>(springHosts.values()));
ObjectMapper mapper = objectMapper.copy();
SimpleModule simpleModule = new SimpleModule();
simpleModule.addDeserializer(ConnectionPoolConfigurationImpl.class, new ConnectionPoolConfigurationImplDeserializer((String) props.get("applicationName")));
mapper.registerModule(simpleModule);
return mapper.convertValue(props, DynomiteDriverProperties.class);
}
use of org.springframework.beans.factory.BeanCreationException in project kork by spinnaker.
the class JedisHealthIndicatorFactory method build.
public static HealthIndicator build(Pool<Jedis> jedisPool) {
try {
final Pool<Jedis> src = jedisPool;
final Field poolAccess = Pool.class.getDeclaredField("internalPool");
poolAccess.setAccessible(true);
GenericObjectPool<Jedis> internal = (GenericObjectPool<Jedis>) poolAccess.get(jedisPool);
return () -> {
Jedis jedis = null;
Health.Builder health;
try {
jedis = src.getResource();
if ("PONG".equals(jedis.ping())) {
health = Health.up();
} else {
health = Health.down();
}
} catch (Exception ex) {
health = Health.down(ex);
} finally {
if (jedis != null)
jedis.close();
}
health.withDetail("maxIdle", internal.getMaxIdle());
health.withDetail("minIdle", internal.getMinIdle());
health.withDetail("numActive", internal.getNumActive());
health.withDetail("numIdle", internal.getNumIdle());
health.withDetail("numWaiters", internal.getNumWaiters());
return health.build();
};
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new BeanCreationException("Error creating Redis health indicator", e);
}
}
use of org.springframework.beans.factory.BeanCreationException in project spring-security by spring-projects.
the class CorsBeanDefinitionParser method parse.
public BeanMetadataElement parse(Element element, ParserContext parserContext) {
if (element == null) {
return null;
}
String filterRef = element.getAttribute(ATT_REF);
if (StringUtils.hasText(filterRef)) {
return new RuntimeBeanReference(filterRef);
}
BeanMetadataElement configurationSource = getSource(element, parserContext);
if (configurationSource == null) {
throw new BeanCreationException("Could not create CorsFilter");
}
BeanDefinitionBuilder filterBldr = BeanDefinitionBuilder.rootBeanDefinition(CorsFilter.class);
filterBldr.addConstructorArgValue(configurationSource);
return filterBldr.getBeanDefinition();
}
Aggregations