Camel K Rest route needs JSON marshalling and commented code executed

391 views Asked by At

A - Case 1: Rest DSL Example fails

I'm trying to apply the example written in the Apache Camel Rest DSL component. The simplified version of the same example for Camel K can be seen as below;

import org.apache.camel.builder.RouteBuilder;

public class RestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        // rest endpoints
        rest("/status")
            .get("/hello").to("direct:hello");
        
        // routes
        from("direct:hello")
            .transform().constant("Hello World");
        
    }

}

And then, the build fails as below;

levent.divilioglu:camel-k-ex $ kamel run RestRoute.java --dev
integration "rest-route" created
Progress: integration "rest-route" in phase Initialization
Condition "IntegrationPlatformAvailable" is "True" for Integration rest-route: default/camel-k
Progress: integration "rest-route" in phase Building Kit
Integration rest-route in phase "Initialization"
Condition "IntegrationPlatformAvailable" is "True" for Integration rest-route: default/camel-k
Integration rest-route in phase "Building Kit"
Condition "IntegrationKitAvailable" is "False" for Integration rest-route: creating a new integration kit
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Integration Kit) changed phase to "Build Submitted"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Integration Kit) changed phase to "Build Running"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed"
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 1 of 5)
Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 1 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 2 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 3 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Scheduling" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Pending" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Running" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Failed" (recovery 4 of 5)
(combined from similar events): Integration rest-route subresource kit-c2o28iiqfl2hcn198ng0 (Build) changed phase to "Initialization" (recovery 5 of 5)
Progress: integration "rest-route" in phase Error
Error: integration "rest-route" deployment failed

After I the log stops, I see it hangs on as can be seen below;

levent.divilioglu:camel-k-ex $ kamel get
NAME        PHASE   KIT
rest-route  Error   default/kit-c2o28iiqfl2hcn198ng0

B - Case 2: Rest DSL Example works if Json Marshalling added

Then I delete by applying kamel delete rest-route, and then add just one lone, marshal().json to the end of the direct route, start it with kamel run RestRoute.java --dev and it works;

import org.apache.camel.builder.RouteBuilder;

public class RestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        // rest endpoints
        rest("/status")
            .get("/hello").to("direct:hello");
        
        // routes
        from("direct:hello")
            .transform().constant("Hello World")
            .marshal().json();
        
    }

}

C - Case 3: Route works with commented Json Marshalling

The most interesting and weird behaviour is this case. I comment out the marshal().json() line, and it continues to work. However even if I remove this commented line, it won't work. So the working example as follows;

import org.apache.camel.builder.RouteBuilder;

public class RestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        // rest endpoints
        rest("/status")
            .get("/hello").to("direct:hello");
        
        // routes
        from("direct:hello")
            .transform().constant("Hello World");
            //.marshal().json()
        
    }

}

D - Versions

MiniKube version;

minikube version: v1.17.1
commit: 043bdca07e54ab6e4fc0457e3064048f34133d7e

Apache Camel K version;

Apache Camel K Runtime 1.7.0

Camel K client version;

Camel K Client 1.4.0

E - Findings and Questions

Where did I do wrong? I've just used the given example from the official apache website. Interesting things are;

  • The example doesn't work itself, but any rest route, needs a JSON marshalling, even if the content is a simple text.
  • The commented line seem to be executed in the integration file;
//.marshal().json()

Is this a bug, or is there a problem in the official Apache Camel Rest DSL example?

0

There are 0 answers