}
if (requestHandlers != null) {
MessageChannel requestChannel = new MessageChannelImpl(requestHandlers);
MessageChannel responseChannel = new MessageChannelImpl(responseHandlers);
Interceptor channelInterceptor = new RequestResponseInterceptor(requestChannel, targetRequestChannel,
responseChannel, targetResponseChannel);
if (interceptorChainHead != null) {
interceptorChainTail.setNext(channelInterceptor);
} else {
interceptorChainHead = channelInterceptor;
}
} else {
// no request handlers
if (interceptorChainHead != null) {
if (targetInterceptorChainHead != null) {
// Connect source interceptor chain directly to target interceptor chain
interceptorChainTail.setNext(targetInterceptorChainHead);
// interceptorChainTail = targetInterceptorChainHead;
} else {
// Connect source interceptor chain to the target request channel
Interceptor channelInterceptor = new RequestResponseInterceptor(null, targetRequestChannel, null,
targetResponseChannel);
interceptorChainTail.setNext(channelInterceptor);
}
} else {
// no source interceptor chain or source handlers, conntect to target interceptor chain or channel
if (targetInterceptorChainHead != null) {
interceptorChainHead = targetInterceptorChainHead;
interceptorChainTail = targetInterceptorChainHead;
} else {
Interceptor channelInterceptor = new RequestResponseInterceptor(null, targetRequestChannel, null,
targetResponseChannel);
interceptorChainHead = channelInterceptor;
interceptorChainTail = channelInterceptor;
}
}