How to return a custom HTTP 401/500 reply message?

Solution Verified - Updated -

Issue

  • Camel Routes not handling unauthorized http response code (401) properly
  • How to return a custom HTTP 401/500 reply message
 <route id="true" id="xxx-4443">
        <from uri="jetty-clientAuth:https://0.0.0.0:11111/xxx?matchOnUriPrefix=true"/>
        <to uri="reqProcessor" id="to2"/>
        <to uri="authProcessor" id="to3"/>
        <to uri="http://xxx-yyy-zzzz:000/xxx?throwExceptionOnFailure=false&bridgeEndpoint=true" id="to4"/>
 </route>
  • In above route's authProcessor we are doing some cert validation and based on the validation response if validation fails we are setting up header value Exchange.HTTP_RESPONSE_CODE to "401" and in exchange body message to Unauthorized.

  • But when request flows to next part of the route which is <to uri="http://xxx-yyy-zzzz:000/xxx?throwExceptionOnFailure=false&bridgeEndpoint=true" id="to4"/>, in the client side response header we see http-status code: 500 instead of 401.

  • So my question is, could you please let us know how can we set the unauthorized code to 401 in such a way that client could receive correct http status code the header.

Environment

  • Red Hat JBoss Fuse
    • 6.2.1

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In