Submit Camel rest-dsl 400 Status Codes

I develop REST services using the REST-DSL camel [in the camel documentation] . I successfully sent a JSON request for a happy journey and get an answer to the same combination (Rest-DSL and camel servlet). Now that we are moving forward, the client can send a Restore service request with invalid values ​​or an invalid valid request, now I am looking for ways to send the 400 status code as a response from the REST DSL when the request is invalid.

Please provide information on how to do this.

+4
source share
2 answers

, - . HTTP, Exchange.HTTP_RESPONSE_CODE.

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

. , :

+6

Pierre-Alban, .

- . - -

OnException (ValidationException.class).handled()
              .setHeader(Exchange.HTTP_RESPONSE_CODE, (400))               .setHeader(Exchange.CONTENT_TYPE, ( "text/plain" )). setBody (exceptionMessage());

+4

All Articles