You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by John Smith <js...@googlemail.com> on 2012/04/13 14:15:05 UTC

Bean's property value is null when used in a route.

Hello,

I have a bean defined below which is used in the route shown. When the bean
is used I need it to know the server name defined in the beans's definition
in the spring context file however it always comes out as null.

In the server log I can see the setServer method being called and it being
set to "dev" but when its used in the route its null. what am I doing wrong?

thanks,
John.

<bean id="svrsend" class="xxx.CamelTestJMS.ServerSender"
		init-method="setup" destroy-method="teardown">
		<property name="server" value="dev"/>
</bean>

Which is used in this route:
   	
Processor processor = new MyProcessor();
from("jms:queue:GET").
process(processor ).
to("xslt://file:etc//xsl//CreateTicket.xsl").
bean(new xxx.CamelTestJMS.ServerSender()).to("file:target/messages/jms");

The ServerSender class:

public class ServerSender {

	private String server = null;
	
	private final Logger log = Logger.getLogger(RemedySender.class);
	
	public RemedySender() {
		System.out.println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$");
	}

	public void hello(@Body String msg) {
		log.fatal(msg.substring(1, 150));
		log.fatal("SERVER NAME: "+getServer());
	}
	
	public void setup() {
		log.error("@@Setup");
		System.out.println("@@Setup");
		System.out.println("Server: "+getServer());
	}
	
	public void teardown() {
		log.error("@@Teardown");
		System.out.println("@@Teardown");
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		System.out.println("*****************************:"+server);
		this.server = server;
	}
	
}

--
View this message in context: http://camel.465427.n5.nabble.com/Bean-s-property-value-is-null-when-used-in-a-route-tp5638139p5638139.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Bean's property value is null when used in a route.

Posted by John Smith <js...@googlemail.com>.
Sorry, there was some copy / paste typos in that code where it references
RemedyServer as the constructor and in the log4j logger definition - it
should read ServerSender.

--
View this message in context: http://camel.465427.n5.nabble.com/Bean-s-property-value-is-null-when-used-in-a-route-tp5638139p5638148.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Bean's property value is null when used in a route.

Posted by John Smith <js...@googlemail.com>.
Perfect, thanks Babak - still a bit new to camel :-)

--
View this message in context: http://camel.465427.n5.nabble.com/Bean-s-property-value-is-null-when-used-in-a-route-tp5638139p5638196.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Bean's property value is null when used in a route.

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

by your provided route you don't make use of the Spring's managed "svrsend"
Bean but instantiate another copy by yourself inside the route.

For example if you want to call the hello method on your Spring Bean you
could do something like:

   to("bean:svrsend?method=hello")

And as the Spring's managed Bean gets reused here by Camel then the Bean's
"server" property should have your expected "dev" value.

Babak


--
View this message in context: http://camel.465427.n5.nabble.com/Bean-s-property-value-is-null-when-used-in-a-route-tp5638139p5638171.html
Sent from the Camel - Users mailing list archive at Nabble.com.