Camel Rest DSL Response Codes Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Camel Rest DSL Response Codes without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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?

Answer

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()
We are here to answer your question about Camel Rest DSL Response Codes - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji