Get white label page with status 404 using Apache Camel Servlet component

56 views Asked by At
I am using Camel to provide a web service to other systems. I wrote a simple Camel consuming route to accept the http requests. I can successfully start the Camel application using Springboot. But When I access it through web browser. I always got HTTP 404 error

I am using the Camel 4.2.0. Here is my POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.4</version>
    </parent>
    <groupId>com.camel.rest</groupId>
    <artifactId>testapp</artifactId>
    <version>1.0-SNAPSHOT</version>


    <properties>
        <camel.version>4.2.0</camel.version>
        <java.version>17</java.version>
    </properties>


    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>3.1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson</artifactId>
            <version>${camel.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-servlet-starter</artifactId>
            <version>3.21.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

My application.properties:

camel.component.servlet.mapping.context-path=/*

server.port=9090

I have a very simple route:

@Component
public class respRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        restConfiguration().component("servlet").port(9090).host("localhost").bindingMode(RestBindingMode.json);

        rest().get("/hello").produces(MediaType.APPLICATION_JSON_VALUE).to("direct:hello");
        from("direct:hello").transform().constant("Welcome buddy");
    }
}

The application is started properly. I see the message: Started route1 (rest://get:/hello)

But when I call http://localhost:9090/hello, I always got status 404

This issue has been bothering me for a couple of days. Any help will be appreciated.

1

There are 1 answers

0
hunter Lewis On

try using

http://localhost:9090/camel/hello

instead of

http://localhost:9090/hello

I came across the similar issue, adding "camel" in the path works for me.