I have written a REST Provider service using Spring Integration,
- I am utilizing exception-type-router along with http-inbound-gateway to set return HTTP Status Code
(e.g) an EntityNotFound Exception is mapped to return 404, IllegalArgument is mapped to return 400 etc.
Everything is working fine except that, when the incoming message is processed by Service Activator, the MessagingGatewaySupport.doSendAndRecieve method which catches the exception while evaluating an expression logs the whole stack, this raises false alarms while scanning through the log files.
for a give configuration like this:
Although I will be handling the exception thrown using a exception-type-router, the Exception is logged in the following code:Code:<int:service-activator id="customerByEmailForHeadActivator" input-channel="incomingCustomerByEmailforHead" expression="@customerManagementGateway.isCustomerAvailableByEmailId(payload) == true ? '' : ''" output-channel="outgoing" requires-reply="true" />
MessagingGatewaySupport.java [lines : 222 - 242]
Is it really necessary to log this exception along with whole stack trace at warn level ?Code:try { if (shouldConvert) { reply = this.messagingTemplate.convertSendAndReceive(this.requestChannel, object, this.historyWritingPostProcessor); if (reply instanceof Throwable) { error = (Throwable) reply; } } else { Message<?> requestMessage = (object instanceof Message<?>) ? (Message<?>) object : this.requestMapper.toMessage(object); requestMessage = this.historyWritingPostProcessor.postProcessMessage(requestMessage); reply = this.messagingTemplate.sendAndReceive(this.requestChannel, requestMessage); if (reply instanceof ErrorMessage) { error = ((ErrorMessage) reply).getPayload(); } } } catch (Exception e) { logger.warn("failure occurred in gateway sendAndReceive", e); error = e; }
I understand that not all systems would handle exceptions the way I handled, but since there is an default exception channel already in place,I think it would be better to log the exception through an interceptor there than at the MessagingGatewaySupport.
please validate my understanding and opinion, so that I can think about raising a JIRA for this.


Reply With Quote
