Phuc La
Phuc La

Reputation: 3

I could not run my program due to error caused by the camel context, what should I do to resolve this?

So what I'm trying to do here is to create a zoom meeting through camel apache. I keep getting the error whenever I run the program and the line causing the error is when I start the camel context c.start() Here is the code that I run:

    package com.example.demo;

    import com.google.gson.Gson;
    import com.google.gson.JsonObject;
    import org.apache.camel.*;
    import org.apache.camel.builder.RouteBuilder;
    import org.apache.camel.impl.DefaultCamelContext;
    import org.apache.camel.model.dataformat.JsonLibrary;

    import static org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.json;

public class Test {
    private String token = "sample token";
    public static void main(String[] args) throws Exception {
        CamelContext c = new DefaultCamelContext();
        settings set = new settings(true, true, false,
                false, true,"voip","cloud");
        recurrence rec = new recurrence(1,1);
        c.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:start")
                        .process(exchange -> exchange.getIn().setBody(new ZoomSetting(
                                "Testing zoom api",
                                2,
                                "2022-05-09T14: 00: 00",
                                45,
                                "America/New_York",
                                "testing",
                                rec,
                                set
                        )))
                        .marshal().json(JsonLibrary.Gson)
                        .setHeader(Exchange.HTTP_METHOD, constant("POST"))
                        .setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
                        .setHeader("Authorization", simple("Bearer"+ token))
                        .to("https://api.zoom.us/v2/users/me/meetings")
                        .process(exchange -> log.info("The response code is: {}", exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE)));
            }
        });
        c.start();

    }
}

I tried to include the dependency in the pom.xml file, but that didn't really help. Here is the dependencies that I included in the pom.xml:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.camel.springboot</groupId>
        <artifactId>camel-spring-boot-starter</artifactId>
        <version>3.16.0</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.camel/camel-http-starter -->
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http-starter</artifactId>
        <version>3.0.0-RC3</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.auth0</groupId>
        <artifactId>java-jwt</artifactId>
        <version>3.19.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-rest</artifactId>
        <version>3.16.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-gson</artifactId>
        <version>3.16.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-direct</artifactId>
        <version>3.16.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-http</artifactId>
        <version>3.16.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-core</artifactId>
        <version>3.16.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-context</artifactId>
        <version>2.25.4</version>
    </dependency>




</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

The error I keep getting is this:

Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.apache.camel.management.JmxManagementLifecycleStrategy does not define or inherit an implementation of the resolved method abstract onRouteContextCreate(Lorg/apache/camel/Route;)V of interface org.apache.camel.spi.LifecycleStrategy. at org.apache.camel.reifier.RouteReifier.doCreateRoute(RouteReifier.java:213) at org.apache.camel.reifier.RouteReifier.createRoute(RouteReifier.java:74) at org.apache.camel.impl.DefaultModelReifierFactory.createRoute(DefaultModelReifierFactory.java:49) at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:887) at org.apache.camel.impl.DefaultCamelContext.startRouteDefinitions(DefaultCamelContext.java:775) at org.apache.camel.impl.engine.AbstractCamelContext.doInit(AbstractCamelContext.java:2937) at org.apache.camel.support.service.BaseService.init(BaseService.java:83) at org.apache.camel.impl.engine.AbstractCamelContext.init(AbstractCamelContext.java:2620) at org.apache.camel.support.service.BaseService.start(BaseService.java:111) at org.apache.camel.impl.engine.AbstractCamelContext.start(AbstractCamelContext.java:2639) at org.apache.camel.impl.DefaultCamelContext.start(DefaultCamelContext.java:255) at com.example.demo.Test.main(Test.java:42)

Upvotes: 0

Views: 3312

Answers (1)

Pasi &#214;sterman
Pasi &#214;sterman

Reputation: 2197

If you want to run camel using main method you should use camel-main which is for running standalone camel applications. What you're trying to do there is running camel as standalone application but using camel-spring-boot dependencies.

You can use maven archetype camel-archetype-main to generate new standalone camel application project and use that as reference on how to setup your project.

mvn archetype:generate -DarchetypeGroupId="org.apache.camel.archetypes" -DarchetypeArtifactId="camel-archetype-main" -DarchetypeVersion="3.14.3"

If you want to use spring-framework and spring-boot to run camel then you can use camel-archetype-spring-boot archetype to generate example camel spring-boot project. I would recommend getting familiar with basics of Spring-framework and Spring-boot before bringing camel to the mix to avoid unnecessary confusion.

mvn archetype:generate -DarchetypeGroupId="org.apache.camel.archetypes" -DarchetypeArtifactId="camel-archetype-spring-boot" -DarchetypeVersion="3.14.3"

Upvotes: 1

Related Questions