Thanks Karen investigating further. i am confused though. working version is the one using "exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500));" whereas the latter using processor is not working..
On Mon, Aug 23, 2021 at 10:09 PM Karen Lease <karenlease...@gmail.com> wrote: > Hi Onder, > I found the explanation for this behavior. It's caused by > "constant(500)" in the expression: > exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)); > > The constant expression isn't evaluted to an integer when it is set; > instead it is stored as a ValueBuilder object in the exchange header. > The DefaultHttpBinding class tries to convert the ValueBuilder to an > integer and it doesn't find an appropriate TypeConverter to do this so > it doesn't set a response code. > > If you do: exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, 500); > it works as you expect. > > In the working version, the constant expression is evaluated by the > setHeader() operation and it stores an integer in the exchange header. > > This is indeed quite confusing! > > Regards, > Karen > > On 19/08/2021 16:04, Onder SEZGIN wrote: > > Even more strange, > > > > i can see 500 in the logs however, response in postman is 404 in this > > example. > > > > from("direct:uploadFiles") > > .process(new Processor() { > > @Override > > public void process(Exchange exchange) throws Exception { > > > > exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, > > constant(500)); > > } > > }) > > .log("Response code header: ${in.header.CamelHttpResponseCode}") > > .choice().when(simple("${in.header.CamelHttpResponseCode} == 500")) > > .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) > > .otherwise().setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) > > .end(); > > > > > > On Thu, Aug 19, 2021 at 2:51 PM Onder SEZGIN <ondersez...@gmail.com> > wrote: > > > >> Hi, > >> > >> i have a confusing issue while camel 3.7.5. > >> > >> when i have below. i can get 500.(Working fine titled example) > >> > >> However, if i have, HTTP response is not getting set to 500. > >> > >> Can anyone provide any light on this? > >> > >> Thanks. > >> > >> from("direct:uploadFiles") > >> .process(new Processor() { > >> @Override > >> public void process(Exchange exchange) throws Exception { > >> > exchange.getIn().setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)); > >> } > >> }); > >> > >> > >> Working fine: > >> ------ > >> > >> rest("/endpoint") > >> .consumes("application/json") > >> .produces("application/text") > >> .post("/upload") > >> .type(Void.class) > >> .to("direct:uploadFiles"); > >> > >> from("direct:uploadFiles") > >> > >> .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(500)) > >> > >> > > >