Class GatewayProxyFactoryBean<T>

Type Parameters:
T - the target gateway interface to build a proxy against.
All Implemented Interfaces:
Advice, Interceptor, MethodInterceptor, Aware, BeanClassLoaderAware, BeanFactoryAware, BeanNameAware, DisposableBean, FactoryBean<T>, InitializingBean, ApplicationContextAware, Lifecycle, Phased, SmartLifecycle, ExpressionCapable, NamedComponent, IntegrationManagement, ManageableLifecycle, ManageableSmartLifecycle, TrackableComponent
Direct Known Subclasses:
AnnotationGatewayProxyFactoryBean

public class GatewayProxyFactoryBean<T> extends AbstractEndpoint implements TrackableComponent, FactoryBean<T>, MethodInterceptor, BeanClassLoaderAware, IntegrationManagement
Generates a proxy for the provided service interface to enable interaction with messaging components without application code being aware of them allowing for POJO-style interaction. This component is also aware of the ConversionService set on the enclosing BeanFactory under the name IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME to perform type conversions when necessary (thanks to Jon Schneider's contribution and suggestion in INT-1230).
Author:
Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, JingPeng Xie
  • Constructor Details

    • GatewayProxyFactoryBean

      public GatewayProxyFactoryBean()
      Create a Factory whose service interface type can be configured by setter injection. If none is set, it will fall back to the default service interface type, RequestReplyExchanger, upon initialization.
    • GatewayProxyFactoryBean

      public GatewayProxyFactoryBean(Class<T> serviceInterface)
  • Method Details

    • setDefaultRequestChannel

      public void setDefaultRequestChannel(MessageChannel defaultRequestChannel)
      Set the default request channel.
      Parameters:
      defaultRequestChannel - the channel to which request messages will be sent if no request channel has been configured with an annotation.
    • setDefaultRequestChannelName

      public void setDefaultRequestChannelName(String defaultRequestChannelName)
      Set the default request channel bean name.
      Parameters:
      defaultRequestChannelName - the channel name to which request messages will be sent if no request channel has been configured with an annotation.
      Since:
      4.2.9
    • getDefaultRequestChannel

      @Nullable protected MessageChannel getDefaultRequestChannel()
    • getDefaultRequestChannelName

      @Nullable protected String getDefaultRequestChannelName()
    • setDefaultReplyChannel

      public void setDefaultReplyChannel(MessageChannel defaultReplyChannel)
      Set the default reply channel. If no default reply channel is provided, and no reply channel is configured with annotations, an anonymous, temporary channel will be used for handling replies.
      Parameters:
      defaultReplyChannel - the channel from which reply messages will be received if no reply channel has been configured with an annotation
    • setDefaultReplyChannelName

      public void setDefaultReplyChannelName(String defaultReplyChannelName)
      Set the default reply channel bean name. If no default reply channel is provided, and no reply channel is configured with annotations, an anonymous, temporary channel will be used for handling replies.
      Parameters:
      defaultReplyChannelName - the channel name from which reply messages will be received if no reply channel has been configured with an annotation
      Since:
      4.2.9
    • getDefaultReplyChannel

      @Nullable protected MessageChannel getDefaultReplyChannel()
    • getDefaultReplyChannelName

      @Nullable protected String getDefaultReplyChannelName()
    • setErrorChannel

      public void setErrorChannel(MessageChannel errorChannel)
      Set the error channel. If no error channel is provided, this gateway will propagate Exceptions to the caller. To completely suppress Exceptions, provide a reference to the "nullChannel" here.
      Parameters:
      errorChannel - The error channel.
    • setErrorChannelName

      public void setErrorChannelName(String errorChannelName)
      Set the error channel name. If no error channel is provided, this gateway will propagate Exceptions to the caller. To completely suppress Exceptions, provide a reference to the "nullChannel" here.
      Parameters:
      errorChannelName - The error channel bean name.
      Since:
      4.2.9
    • getErrorChannel

      @Nullable protected MessageChannel getErrorChannel()
    • getErrorChannelName

      @Nullable protected String getErrorChannelName()
    • setDefaultRequestTimeout

      public void setDefaultRequestTimeout(Long defaultRequestTimeout)
      Set the default timeout value for sending request messages. If not explicitly configured with an annotation, or on a method element, this value will be used.
      Parameters:
      defaultRequestTimeout - the timeout value in milliseconds
    • setDefaultRequestTimeoutExpression

      public void setDefaultRequestTimeoutExpression(Expression defaultRequestTimeout)
      Set an expression to be evaluated to determine the default timeout value for sending request messages. If not explicitly configured with an annotation, or on a method element, this value will be used.
      Parameters:
      defaultRequestTimeout - the timeout value in milliseconds
      Since:
      5.0
    • setDefaultRequestTimeoutExpressionString

      public void setDefaultRequestTimeoutExpressionString(String defaultRequestTimeout)
      Set an expression to be evaluated to determine the default timeout value for sending request messages. If not explicitly configured with an annotation, or on a method element, this value will be used.
      Parameters:
      defaultRequestTimeout - the timeout value in milliseconds
      Since:
      5.0
    • getDefaultRequestTimeout

      @Nullable protected Expression getDefaultRequestTimeout()
    • setDefaultReplyTimeout

      public void setDefaultReplyTimeout(Long defaultReplyTimeout)
      Set the default timeout value for receiving reply messages. If not explicitly configured with an annotation, or on a method element, this value will be used.
      Parameters:
      defaultReplyTimeout - the timeout value in milliseconds
    • setDefaultReplyTimeoutExpression

      public void setDefaultReplyTimeoutExpression(Expression defaultReplyTimeout)
      Set an expression to be evaluated to determine the default timeout value for receiving reply messages. If not explicitly configured with an annotation, or on a method element, this value will be used.
      Parameters:
      defaultReplyTimeout - the timeout value in milliseconds
      Since:
      5.0
    • setDefaultReplyTimeoutExpressionString

      public void setDefaultReplyTimeoutExpressionString(String defaultReplyTimeout)
      Set an expression to be evaluated to determine the default timeout value for receiving reply messages. If not explicitly configured with an annotation, or on a method element, this value will be used.
      Parameters:
      defaultReplyTimeout - the timeout value in milliseconds
      Since:
      5.0
    • getDefaultReplyTimeout

      @Nullable protected Expression getDefaultReplyTimeout()
    • setShouldTrack

      public void setShouldTrack(boolean shouldTrack)
      Specified by:
      setShouldTrack in interface TrackableComponent
    • setAsyncExecutor

      public void setAsyncExecutor(@Nullable Executor executor)
      Set the executor for use when the gateway method returns Future or ListenableFuture. Set it to null to disable the async processing, and any Future return types must be returned by the downstream flow.
      Parameters:
      executor - The executor.
    • setTypeConverter

      public void setTypeConverter(TypeConverter typeConverter)
    • setMethodMetadataMap

      public void setMethodMetadataMap(Map<String,GatewayMethodMetadata> methodMetadataMap)
    • setGlobalMethodMetadata

      public void setGlobalMethodMetadata(GatewayMethodMetadata globalMethodMetadata)
    • getGlobalMethodMetadata

      @Nullable protected GatewayMethodMetadata getGlobalMethodMetadata()
    • setBeanClassLoader

      public void setBeanClassLoader(ClassLoader beanClassLoader)
      Specified by:
      setBeanClassLoader in interface BeanClassLoaderAware
    • setMapper

      public final void setMapper(MethodArgsMessageMapper mapper)
      Provide a custom MethodArgsMessageMapper to map from a MethodArgsHolder to a Message.
      Parameters:
      mapper - the mapper.
    • getMapper

      @Nullable protected MethodArgsMessageMapper getMapper()
    • setProxyDefaultMethods

      public void setProxyDefaultMethods(boolean proxyDefaultMethods)
      Indicate if default methods on the interface should be proxied as well. If an explicit Gateway annotation is present on method it is proxied independently of this option. Note: default methods in JDK classes (such as Function) can be proxied, but cannot be invoked via MethodHandle by an internal Java security restriction for MethodHandle.Lookup.
      Parameters:
      proxyDefaultMethods - the boolean flag to proxy default methods or invoke via MethodHandle.
      Since:
      5.3
    • getAsyncExecutor

      @Nullable protected AsyncTaskExecutor getAsyncExecutor()
    • isAsyncExecutorExplicitlySet

      protected boolean isAsyncExecutorExplicitlySet()
    • getGateways

      public Map<Method,MessagingGatewaySupport> getGateways()
      Return the Map of Method to MessagingGatewaySupport generated by this factory bean.
      Returns:
      the map.
      Since:
      4.3
    • registerMetricsCaptor

      public void registerMetricsCaptor(MetricsCaptor metricsCaptorToRegister)
      Description copied from interface: IntegrationManagement
      Inject a MetricsCaptor. Ignored if ObservationRegistry is provided.
      Specified by:
      registerMetricsCaptor in interface IntegrationManagement
      Parameters:
      metricsCaptorToRegister - the captor.
      See Also:
    • onInit

      protected void onInit()
      Description copied from class: IntegrationObjectSupport
      Subclasses may implement this for initialization logic.
      Overrides:
      onInit in class AbstractEndpoint
    • getObjectType

      public Class<?> getObjectType()
      Specified by:
      getObjectType in interface FactoryBean<T>
    • getObject

      public T getObject()
      Specified by:
      getObject in interface FactoryBean<T>
    • invoke

      @Nullable public Object invoke(MethodInvocation invocation) throws Throwable
      Specified by:
      invoke in interface MethodInterceptor
      Throws:
      Throwable
    • doInvoke

      @Nullable protected Object doInvoke(MethodInvocation invocation, boolean runningOnCallerThread) throws Throwable
      Throws:
      Throwable
    • doStart

      protected void doStart()
      Description copied from class: AbstractEndpoint
      Subclasses must implement this method with the start behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.
      Specified by:
      doStart in class AbstractEndpoint
    • doStop

      protected void doStop()
      Description copied from class: AbstractEndpoint
      Subclasses must implement this method with the stop behavior. This method will be invoked while holding the AbstractEndpoint.lifecycleLock.
      Specified by:
      doStop in class AbstractEndpoint
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean
      Specified by:
      destroy in interface IntegrationManagement
      Overrides:
      destroy in class AbstractEndpoint