Hi,
I have a setup with a client and server coupled by JMS and gateways. The client side is setup like this:
Client-side
The Server sideCode:<int:gateway id="queryClient" service-interface="QueryClient" default-request-channel="queryRequests" error-channel="queryError" default-reply-timeout="3000"> <int:method name="save"> <int:header name="operation" value="save"/> </int:method> <int:method name="get"> <int:header name="operation" value="findOne"/> </int:method> </int:gateway> <int:channel id="queryError"> <int:interceptors> <int:wire-tap channel="log" /> </int:interceptors> </int:channel> <int:channel id="queryError"/> <int:channel id="queryRequests"/> <int-jms:outbound-gateway request-channel="queryRequests" request-destination-name="searchservice.queryrequests" connection-factory="jmsFactory" time-to-live="20000" /> <int:transformer input-channel="queryError" ref="errorHandler" />
Code:<int-jms:inbound-gateway request-channel="incomingQueryRequests" request-destination-name="searchservice.queryrequests" connection-factory="jmsConnFac" error-channel="errorMapper" /> <int:channel id="incomingQueryRequests"/> <int:recipient-list-router input-channel="incomingQueryRequests"> <int:recipient channel="saveQueryRequest" selector-expression="'save'.equals(headers['operation'])"/> <int:recipient channel="findOneQueryRequest" selector-expression="'findOne'.equals(headers['operation'])"/> </int:recipient-list-router> <int:channel id="saveQueryRequest"/> <int:channel id="findOneQueryRequest"/> <int:channel id="errorMapper" /> <int:transformer input-channel="errorMapper" ref="errorHandler" /> <int:service-activator id="querySaveHandler" input-channel="saveQueryRequest" ref="queryRepository" method="save" requires-reply="true"/> <int:service-activator id="queryFindOneHandler" input-channel="findOneQueryRequest" ref="queryRepository" method="findOne"/>
My questions are:
Question1: null handling
If an exception occurs on the server side, eg. the finder doesn't find anything and returns null, what is best practice to send this to the client side, which clearly expects an object or null?
Question 2: Exception handling
If an exception is thrown somewhere in the chain on the server side - how do I propagate this exception to the client side?
As you can see, I've tried to use error-channels to propagate exceptions, by they are not doing what I expected. The errorHandler handling the error-channel on the server side basically builds an Exception like this:
My hope was that this exception would be propagated to the client side error-channel, where the client side errorHandler could take this exception and rethrow it as a gateway response.Code:Server side errorhandler: public SearchServiceException tranformToException(Message message) { return new SearchServiceException(message.getPayload().toString()); }
What happens is that the client side errorhandler receives a MessageTimeoutException and includes no clue what so ever about the original message from the server side errorhandler.Code:Client side error handler: public void doHandle(Object exception) { System.out.println("Exceptionhandler handles THIS: " + exception); throw new SearchServiceException(exception.toString()); }


Reply With Quote
