Reputation: 2225
I have created a camel route with the following exception handling:
onException(BadRequestException.class)
.handled(true)
.process(exchange -> {
System.out.println("Reached processor");
System.out.println(exchange.getIn().getBody(String.class));
})
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(HttpStatus.BAD_REQUEST));
I make a request to http://localhost:8080/services/rest/endpoint?key=value
In a bean, I have some validation that says that two query parameters are required, key
and keyTwo
. keyTwo
isn't present, so I throw a BadRequestException
:
public void assertRequiredParametersPresentOnExchange() throws BadRequestException {
try {
requiredParameters.stream()
.forEach(p -> assertNotNull(p));
} catch (IllegalArgumentException e) {
throw new BadRequestException(e.getMessage());
}
}
When I execute the URL, I can see Reached processor
output from the exception handler above, but then nothing happens. Postman waits for a reply for ~60 seconds and then gives me status code 23.
What am I missing here? MEP? Setting some property on the exchange?
Upvotes: 4
Views: 2704
Reputation: 436
It seems like you are getting the enums ordinal which is 23. Could you try to replace the the enum
org.apache.http.HttpStatus.SC_BAD_REQUEST
instead of
org.springframework.http.HttpStatus.BAD_REQUEST
and see if it makes any difference
Upvotes: 6