Reputation: 61
I am in the process of learning how to use Camel. I am having an issue with the following snippet of code:
@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();
}
}
My CamelConfig Class is the following:
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") ;
}
}
The error that is reported is the following: 'Exception in thread "main" java.net.BindException: Can't assign requested address'
Would anybody be able to help ?
Thank You
Upvotes: 0
Views: 1761
Reputation: 11022
When used as a consumer, the jetty
component create an HTTP server, listening to a HTTP request, and creating an exchange with this request.
In other words, when you do from("jetty:http://cdn2.feefo.com/..")
, you are asking jetty to create an HTTP server with the network interface associated to "cdn2.feefo.com": This fails (well, I have assumed your machine is not this host)
If you want to request this HTTP address, you have to use jetty (or the http4 component) as a producer. For example:
from("direct:check_xmlfeedback")
.to("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
...
and call your route with :
context.getProducerTemplate().requestBody("direct:check_xmlfeedback", null);
If you want to periodically poll this HTTP address, you can use the timer
component:
from("timer:check?period=5m")
.to("jetty:http://cdn2.feefo.com/api/xmlfeedback?merchantidentifier=example-retail-merchant")
...
Upvotes: 5