change http responses and body responses from apache camel

1 answer

i have 2 routes:

<route id="test1">             <from uri="direct:start" />             <setProperty propertyName="id">                 <simple>${header._id}</simple>             </setProperty>             <setBody>                 <simple>${in.headers._id}</simple>             </setBody>                               <convertBodyTo type="java.lang.String" />             <log logName="test" message="id : ${body}" />             <to uri="file://inbox"/>         </route>  <route id="tesst" streamCache="true">         <from uri="file://inbox" />         <convertBodyTo type="java.lang.String" />         <log logName="test"             message="from inbox: ${body}" />         <setProperty propertyName="test">             <simple>${body}</simple>         </setProperty>         <to             uri="sql: SELECT blabla FROM blabla WHERE test = :#${property.test}" />         <setProperty propertyName="result">             <simple>${body}</simple>         </setProperty>         <choice>             <when>                 <simple>${property.result} != ""</simple>                 <log logName="test"                     message="call procedure.." />                 <to uri="sql: CALL public.sp_test(:#${property.test})" />              </when>             <otherwise>                 <log logName="test" message="Data not found!" />                 <setHeader headerName="Exchange.HTTP_RESPONSE_CODE">                     <constant>404</constant>                 </setHeader>                 <camel:setBody>                     <simple resultType="java.lang.String">Data not found!</simple>                 </camel:setBody>             </otherwise>         </choice>     </route> 

when i insert the wrong data, the http response i get still 200. i want to make http response 404 after some validation in choice-when-otherwise check. i already tried setheader, setheaderout, but none of them works. how can i do that?

All answers to this question, which has the identifier 61225001

The best answer:

As mentioned by @bedla in the comments, a File consumer (in-only messaging) cannot send a response. So it is hard to understand your case.

However, if you implement an HTTP server (consumer; in-out messaging) with Camel, you can set the HTTP status code of the response as message header

.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(404)) 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type com.google.firebase.iid.zzav is referenced as an interface from com.google.firebase.messaging.zzd”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data