Hi,
I did a little more testing and found that there seems to be a conflict in the
headers.
When I add this to the XML it works:
<removeHeaders pattern="*”/>
I printed the headers, maybe that gives a clue.
“
{Accept=application/json, Accept-Encoding=gzip, deflate, Accept-Language=nl-nl,
breadcrumbId=51099-1476544028839-0-2, CamelHttpCharacterEncoding=UTF-8,
CamelHttpMethod=POST, CamelHttpPath=, CamelHttpQuery=null,
CamelHttpServletRequest=Request(POST /custom_webapi/hello/world)@13b615ae,
CamelHttpServletResponse=HTTP/1.1 200
, CamelHttpUri=/custom_webapi/hello/world,
CamelHttpUrl=http://remco.local:8080/custom_webapi/hello/world,
CamelServletContextPath=/custom_webapi/hello/world, Connection=keep-alive,
Content-Length=3, Content-Type=application/json, Host=remco.local:8080,
Origin=http://petstore.swagger.io,
Referer=http://petstore.swagger.io/?url=http://remco.local:8080/custom_webapi/api-docs/helloWorld,
User-Agent=Mozilla/5.0}
"
That would explain why in some cases it works, the request was already routed
to another webserver, so the headers were already changed before the exception.
--
Met vriendelijke groet,
Remco Schoen
Op 14 okt. 2016, om 16:36 heeft Remco Schoen
<[email protected]<mailto:[email protected]>> het volgende geschreven:
Hi,
I’m trying to use the REST DSL and do validation on the incoming object with
the Bean Validation Component.
I have configured my Spring XML like this:
<onException>
<exception>org.apache.camel.component.bean.validator.BeanValidationException</exception>
<handled>
<constant>true</constant>
</handled>
<setHeader headerName="Exchange.HTTP_RESPONSE_CODE">
<constant>422</constant>
</setHeader>
<setBody>
<simple>Validation error.\n\Message:\n${exception.message}</simple>
</setBody>
</onException>
But when I use the Swagger UI to send a message to my endpoint, I get no body
or HTTP response code. For other exceptions this approach works.
Should this work with this exception?
I’m using version 2.17.3
Kind regards,
Remco Schoen