Is Spring Boot Camel onException handling Broken after 4.7.x release? - Stack Overflow

We are using camel as ESB and noticed something breaking after 4.7.x release.The "onException&quo

We are using camel as ESB and noticed something breaking after 4.7.x release.

The "onException" registered in routes are not working. Control won't flow into this block but works fine in versions prior to 4.7.x. Was there any breaking api change introduced in this version?

I have attached the very small boot gradle project to replicate the scenario. In build.gradle just switch the camel version and you can see the difference.

If you use version prior version to 4.7, everything works as excepted. The below code will print "exception caught!!" and returns a 200 OK response. But if you upgrade to 4.7.x or later, the control won't reach in to the onException block and rest response returns a 500 response.

URL : http://localhost:8080/camel/demo

@Component
public class TestRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        onException(Throwable.class)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("exception caught!!");
                    }
                }).handled(true);
        rest("/")
            .consumes("application/ json;charset=UTF-8")
            .produces("application/ json;charset=UTF-8")
            .get("/demo")
            .to("direct:next-step");
        from("direct:next-step")
            .doTry()
                // invoking SOAP service
                .process(exchange -> {
                    throw new RuntimeException("Random Exception");
                })
            .doCatch(Throwable.class)
                .process(exchange -> {
                    throw new IllegalStateException("not in a valid state");
                });
    }
}

My build.gradle file below :

buildscript {
    ext {
        camelSpringVersion = '4.4.5' // this works as expected
        //camelSpringVersion = '4.10.2' // this is broken
    }
}
plugins {
    id 'java'
    id 'war'
    id '.springframework.boot' version '3.4.3'
    id 'io.spring.dependency-management' version '1.1.7'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation '.springframework.boot:spring-boot-starter-web'
    providedRuntime '.springframework.boot:spring-boot-starter-tomcat'
    testImplementation '.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly '.junit.platform:junit-platform-launcher'

    implementation ".apache.camel:camel-http:${camelSpringVersion}"
    implementation ".apache.camel.springboot:camel-spring-boot-starter:${camelSpringVersion}"
    implementation ".apache.camel.springboot:camel-servlet-starter:${camelSpringVersion}"
    implementation ".apache.camel.springboot:camel-jackson-starter:${camelSpringVersion}"
    implementation ".apache.camel:camel-health:${camelSpringVersion}"
}

tasks.named('test') {
    useJUnitPlatform()
}

We are using camel as ESB and noticed something breaking after 4.7.x release.

The "onException" registered in routes are not working. Control won't flow into this block but works fine in versions prior to 4.7.x. Was there any breaking api change introduced in this version?

I have attached the very small boot gradle project to replicate the scenario. In build.gradle just switch the camel version and you can see the difference.

If you use version prior version to 4.7, everything works as excepted. The below code will print "exception caught!!" and returns a 200 OK response. But if you upgrade to 4.7.x or later, the control won't reach in to the onException block and rest response returns a 500 response.

URL : http://localhost:8080/camel/demo

@Component
public class TestRoute extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        onException(Throwable.class)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("exception caught!!");
                    }
                }).handled(true);
        rest("/")
            .consumes("application/ json;charset=UTF-8")
            .produces("application/ json;charset=UTF-8")
            .get("/demo")
            .to("direct:next-step");
        from("direct:next-step")
            .doTry()
                // invoking SOAP service
                .process(exchange -> {
                    throw new RuntimeException("Random Exception");
                })
            .doCatch(Throwable.class)
                .process(exchange -> {
                    throw new IllegalStateException("not in a valid state");
                });
    }
}

My build.gradle file below :

buildscript {
    ext {
        camelSpringVersion = '4.4.5' // this works as expected
        //camelSpringVersion = '4.10.2' // this is broken
    }
}
plugins {
    id 'java'
    id 'war'
    id '.springframework.boot' version '3.4.3'
    id 'io.spring.dependency-management' version '1.1.7'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(17)
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation '.springframework.boot:spring-boot-starter-web'
    providedRuntime '.springframework.boot:spring-boot-starter-tomcat'
    testImplementation '.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly '.junit.platform:junit-platform-launcher'

    implementation ".apache.camel:camel-http:${camelSpringVersion}"
    implementation ".apache.camel.springboot:camel-spring-boot-starter:${camelSpringVersion}"
    implementation ".apache.camel.springboot:camel-servlet-starter:${camelSpringVersion}"
    implementation ".apache.camel.springboot:camel-jackson-starter:${camelSpringVersion}"
    implementation ".apache.camel:camel-health:${camelSpringVersion}"
}

tasks.named('test') {
    useJUnitPlatform()
}
Share Improve this question edited Mar 12 at 4:16 Valath asked Mar 12 at 4:10 ValathValath 9204 gold badges13 silver badges38 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Solution 1 ::

In order to preserve existing behaviour, you need to set this property

camel.rest.inline-routes = false 

in all versions post 4.7.x.

Solution 2 ::

If you add a dummy route, its working as expected. For example if you modify above code as below, its working as expected.

@Component
public class TestRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {

        onException(Throwable.class)
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        System.out.println("exception caught!!");
                    }
                }).handled(true);

        rest("/")
            .consumes("application/ json;charset=UTF-8")
            .produces("application/ json;charset=UTF-8")
            .get("/demo")
            .to("direct:next-step-dummy");

   from("direct:next-step-dummy") // setting a dummy route
            .to("direct:next-step");

        from("direct:next-step")
            .doTry()
                // invoking SOAP service
                .process(exchange -> {
                    throw new RuntimeException("Random Exception");
                })
            .doCatch(Throwable.class)
                .process(exchange -> {
                    throw new IllegalStateException("not in a valid state");
                });
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744770452a4592726.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信