Apache camel get result as string -


i have simple application use camel-weather service. can log result in console, want save result in variable, string, can show on jlabel or something.

my route is:

from("weather:foo?location=breda,netherlands&appid=appid")     .to("bean:outputbean?method=println")     .to("stream:out"); 

the outputbean nothing more simple return @ moment. want create json parser in function.

public class outputbean {     public string println(string msg){         return msg;     }    } 

how can save result route in variabele, can use data on later moment?

edit: code looks now:

camelcontext.addroutes(new routebuilder() {                  @override     public void configure() throws exception {         from("weather:foo?location="+ txtcity.gettext() + "&mode=xml&units=metric&appid=appid")         .setheader("temperature", xpathbuilder.xpath("//temperature/@value", string.class))         .to("bean:outputbean?method=println")         .to("stream:out");     } }); [here]  public class outputbean {     public string println(@header("temperature")string temperature){         return "output: " + temperature;     } } 

how can use temperature variabele on [here] place?

i this.

  1. save whatever want message header.
from("weather:foo?location=breda,netherlands&appid=appid") .setheader("myheader", "myheadervalue");     .to("bean:outputbean?method=println") .to("stream:out"); 

you can value either input body or somewhere else.

  1. in bean receive header , save , whatever want.
public class outputbean {     public string println(@header("myheader")string header){         string value = header;         return value;     } 

Comments