You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by pberkman <pe...@cornergrove.com> on 2012/11/07 16:29:25 UTC

Bridge Property Loading Order

I have the following in my main Camel context:

	<bean id="bridgePropertyPlaceholder"
class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
		<property name="location" value="file:nextgate/ms/ngmsroute.properties"/>
	</bean>

and, a bit later in the file I try and use the properties to control an
<import...> as follows:

	<import resource="${nextgate.ms.hl7v3.pdq.endpointfile}" />
	<import resource="${nextgate.ms.hl7v3.pix.endpointfile}" />
	<import resource="${nextgate.ms.hl7v3.xcpd.endpointfile}" />

I'm doing this to allow for various configurations - secure, non-secure, and
SAML bassed endpoints.

I'm getting an exception from Spring that the referenced placeholder has NOT
been defined.

It seems that the Spring loader goes through and tries to complete all of
the IMPORTs BEFORE loading the propert bridge bean.  Is this correct, or am
I missing something else?

if so, another question is:  is there a way to have the Bridge Property bean
prioritized BEFORE the imports get executed?

thank you!



--
View this message in context: http://camel.465427.n5.nabble.com/Bridge-Property-Loading-Order-tp5722306.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Bridge Property Loading Order

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Thanks for sharing this. Nice to see improvements in 3.1 and 3.2 of
Spring in regard to property placeholders and environment settings and
whatnot. And hopefully someday they open up so this is accessible for
3rd party namespace handlers. So we can have seamless Spring property
placeholder integration.

People can vote on this. But don't write something about Camel, it's a
competitor project to their own Spring projects.
http://jira.springframework.org/browse/SPR-4466

On Thu, Nov 8, 2012 at 11:35 PM, pberkman <pe...@cornergrove.com> wrote:
> I found a reasonable solution:
>
> 1) upgrade to Spring 3.1.3.RELEASE
>
> 2) Implement a Context Initializer Class:
>     a) create a wrapper for your properties file (mine is just a static
> singleton for a PropertiesFile).
>     b) create SpringContextInitializer:
>
> public class SpringContextInitializer implements
> ApplicationContextInitializer<ConfigurableWebApplicationContext> {
>
>         private static final transient Logger LOG =
> LoggerFactory.getLogger(SpringContextInitializer.class);
>
>     public void initialize(ConfigurableWebApplicationContext ctx) {
>
>         LOG.trace("SpringContextInitializer: initialize");
>
>         ctx.getEnvironment().getPropertySources().addFirst(new
> SpringContextInitializerPropertySource("NGMSPropertiesRoute"));
>     }
> }
>
>     c) Implement a SpringContextInitializerPropertySource:
>
> public class SpringContextInitializerPropertySource extends
> PropertySource<NGMSPropertiesRoute> {
>
>         private static final transient Logger LOG =
> LoggerFactory.getLogger(SpringContextInitializerPropertySource.class);
>
>         public SpringContextInitializerPropertySource(String name) {
>                 super(name);
>         }
>
>         @Override
>         public Object getProperty(String name) {
>
>                 String val =
> PropertiesFactory.getPropertiesFactory().getRouteProperties().getProperty(name,
> null);
>
>                 LOG.trace("Spring asked for property: {}, returning: {}", name, val);
>
>                 return val;
>         }
> }
>
> 3) Configure the web.xml file to use your context initializer:
>
>     <context-param>
>         <param-name>contextInitializerClasses</param-name>
>         <param-value>com.mycompany.SpringContextInitializer</param-value>
>     </context-param>
>
>
> and, now I can use property placeholder ANYWHERE - including the <import
> resource="${myvariable.name}" />
>
> The writeup on this from Spring is at:
> http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/
>
> Thanks!
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Bridge-Property-Loading-Order-tp5722306p5722378.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
FuseSource is now part of Red Hat
Email: cibsen@redhat.com
Web: http://fusesource.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Bridge Property Loading Order

Posted by pberkman <pe...@cornergrove.com>.
I found a reasonable solution:

1) upgrade to Spring 3.1.3.RELEASE

2) Implement a Context Initializer Class:
    a) create a wrapper for your properties file (mine is just a static
singleton for a PropertiesFile).
    b) create SpringContextInitializer:

public class SpringContextInitializer implements
ApplicationContextInitializer<ConfigurableWebApplicationContext> {

	private static final transient Logger LOG =
LoggerFactory.getLogger(SpringContextInitializer.class);

    public void initialize(ConfigurableWebApplicationContext ctx) { 

    	LOG.trace("SpringContextInitializer: initialize");
    	
        ctx.getEnvironment().getPropertySources().addFirst(new
SpringContextInitializerPropertySource("NGMSPropertiesRoute")); 
    } 
}

    c) Implement a SpringContextInitializerPropertySource:

public class SpringContextInitializerPropertySource extends
PropertySource<NGMSPropertiesRoute> {

	private static final transient Logger LOG =
LoggerFactory.getLogger(SpringContextInitializerPropertySource.class);

	public SpringContextInitializerPropertySource(String name) {
		super(name);
	}

	@Override
	public Object getProperty(String name) {

		String val =
PropertiesFactory.getPropertiesFactory().getRouteProperties().getProperty(name,
null);
		
		LOG.trace("Spring asked for property: {}, returning: {}", name, val);
		
		return val;
	} 
}

3) Configure the web.xml file to use your context initializer:

    <context-param>
    	<param-name>contextInitializerClasses</param-name>
    	<param-value>com.mycompany.SpringContextInitializer</param-value>
    </context-param>


and, now I can use property placeholder ANYWHERE - including the <import
resource="${myvariable.name}" />

The writeup on this from Spring is at:
http://blog.springsource.org/2011/02/15/spring-3-1-m1-unified-property-management/

Thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/Bridge-Property-Loading-Order-tp5722306p5722378.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Bridge Property Loading Order

Posted by pberkman <pe...@cornergrove.com>.
for both test and production.   the container is Glassfish 3.1.2 (not OSGI
yet).  I'm trying, with zero success so far, the solutions around writing a
Sring Context Bootstrap...  anything simpler would be good...  I'm surprised
that Spring didn't think of this earlier... seems like a good use???

thanks!



--
View this message in context: http://camel.465427.n5.nabble.com/Bridge-Property-Loading-Order-tp5722306p5722323.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Bridge Property Loading Order

Posted by Christian Müller <ch...@gmail.com>.
The PropertyPlaceholderConfigurer is not made for this kind of substitution.

Did you need this stuff only for your test or also for your regular
deployment?
Which environment do you use (Standalone, Karaf, Tomcat, ...)?

Best,
Christian

On Wed, Nov 7, 2012 at 4:29 PM, pberkman <pe...@cornergrove.com>wrote:

> I have the following in my main Camel context:
>
>         <bean id="bridgePropertyPlaceholder"
> class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
>                 <property name="location"
> value="file:nextgate/ms/ngmsroute.properties"/>
>         </bean>
>
> and, a bit later in the file I try and use the properties to control an
> <import...> as follows:
>
>         <import resource="${nextgate.ms.hl7v3.pdq.endpointfile}" />
>         <import resource="${nextgate.ms.hl7v3.pix.endpointfile}" />
>         <import resource="${nextgate.ms.hl7v3.xcpd.endpointfile}" />
>
> I'm doing this to allow for various configurations - secure, non-secure,
> and
> SAML bassed endpoints.
>
> I'm getting an exception from Spring that the referenced placeholder has
> NOT
> been defined.
>
> It seems that the Spring loader goes through and tries to complete all of
> the IMPORTs BEFORE loading the propert bridge bean.  Is this correct, or am
> I missing something else?
>
> if so, another question is:  is there a way to have the Bridge Property
> bean
> prioritized BEFORE the imports get executed?
>
> thank you!
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Bridge-Property-Loading-Order-tp5722306.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



--