![](/img/trans.png)
[英]“java.net.BindException: Can't assign requested address” on client's side
[英]Apache Camel BindException: “Can't Assign Requested Address”
我正在学习如何使用骆驼。 我的以下代码段有问题:
@SpringBootApplication
public class FeefooExampleApplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(FeefooExampleApplication.class, args);
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new CamelConfig());
camelContext.start();
Blah blah = new Blah();
blah.getFeefoData();
}
}
我的CamelConfig类如下:
package com.example.camel;
import com.example.feefo.FeedbackProcessor;
import org.apache.camel.builder.RouteBuilder;
public class CamelConfig extends RouteBuilder {
private FeedbackProcessor feedbackProcessor = new FeedbackProcessor();
@Override
public void configure() throws Exception {
from("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
.convertBodyTo(String.class)
.bean(feedbackProcessor, "processFeedback") ;
}
}
报告的错误如下:'线程“ main”中的异常java.net.BindException:无法分配请求的地址”
有人可以帮忙吗?
谢谢
当用作使用者时, jetty
组件会创建一个HTTP服务器,侦听HTTP请求,并与该请求进行交换。
换句话说,当您执行from("jetty:http://cdn2.feefo.com/..")
,您要求Jetty创建一个具有与“ cdn2.feefo.com”关联的网络接口的HTTP服务器:这会失败(好吧,我假设您的计算机不是此主机)
如果要请求此HTTP地址,则必须使用jetty(或http4组件)作为生产者。 例如:
from("direct:check_xmlfeedback")
.to("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
...
并致电给您的路线:
context.getProducerTemplate().requestBody("direct:check_xmlfeedback", null);
如果要定期轮询此HTTP地址,则可以使用timer
组件:
from("timer:check?period=5m")
.to("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.