mchinaloy
mchinaloy

Reputation: 1494

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.

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?

Upvotes: 0

Views: 4074

Answers (2)

mchinaloy
mchinaloy

Reputation: 1494

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()

Upvotes: 3

Souciance Eqdam Rashti
Souciance Eqdam Rashti

Reputation: 3193

See the header section here http://camel.apache.org/constant.html for setting headers.. You should be able to set the http response code and body directly.

Upvotes: 0

Related Questions