使用Camel和Restlet设置HTTP代码OneException

使用Camel和Restlet设置HTTP代码OneException,exception,apache-camel,restlet,http-status-codes,Exception,Apache Camel,Restlet,Http Status Codes,在Apache Camel项目中使用,我无法在中的响应上设置HTTP状态代码 考虑如下配置的CamelRouteBuilder: onException(Exception.class) .handled(true) .process(new FailureResponseProcessor()); from("restlet:http://example.com/foo") .process(fooProcessor) .to("file:data/outbox"); 在F

在Apache Camel项目中使用,我无法在中的响应上设置HTTP状态代码

考虑如下配置的Camel
RouteBuilder

onException(Exception.class)
  .handled(true)
  .process(new FailureResponseProcessor());

from("restlet:http://example.com/foo")
  .process(fooProcessor)
  .to("file:data/outbox");
FailureResponseProcessor
中,我尝试为Restlet设置HTTP响应代码:

public void process(Exchange exchange) throws Exception {
  Response response = exchange.getIn()
                              .getHeader(RestletConstants.RESTLET_RESPONSE,
                                         Response.class);
    response.setStatus(Status.SERVER_ERROR_INTERNAL);
}
这是行不通的。HTTP响应的状态始终为
200OK


有效设置HTTP状态代码需要什么?

这里您只需检索响应对象并对其进行更改。这不会沿着路线传播。修改对象后需要设置标题

exchange.getIn().setHeader(RestletConstants.RESTLET_RESPONSE, response);

谢谢。

您可以通过设置

.onException(MyException.class).process(SetFailureResponse::new).handled(true)
在单独的SetFailureResponse类集合中

@Override
    public void process(Exchange exchange) throws Exception {
        exchange.getMessage().setHeader(Exchange.HTTP_RESPONSE_CODE,400);
    }

这帮我找到了正确的方向。实际的问题是,在处理器上游,头文件没有传播。