title: How to get HTTP status code for REST service in Mule
body: <p>I have following Mule flow :-</p>
  
  <pre><code>&lt;jms:activemq-connector name="Active_MQ" brokerURL="tcp://localhost:61616" validateConnections="true" doc:name="Active MQ"/&gt;
  
      &lt;mule-ss:security-manager&gt;
          &lt;mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager" /&gt;
      &lt;/mule-ss:security-manager&gt;
      &lt;spring:beans&gt;
          &lt;ss:authentication-manager alias="authenticationManager"&gt;
              &lt;ss:authentication-provider&gt;
                  &lt;ss:user-service id="userService"&gt;
                      &lt;ss:user name="username" password="password" authorities="ROLE_ADMIN" /&gt;
                  &lt;/ss:user-service&gt;
              &lt;/ss:authentication-provider&gt;
          &lt;/ss:authentication-manager&gt;
      &lt;/spring:beans&gt;
  
  &lt;flow name="testFlow1" doc:name="testFlow1"&gt;
  &lt;http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8083" doc:name="HTTP"&gt;
    &lt;mule-ss:http-security-filter realm="realm" /&gt;
  &lt;/http:inbound-endpoint&gt;
  
   &lt;jersey:resources doc:name="REST"&gt;
      &lt;component class="MyRest" /&gt;
    &lt;/jersey:resources&gt;
  
   &lt;logger message="Done !!!!!" level="INFO" doc:name="Logger"/&gt;
  
       &lt;!-- http://username:password@localhost:8083/myrest   or   http://localhost:8083/myrest and in this case we need to provide username and password from browser--&gt;
  
   &lt;catch-exception-strategy&gt;
      &lt;choice &gt;
       &lt;when expression="#[exception.getCauseException().getClass().getName()=='org.springframework.security.authentication.BadCredentialsException']"&gt;
       &lt;logger level="INFO" message="Authentication failed exception: #[exception.getCauseException().getClass().getName()]"/&gt;
       &lt;set-property propertyName="http.status" value="401"/&gt;
       &lt;http:response-builder status="401" doc:name="Status code = 401" doc:description="Authentication failed"/&gt;
        &lt;/when&gt;
          &lt;when expression="#[exception.getCauseException().getClass().getName()=='org.springframework.security.access.AccessDeniedException']"&gt;
        &lt;logger level="INFO" message="Access denied exception: #[exception.getCauseException().getClass().getName()]"/&gt;
        &lt;set-property propertyName="http.status" value="405"/&gt;
       &lt;http:response-builder status="405" doc:name="Status code = 405" doc:description="Authorization exception - Access denied"/&gt;
       &lt;/when&gt;
        &lt;otherwise&gt;
        &lt;logger message="An exception has been caught: #[exception.getCauseException().getClass().getName()]" level="ERROR" doc:name="Exception Thrown"/&gt;
       &lt;set-payload value="Error detected while processing" doc:name="Prepare response for client"/&gt;
       &lt;set-property propertyName="http.status" value="500"/&gt;
       &lt;http:response-builder status="500" doc:name="Status code = 500" doc:description="Exception - Sending a 500 Http Status code as Response"/&gt;
       &lt;/otherwise&gt;
        &lt;/choice&gt;
    &lt;/catch-exception-strategy&gt;
  
      &lt;/flow&gt;
  </code></pre>
  
  <p>I have taken the following as reference :- <a href="https://github.com/daveEason/mule-example-spring-security/blob/master/src/main/app/mule-config.xml" rel="nofollow">https://github.com/daveEason/mule-example-spring-security/blob/master/src/main/app/mule-config.xml</a></p>
  
  <p>Now the issue whenever I hit the url :-  <code>http://localhost:8083/myrest</code>   ... I get the following exception :-</p>
  
  <pre><code>ERROR 2014-10-20 23:06:52,223 [[test].connector.http.mule.default.receiver.03] org.mule.exception.CatchMessagingExceptionStrategy: 
  ********************************************************************************
  Message               : Registered authentication is set to org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter but there was no security context on the session. Authentication denied on endpoint http://localhost:8083. Message payload is of type: String
  Code                  : MULE_ERROR--2
  --------------------------------------------------------------------------------
  Exception stack is:
  1. Registered authentication is set to org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter but there was no security context on the session. Authentication denied on endpoint http://localhost:8083. Message payload is of type: String (org.mule.api.security.UnauthorisedException)
    org.mule.transport.http.filters.HttpBasicAuthenticationFilter:156 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/UnauthorisedException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  org.mule.api.security.UnauthorisedException: Registered authentication is set to org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter but there was no security context on the session. Authentication denied on endpoint http://localhost:8083. Message payload is of type: String
      at org.mule.transport.http.filters.HttpBasicAuthenticationFilter.authenticateInbound(HttpBasicAuthenticationFilter.java:156)
      at org.mule.security.AbstractEndpointSecurityFilter.authenticate(AbstractEndpointSecurityFilter.java:54)
      at org.mule.security.AbstractAuthenticationFilter.doFilter(AbstractAuthenticationFilter.java:52)
      + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  
  ERROR 2014-10-20 23:06:52,225 [[test].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: An exception has been caught: org.mule.api.security.UnauthorisedException
  ERROR 2014-10-20 23:06:52,520 [[test].connector.http.mule.default.receiver.03] org.mule.exception.CatchMessagingExceptionStrategy: 
  ********************************************************************************
  Message               : Registered authentication is set to org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter but there was no security context on the session. Authentication denied on endpoint http://localhost:8083. Message payload is of type: String
  Code                  : MULE_ERROR--2
  --------------------------------------------------------------------------------
  Exception stack is:
  1. Registered authentication is set to org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter but there was no security context on the session. Authentication denied on endpoint http://localhost:8083. Message payload is of type: String (org.mule.api.security.UnauthorisedException)
    org.mule.transport.http.filters.HttpBasicAuthenticationFilter:156 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/UnauthorisedException.html)
  --------------------------------------------------------------------------------
  Root Exception stack trace:
  org.mule.api.security.UnauthorisedException: Registered authentication is set to org.mule.module.spring.security.filters.http.HttpBasicAuthenticationFilter but there was no security context on the session. Authentication denied on endpoint http://localhost:8083. Message payload is of type: String
      at org.mule.transport.http.filters.HttpBasicAuthenticationFilter.authenticateInbound(HttpBasicAuthenticationFilter.java:156)
      at org.mule.security.AbstractEndpointSecurityFilter.authenticate(AbstractEndpointSecurityFilter.java:54)
      at org.mule.security.AbstractAuthenticationFilter.doFilter(AbstractAuthenticationFilter.java:52)
      + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************
  
  ERROR 2014-10-20 23:06:52,522 [[test].connector.http.mule.default.receiver.03] org.mule.api.processor.LoggerMessageProcessor: An exception has been caught: org.mule.api.security.UnauthorisedException
  </code></pre>
  
  <p>I wonder why it's generating such exception .. </p>
  
  <p>But if I remove the <strong>exception block</strong> from the code and hit  <code>http://localhost:8083/myrest</code> it works fine and ask the <strong>username</strong> and <strong>password</strong> as expected and generate expected result ..</p>
  
  <p>But I wonder why it is generating exception when I am using <strong>exception block</strong> in the code ..
  Actually my intention of using  <strong>exception block</strong> is to get and control different http status in different situation</p>