How to check why #BeanInject in Camel does not initialize member? - nullpointerexception

I have the following context configuration:
<bean id="propertiesFactory" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:conf.properties</value>
</list>
</property>
</bean>
<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="properties" ref="propertiesFactory"/>
</bean>
<bean id="messageThrottlerHolder" class="foo.bar.common.MessageThrottlerHolder"/>
<bean id="cassandraRoute" class="foo.bar.routes.CassandraRouteBuilder"/>
Then in both classes: MessageThrottlerHolder and in CassandraRouteBuilder there is:
#BeanInject
Properties properties;
Wonderful.
But CassandraRouteBuilder may/could use properties without NPE, as properties are well initialized.
On the other hand the MessageThrottlerHolder is not able to use properties as in the constructor properties are null and there is no way to initialize them.
How can I check why properties are null?
What can be wrong, that #BeanInject somehow does not initialize properties?

You are doing this wrong if you think that Properties are somehow Camel property placeholder or anything like that.
Camel's #BeanInject is for looking up bean in the Camel register via a bean name/id, as a poor-mans Spring IoC. If you are using Spring then you can use the Spring #Autowired or whatever they have for that.
If you want to access properties from the properties placeholder, then you can inject CamelContext and use its API for resolving: http://static.javadoc.io/org.apache.camel/camel-core/2.20.0/org/apache/camel/CamelContext.html#resolvePropertyPlaceholders-java.lang.String-
Or use Camel's #PropertyInject instead where you specify the key name to lookup. I am not sure if Spring has any similar annotation for looking up properties, as you have turned on the camel-spring bridge. You can also try to look into that.

Related

Is it possible to put camel properties in a hazelcast cache?

I would like to know if it is possible to push property in the cache hazelcast.
I work with a distributed environment and would like properties to be shared across all environments. Is it possible?
My current configuration for loading properties is as follows:
<bean id="propertiesConfigurer" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
<property name="systemPropertiesMode" value="2"/>
<property name="properties" ref="allProperties" />
</bean>
Thank you
You can simply use the distributed data structures of Hazelcast (i.e. IMap) and put any data you want as long as you make them serializable.
Yes, you can create a distributed map with entries as <String, Properties>. Each entry will keep a set of properties. Or, you can create a simple distributed map with entries as <String, String> and use this map as a set of properties.

how to use action=remove in property mediator using wso2 esb

I know how to set property using property mediator but don't know how to use remove property using property mediator. Can anyone give me an example?
See https://docs.wso2.com/display/ESB490/Generic+Properties
Sample : <property name="TRANSPORT_HEADERS" action="remove" scope="axis2"/>

Is there a way to use inheritance with ActiveMQ broker Spring bean definition via amq:broker

I'm declaring a Broker via the amq:broker namespace, but I'm wondering if similar to a regular spring bean with abstract="true", is it possible to create an abstract Broker "parent" bean and have children which inherit it's properties and complete it?
<amq:broker id="parentBroker" brokerName="parentBroker" useJmx="true" persistent="true" advisorySupport="true" abstract="true">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:61636" />
</amq:transportConnectors>
</amq:broker>
<amq:broker id="childBroker" parent="parentBroker">
<amq:persistenceAdapter>
<amq:kahaDB directory="/somewhere/kahadb" journalMaxFileLength="32mb" />
</amq:persistenceAdapter>
</amq:broker>
I guess not, you'd just have to use regular Spring 's then?

pass few properties to a custom action

What is a standart way of passing properties to a custom action without parsing them? I mean if I write "X1=X1value X2=X2value", then in my custom action X1 will be equal to "X1value X2=X2value", and X2 won't exist as a separate property. So what is the properties string format?
I don't know that there is a "standard" for serializing and serializng CustomActionData. There are a couple libraries out there though. If you happen to be using C# DTF custom actions there is a CustomActionData class that can serialize and deserialize the property collection for you. Otherwise you pretty much come up with your own pattern like:
/PROPERTYA=VALUEA /PROPERTYB=VALUEB
or
PROPERTYA=VALUEA;PROPERTYB=VALUEB
Or even an XML fragment like
<Properties>
<Property Id="PROPERTYA">VALUEA</Property>
<Property Id="PROPERTYB">VALUEB</Property>
</Properties>
The point is to serialize and deserialize so that it can be available to your deferred CA.

Seting up NHibernate Validator with Spring.net

How can I setup NHibernate Validator with Spring.net as IoC?
I am already using Spring.net integration with NHibernate and can't get AutoRegisterListeners to work.
What I need is to setup NHV to validate entities automatically upon Update/Save instead of having to call Validate method every time and use Spring.net with ISharedEngineProvider to make sure optimal performance.
After looking around a lot I found this one: http://forum.springframework.net/showthread.php?t=5286
I'm repeating it here for others to find it easier that I did!:
<object id="sessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate20">
<!-- the usual properties ... -->
<!-- event listeners -->
<property name="EventListeners">
<dictionary>
<entry key="PreUpdate">
<object type="NHibernate.Validator.Event.ValidatePreUpdateEventListener, NHibernate.Validator" />
</entry>
<entry key="PreInsert">
<object type="NHibernate.Validator.Event.ValidatePreInsertEventListener, NHibernate.Validator" />
</entry>
</dictionary>
</property> </object>