Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camel rest-dsl sending 400 Status codes

I am developing REST services using camel REST-DSL [in camel documentation] component.I am successful in sending JSON request for happy path and get the response on the same using (Rest-DSL and camel servlet) combination. Now as we move forward the client may sent Rest Service request with not enough values or invalid valid request ,now I am looking for ways to send 400 status code as a response from REST DSL when request is not valid.

Please advise on the way to achieve this.

like image 370
Leo Prince Avatar asked Dec 06 '22 23:12

Leo Prince


1 Answers

I am assuming you are doing your validation in a custom processor or something similiar. If you want to send your an HTTP Error code just add the header Exchange.HTTP_RESPONSE_CODE.

For example : exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 400);

The behaviour may depend of the engine you use. As documentation says it should work with servlet engine :

  • https://cwiki.apache.org/confluence/display/CAMEL/SERVLET#SERVLET-MessageHeaders
  • https://cwiki.apache.org/confluence/display/CAMEL/HTTP#HTTP-MessageHeaders
like image 128
Pierre-Alban DEWITTE Avatar answered Jan 21 '23 21:01

Pierre-Alban DEWITTE