use of org.springframework.beans.factory.BeanFactory in project com.revolsys.open by revolsys.
the class JndiObjectFactory method createInstance.
@Override
protected Object createInstance() throws Exception {
final Hashtable<Object, Object> initialEnvironment = new Hashtable<>();
final String initialFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY);
final BeanFactory beanFactory = getBeanFactory();
if (initialFactory != null) {
initialEnvironment.put(Context.INITIAL_CONTEXT_FACTORY, initialFactory);
}
Object savedObject;
if (initialFactory == null && !NamingManager.hasInitialContextFactoryBuilder()) {
final SimpleNamingContextBuilder builder = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
synchronized (this.beanName.intern()) {
savedObject = beanFactory.getBean(this.beanName);
builder.bind(this.jndiUrl, savedObject);
}
} else {
Context context;
if (NamingManager.hasInitialContextFactoryBuilder()) {
context = NamingManager.getInitialContext(initialEnvironment);
} else {
context = new InitialContext();
}
try {
savedObject = context.lookup(this.jndiUrl);
} catch (final NameNotFoundException e) {
synchronized (this.beanName.intern()) {
savedObject = beanFactory.getBean(this.beanName);
try {
context.bind(this.jndiUrl, savedObject);
} catch (final NameNotFoundException e2) {
}
}
}
if (savedObject == null) {
synchronized (this.beanName.intern()) {
Logs.error(this, "JNDI data source was null " + this.jndiUrl);
savedObject = beanFactory.getBean(this.beanName);
}
}
}
return null;
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class MapToObjectTransformerTests method testMapToObjectTransformationWithConversionService.
@Test
public void testMapToObjectTransformationWithConversionService() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("fname", "Justin");
map.put("lname", "Case");
map.put("address", "1123 Main st");
Message<?> message = MessageBuilder.withPayload(map).build();
MapToObjectTransformer transformer = new MapToObjectTransformer(Person.class);
BeanFactory beanFactory = this.getBeanFactory();
ConverterRegistry conversionService = beanFactory.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, ConverterRegistry.class);
conversionService.addConverter(new StringToAddressConverter());
transformer.setBeanFactory(beanFactory);
Message<?> newMessage = transformer.transform(message);
Person person = (Person) newMessage.getPayload();
assertNotNull(person);
assertEquals("Justin", person.getFname());
assertEquals("Case", person.getLname());
assertNotNull(person.getAddress());
assertEquals("1123 Main st", person.getAddress().getStreet());
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class AbstractCorrelatingMessageHandler method onInit.
@Override
protected void onInit() throws Exception {
super.onInit();
Assert.state(!(this.discardChannelName != null && this.discardChannel != null), "'discardChannelName' and 'discardChannel' are mutually exclusive.");
BeanFactory beanFactory = this.getBeanFactory();
if (beanFactory != null) {
if (this.outputProcessor instanceof BeanFactoryAware) {
((BeanFactoryAware) this.outputProcessor).setBeanFactory(beanFactory);
}
if (this.correlationStrategy instanceof BeanFactoryAware) {
((BeanFactoryAware) this.correlationStrategy).setBeanFactory(beanFactory);
}
if (this.releaseStrategy instanceof BeanFactoryAware) {
((BeanFactoryAware) this.releaseStrategy).setBeanFactory(beanFactory);
}
}
if (this.discardChannel == null) {
this.discardChannel = new NullChannel();
}
if (this.releasePartialSequences) {
Assert.isInstanceOf(SequenceSizeReleaseStrategy.class, this.releaseStrategy, "Release strategy of type [" + this.releaseStrategy.getClass().getSimpleName() + "] cannot release partial sequences. Use a SequenceSizeReleaseStrategy instead.");
((SequenceSizeReleaseStrategy) this.releaseStrategy).setReleasePartialSequences(this.releasePartialSequences);
}
if (this.evaluationContext == null) {
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
if (this.sequenceAware) {
this.logger.warn("Using a SequenceSizeReleaseStrategy with large groups may not perform well, consider " + "using a SimpleSequenceSizeReleaseStrategy");
}
/*
* Disallow any further changes to the lock registry
* (checked in the setter).
*/
this.lockRegistrySet = true;
this.forceReleaseProcessor = createGroupTimeoutProcessor();
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class HeaderChannelRegistryTests method testBFCRNoRegistry.
@Test
public void testBFCRNoRegistry() {
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
BeanFactory beanFactory = mock(BeanFactory.class);
doAnswer(invocation -> {
throw new NoSuchBeanDefinitionException("bar");
}).when(beanFactory).getBean("foo", MessageChannel.class);
resolver.setBeanFactory(beanFactory);
try {
resolver.resolveDestination("foo");
fail("Expected exception");
} catch (DestinationResolutionException e) {
assertThat(e.getMessage(), Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory " + "(and there is no HeaderChannelRegistry present)."));
}
}
use of org.springframework.beans.factory.BeanFactory in project spring-integration by spring-projects.
the class HeaderChannelRegistryTests method testBFCRWithRegistry.
@Test
public void testBFCRWithRegistry() {
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.getBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME, HeaderChannelRegistry.class)).thenReturn(mock(HeaderChannelRegistry.class));
doAnswer(invocation -> {
throw new NoSuchBeanDefinitionException("bar");
}).when(beanFactory).getBean("foo", MessageChannel.class);
resolver.setBeanFactory(beanFactory);
try {
resolver.resolveDestination("foo");
fail("Expected exception");
} catch (DestinationResolutionException e) {
assertThat(e.getMessage(), Matchers.containsString("failed to look up MessageChannel with name 'foo' in the BeanFactory."));
}
}
Aggregations