Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在运行时切换绑定(驼峰Rest Dsl)_Java_Apache Camel - Fatal编程技术网

Java 如何在运行时切换绑定(驼峰Rest Dsl)

Java 如何在运行时切换绑定(驼峰Rest Dsl),java,apache-camel,Java,Apache Camel,我有一个绑定模式设置为off的rest端点: rest("/users") .bindingMode(RestBindingMode.off) .get() .route() .id("Get all users") .bean(userService,"getAll") .endRest() 我想在捕获异常时将绑定模式切换为json: onException(UserNotFoundException.class) .hand

我有一个绑定模式设置为off的rest端点:

rest("/users")
   .bindingMode(RestBindingMode.off)
      .get()
      .route()
      .id("Get all users")
        .bean(userService,"getAll")
.endRest()
我想在捕获异常时将绑定模式切换为json:

 onException(UserNotFoundException.class)
   .handled(true)
   .process(responseProcessor);

用骆驼怎么做?我尝试将头绑定设置为json,但这不起作用。还有其他想法吗?

你不能那样做。在OneException中的处理器中,您可以自己将响应负载设置为JSon。如果需要,您可以使用Camel的dataformat/组件来支持JSon。

您不能这样做。在OneException中的处理器中,您可以自己将响应负载设置为JSon。如果需要,您可以使用Camel的dataformat/components来支持JSon。

您可以尝试使用以下命令在process方法中更改绑定模式:

@Override
    public void process(Exchange exchange) throws Exception {
exchange.getContext().getRestConfiguration().setBindingMode(RestConfiguration.RestBindingMode.json);
}

您可以在process方法中尝试使用以下命令更改绑定模式:

@Override
    public void process(Exchange exchange) throws Exception {
exchange.getContext().getRestConfiguration().setBindingMode(RestConfiguration.RestBindingMode.json);
}

恐怕这也会改变其他端点的绑定模式。我想将其应用于单个端点,这将改变调用处理器的路由上下文的绑定模式,因此仅适用于该执行。由于您在初始路由中有.bindingMode(RestBindingMode.off),因此对于下一个请求,它将再次设置为off。感谢您的建议和说明。这就是我所需要的(绑定一次执行)。稍后将对其进行测试并提供反馈。我担心这也可能会改变其他端点的绑定模式。我想将其应用于单个端点,这将改变调用处理器的路由上下文的绑定模式,因此仅适用于该执行。由于您在初始路由中有.bindingMode(RestBindingMode.off),因此对于下一个请求,它将再次设置为off。感谢您的建议和说明。这就是我所需要的(绑定一次执行)。稍后将对其进行测试并向您提供反馈。