FAQ
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.

Search Discussions

  • John Smith at Apr 13, 2012 at 12:18 pm
    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.
  • Babak Vahdat at Apr 13, 2012 at 12:36 pm
    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.
  • John Smith at Apr 13, 2012 at 12:47 pm
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedApr 13, '12 at 12:15p
activeApr 13, '12 at 12:47p
posts4
users2
websitecamel.apache.org

2 users in discussion

John Smith: 3 posts Babak Vahdat: 1 post

People

Translate

site design / logo © 2022 Grokbase