I'm having troubles getting any of the simplest springboot servlet rest api examples to work on my machine. I'm just trying to create the simplest possible test api to practice the framework. I have the following code in my Routes RouteBuilder class:
@Component
public class Routes extends RouteBuilder {
@Override
public void configure() {
restConfiguration()//Bind the api servlet to the localhost port 8080
.component("servlet").host("localhost").port(8080)
.bindingMode(RestBindingMode.auto);
rest("/api")//Log any get requests
.get()
.route().to("log:DEBUG?showBody=true&showHeaders=true");
}
}
However, when I try to invoke this code with curl, I get the following error:
curl -X GET http://localhost:8080/api
curl: (7) Failed to connect to localhost port 8080: Connection refused
I'm using camel 2.22.0 and SpringBoot 2.0.4.RELEASE. I'm running this on Ubuntu 20.04 LTS.
EDIT:
I did the changes suggested, but I still get the same Connection refused by curl. My code now looks like this:
restConfiguration()//Bind the api servlet to the localhost port 8080
.component("servlet").host("localhost").port(8080)//Use camel default context path
.bindingMode(RestBindingMode.auto);
rest("/api")//Log any get requests
.get()
.route().to("log:DEBUG?showBody=true&showHeaders=true");
curl -X GET http://localhost:8080/camel/api -> Connection refused
I also now have the following in my application.yml:
server:
port: 8080 #Specify port for camel servlet
max-http-header-size: 32768 # Maximum size in bytes of the HTTP message header.