Apache Camel将地址剩余与重定向地址连接起来

时间:2019-02-20 14:26:10

标签: spring-boot apache-camel

我正在使用Apache Camel进行系统集成,并且遇到了一个奇怪的url链接问题,仅在以下情况下出现:

  • 我公开了提供参数的REST服务
  • 我不使用Processor进行数据转换,而是使用bean

我将Apache Camel和Spring Boot和 netty4-http 组件一起使用来进行重定向。下面是创建异常的简化示例:

@Component
public class TestRoute extends RouteBuilder {
     public void configure() throws Exception {
     getContext().getGlobalOptions().put("CamelJacksonEnableTypeConverter", "true");

                restConfiguration()
                    .host("localhost")
                    .port("8096")
                    .bindingMode(RestBindingMode.auto);

                 rest()
                    .get("/method/{param1}")    
                    // Same problem if i use from() instead route()
                    .route()    
                        .to("direct:some-operation")
                        .to("netty4-http://localhost:8080/another/service"); 
        }
    }


    @Component
    public class TestBean {

        @Consume(uri = "direct:some-operation")
        public String getStartProcess() {
            /* bean's operation */
            return "Hello";
        }

    }

例如,如果我呼叫http://localhost:8096/method/dog,则得到的结果是该呼叫被重定向到http://localhost:8080/another/service/method/dog,后者被重定向,其余的则被串联。

我的第一个尝试是删除 to() bean,认为这是造成问题的原因,但是结果没有改变。

所以我做了很多测试,我注意到如果执行以下操作之一,则不会出现异常:

  • 我将逻辑移至流程,而不是使用bean。在 这样,我在交换对象中创建了一个新的 message out , 重定向是正确的(至少这是我给自己的解释)

    .process(new Processor() {
    
        @Override
        public void process(Exchange exchange) throws Exception{
            /* same bean's operation */
            exchange.getOut().setBody("Hello");
    
        }
    }).to("netty4-http://localhost:8080/another/service");
    
  • 如果我公开了不带参数的REST调用,那么作为.get(“ /方法”),它也可以与Bean一起使用,并且不会进行串联

为什么我的行为异常? 使用bean是否有可能的解决方案?

谢谢

0 个答案:

没有答案