You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sonusgr <mv...@gmail.com> on 2013/03/12 13:02:33 UTC

Can't read properties from Processor

Hi, I am fairly new to Camel.
I am writing some test cases, trying to integrate Camel with Spring.

My testCase is 

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@PropertySource("classpath:test.properties")
public class DistributionTargetProcessorTest extends CamelSpringTestSupport
{

    protected CamelContext camelContext;

    protected ProducerTemplate template;

   @Autowired fields.....

 @Configuration
    static class SomeTestConfiguration {
     @Bean
        public AutowiredField someRepositoy() {
            return Mockito.mock(SomeRepository.class);

         etc....
        }

 @Before
    public void startServices() throws Exception {
        
    	deleteDirectory("activemq-data");
        camelContext = new DefaultCamelContext();
        camelContext.addRoutes(new MockRoute());
        template = camelContext.createProducerTemplate();
        camelContext.start();
    }

@Test
    public void testClientInvocation() throws Exception {
   	    	
    	String out = "";
    	try {

        template.sendBodyAndHeaders("direct:testDistProcessor",
generateConfirmationContainer(), getConfirmationHeaders());
        
    	}
    	catch (Exception npe) {
    	}
    }

@Override
	protected AbstractApplicationContext createApplicationContext() {
		return new ClassPathXmlApplicationContext("spring/conf-ctx.xml");
		}

public class MockRoute extends RouteBuilder {
	
    public void configure() {
        from("direct:testDistProcessor")
                .process(new TargetProcessor())               
                .end();
    }   
}

public class DistributionTargetProcessor implements Processor{


    @Value("${some.property}")
    private String someProperty;

    @Override
    public void process(Exchange exchange) throws Exception {



in my context

<context:property-placeholder
location="file:///${home}/cfg/test.properties"/>


The properties in my Processor come as null. Also any autowire fields come
as null. 
I am guessing the spring application context is not configured properly but
could some point out what's wrong?




--
View this message in context: http://camel.465427.n5.nabble.com/Can-t-read-properties-from-Processor-tp5728996.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Can't read properties from Processor

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Mar 13, 2013 at 12:07 AM, sonusgr <mv...@gmail.com> wrote:
> any ideas?
>

If you use any of the Spring annotation stuff, eg @Value
Then you must let Spring handle the lifecycle / IoC / of this class /
processor. So you cannot do new MyXXXProcessor in the code. But have
to refer to a spring bean id instead. For example using the camel bean
component. Then Camel will lookup the bean in Spring, and Spring will
does its IoC stuff et all.



>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Can-t-read-properties-from-Processor-tp5728996p5729051.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: Can't read properties from Processor

Posted by sonusgr <mv...@gmail.com>.
any ideas?



--
View this message in context: http://camel.465427.n5.nabble.com/Can-t-read-properties-from-Processor-tp5728996p5729051.html
Sent from the Camel - Users mailing list archive at Nabble.com.