org.springframework.integration.endpoint
Class DefaultEndpoint<T extends MessageHandler>

java.lang.Object
  extended by org.springframework.integration.endpoint.AbstractEndpoint
      extended by org.springframework.integration.endpoint.AbstractRequestReplyEndpoint
          extended by org.springframework.integration.endpoint.DefaultEndpoint<T>
All Implemented Interfaces:
org.springframework.beans.factory.BeanNameAware, ChannelRegistryAware, MessageEndpoint, MessageTarget

public class DefaultEndpoint<T extends MessageHandler>
extends AbstractRequestReplyEndpoint
implements ChannelRegistryAware

The default Message Endpoint implementation. Serves as a "host" for any MessageHandler and resolves the target for any reply Message(s) returned by that handler. If the handler returns a non-empty CompositeMessage, each Message in its list will be sent as a separate reply Message.

The reply target is resolved according to the following order:

  1. the 'nextTarget' header value of the reply Message
  2. the 'outputChannel' of this Message Endpoint
  3. the 'returnAddress' header value of the request Message
For the 'nextTarget' and 'returnAddress' values, either a MessageTarget instance or String is accepted. If the value is a String, then the endpoint will consult its ChannelRegistry (typically provided by the MessageBus). If no reply target can be determined for a non-null reply Message, a MessageEndpointReplyException will be thrown.

Author:
Mark Fisher

Field Summary
private  ChannelRegistry channelRegistry
           
private  T handler
           
private  java.util.List<EndpointInterceptor> interceptors
           
private  MessageSelector selector
           
 
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
logger
 
Constructor Summary
DefaultEndpoint(T handler)
          Create an endpoint for the given handler.
 
Method Summary
 void addInterceptor(EndpointInterceptor interceptor)
           
private  Message<?> doHandleRequestMessage(Message<?> requestMessage, int index)
           
protected  ChannelRegistry getChannelRegistry()
           
protected  T getHandler()
           
 Message<?> handleRequestMessage(Message<?> requestMessage)
           
protected  boolean isValidReplyMessage(Message<?> replyMessage)
          The reply Message is considered invalid if it is null, has a null payload, or has an empty Array or Collection as its payload.
private  MessageTarget resolveReplyTarget(Message<?> replyMessage, MessageHeaders requestHeaders)
           
private  MessageTarget resolveTargetAttribute(java.lang.Object targetAttribute)
           
protected  void sendReplyMessage(Message<?> replyMessage, Message<?> requestMessage)
           
 void setChannelRegistry(ChannelRegistry channelRegistry)
           
 void setInterceptors(java.util.List<EndpointInterceptor> interceptors)
           
 void setOutputChannel(MessageChannel outputChannel)
          Specify the channel where reply Messages should be sent if no 'nextTarget' header value is available on the reply Message.
 void setReplyTimeout(long replyTimeout)
          Specify the timeout for sending reply Messages to the reply target.
 void setReturnAddressOverrides(boolean returnAddressOverrides)
           
 void setSelector(MessageSelector selector)
           
protected  boolean supports(Message<?> message)
           
 
Methods inherited from class org.springframework.integration.endpoint.AbstractRequestReplyEndpoint
getInputChannelName, getOutputChannelName, sendInternal, setInputChannelName, setOutputChannelName, setRequiresReply, setSource, setTarget
 
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
getMessageExchangeTemplate, getName, getSchedule, getSource, getTarget, send, setBeanName, setErrorHandler, setSchedule, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

handler

private final T extends MessageHandler handler

channelRegistry

private volatile ChannelRegistry channelRegistry

selector

private volatile MessageSelector selector

interceptors

private final java.util.List<EndpointInterceptor> interceptors
Constructor Detail

DefaultEndpoint

public DefaultEndpoint(T handler)
Create an endpoint for the given handler.

Method Detail

getHandler

protected T getHandler()

setSelector

public void setSelector(MessageSelector selector)

addInterceptor

public void addInterceptor(EndpointInterceptor interceptor)

setInterceptors

public void setInterceptors(java.util.List<EndpointInterceptor> interceptors)

setChannelRegistry

public void setChannelRegistry(ChannelRegistry channelRegistry)
Specified by:
setChannelRegistry in interface ChannelRegistryAware

getChannelRegistry

protected ChannelRegistry getChannelRegistry()

setReplyTimeout

public void setReplyTimeout(long replyTimeout)
Specify the timeout for sending reply Messages to the reply target. The default value indicates an indefinite timeout.


handleRequestMessage

public final Message<?> handleRequestMessage(Message<?> requestMessage)
Specified by:
handleRequestMessage in class AbstractRequestReplyEndpoint

isValidReplyMessage

protected boolean isValidReplyMessage(Message<?> replyMessage)
The reply Message is considered invalid if it is null, has a null payload, or has an empty Array or Collection as its payload.

Specified by:
isValidReplyMessage in class AbstractRequestReplyEndpoint

sendReplyMessage

protected void sendReplyMessage(Message<?> replyMessage,
                                Message<?> requestMessage)
Specified by:
sendReplyMessage in class AbstractRequestReplyEndpoint

doHandleRequestMessage

private Message<?> doHandleRequestMessage(Message<?> requestMessage,
                                          int index)

supports

protected boolean supports(Message<?> message)

resolveReplyTarget

private MessageTarget resolveReplyTarget(Message<?> replyMessage,
                                         MessageHeaders requestHeaders)

resolveTargetAttribute

private MessageTarget resolveTargetAttribute(java.lang.Object targetAttribute)

setReturnAddressOverrides

public void setReturnAddressOverrides(boolean returnAddressOverrides)

setOutputChannel

public void setOutputChannel(MessageChannel outputChannel)
Specify the channel where reply Messages should be sent if no 'nextTarget' header value is available on the reply Message.