我對駱駝很新。我一直在嘗試從http源獲取數據。 這裏是我的代碼:Apache駱駝簡單HTTP示例
from("timer://runOnce?repeatCount=1")
.to("http4://webservice.com/example.xml")
.process(new structureXML())
.to("mock:resource")
.stop();
和:
class structureXML implements Processor {
public void process(Exchange httpExchange) throws Exception {
String httpres = httpExchange.getIn().getBody(String.class);
String[] lines = httpres.split("\n");
Pattern p = Pattern.compile("<Map Key='(.+)' Value='(.+)'/>");
HashMap<String, Integer> mapdata = new HashMap<String, Integer>();
for(String line : lines) {
Matcher m = p.matcher(line);
if(m.find())
mapdata.put(m.group(1), Integer.parseInt(m.group(2)));
}
httpExchange.getIn().setBody(mapdata);
}
}
好例子作品的權利,但我想知道的可能途徑,以進一步改善這種情況(使用XPath和等如XML處理),我也想知道我可以在消息內部存儲Java對象的方式,以便我可以在另一條路徑中使用它(例如:direct:resource而不是模擬)
非常詳細和有用的答案,非常感謝 – lkn2993