简体   繁体   English

Camel Rest DSL响应码

[英]Camel Rest DSL Response Codes

I have a route builder that looks as follows: 我有一个路由生成器,如下所示:

.post("/myEndpoint")
    .type(MyObject.class)
    .to("bean:myListener?method=create")

I would like this to return a 201 Created HTTP Response Code, at present its returns a 200 OK. 我希望这返回201 Created HTTP Response Code,目前返回200 OK。

Is there a way to do this in the RouteBuilder without having to forward any results onto a separate service class and then manually set the code on the Exchange? 是否有办法在RouteBuilder中执行此操作,而不必将任何结果转发到单独的服务类上,然后在Exchange上手动设置代码?

We managed to get it to work by doing the following - 通过执行以下操作,我们设法使其起作用:

.post("/myEndpoint")
    .type(MyObject.class)
    .route()
    .setHeader(Exchange.HTTP_RESPONSE_CODE,simple(HTTP_CREATED))
    .to("bean:myListener?method=create")
.endRest()

有关设置标题的信息,请参见http://camel.apache.org/constant.html的标题部分。您应该能够直接设置http响应代码和正文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM