我是Apache Camel的新成員。我試着去這個文件複製到文件夾:https://www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xmlCamel從http
我得到的錯誤:
Exception in thread "main" java.lang.UnsupportedOperationException: Cannot consume from http endpoint
package route;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.BasicConfigurator;
public class CurrencyRoute {
public static void main(String args[]) throws Exception {
// Log 4j
BasicConfigurator.configure();
// Create camel context
CamelContext context = new DefaultCamelContext();
// New route
context.addRoutes(new RouteBuilder() {
public void configure() {
from("https://www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml")
.log("Read file")
.to("file:src/main/resources/data/inbox");
}
});
// start the route and let it do its work
context.start();
Thread.sleep(10000);
// stop the CamelContext
context.stop();
}
}
所以我知道我必須爲它定義一個路線,但我應該在哪裏把它定義(在什麼文件??),以及如何定義?
更新代碼2017年10月13日13:06
package route;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.log4j.BasicConfigurator;
public class CurrencyRoute {
public static void main(String args[]) throws Exception {
// Log 4j
BasicConfigurator.configure();
// Create camel context
CamelContext context = new DefaultCamelContext();
// Template
ProducerTemplate template = context.createProducerTemplate();
// New route
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").setHeader(Exchange.HTTP_METHOD, constant("GET"))
.to("https://www.dnb.no/portalfront/datafiles/miscellaneous/csv/kursliste_ws.xml")
.to("file:src/main/resources/data/inbox/?autoCreate=true");
}
});
// SendBody
template.sendBody("direct:start", null);
// start the route and let it do its work
context.start();
Thread.sleep(10000);
// stop the CamelContext
context.stop();
}
}
我沒有任何名爲「模板」的變量。你的意思是context.sendBody(「direct:start」,null); ? – Solo
您可以使用ProducerTemplate template = context.createProducerTemplate()創建一個簡單的ProducerTemplate; – Shailendra
我用模板更新了代碼(請參閱我的第一篇文章),然後我得到這個錯誤: 線程「main」org.apache.camel.CamelExecutionException中的異常:在Exchange上執行期間發生異常:Exchange [消息:[Body is null ]] – Solo