Class GatewayProxyFactoryBean<T>
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.gateway.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, Christian Tzolov
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLockFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTEFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionCreate a Factory whose service interface type can be configured by setter injection.GatewayProxyFactoryBean(Class<T> serviceInterface) -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()protected ObjectdoInvoke(MethodInvocation invocation, boolean runningOnCallerThread) protected voiddoStart()Subclasses must implement this method with the start behavior.protected voiddoStop()Subclasses must implement this method with the stop behavior.protected AsyncTaskExecutorprotected MessageChannelprotected Stringprotected Expressionprotected MessageChannelprotected Stringprotected Expressionprotected MessageChannelprotected StringReturn the Map ofMethodtoMessagingGatewaySupportgenerated by this factory bean.protected GatewayMethodMetadataprotected MethodArgsMessageMapperClass<?>invoke(MethodInvocation invocation) protected booleanprotected voidonInit()Subclasses may implement this for initialization logic.voidregisterMetricsCaptor(MetricsCaptor metricsCaptorToRegister) Inject aMetricsCaptor.voidsetAsyncExecutor(Executor executor) Set the executor for use when the gateway method returnsFutureorListenableFuture.voidsetBeanClassLoader(ClassLoader beanClassLoader) voidsetDefaultReplyChannel(MessageChannel defaultReplyChannel) Set the default reply channel.voidsetDefaultReplyChannelName(String defaultReplyChannelName) Set the default reply channel bean name.voidsetDefaultReplyTimeout(Long defaultReplyTimeout) Set the default timeout value for receiving reply messages.voidsetDefaultReplyTimeoutExpression(Expression defaultReplyTimeout) Set an expression to be evaluated to determine the default timeout value for receiving reply messages.voidsetDefaultReplyTimeoutExpressionString(String defaultReplyTimeout) Set an expression to be evaluated to determine the default timeout value for receiving reply messages.voidsetDefaultRequestChannel(MessageChannel defaultRequestChannel) Set the default request channel.voidsetDefaultRequestChannelName(String defaultRequestChannelName) Set the default request channel bean name.voidsetDefaultRequestTimeout(Long defaultRequestTimeout) Set the default timeout value for sending request messages.voidsetDefaultRequestTimeoutExpression(Expression defaultRequestTimeout) Set an expression to be evaluated to determine the default timeout value for sending request messages.voidsetDefaultRequestTimeoutExpressionString(String defaultRequestTimeout) Set an expression to be evaluated to determine the default timeout value for sending request messages.voidsetErrorChannel(MessageChannel errorChannel) Set the error channel.voidsetErrorChannelName(String errorChannelName) Set the error channel name.voidsetErrorOnTimeout(boolean errorOnTimeout) If errorOnTimeout is true, null won't be returned as a result of a gateway method invocation, when a timeout occurs.voidsetGlobalMethodMetadata(GatewayMethodMetadata globalMethodMetadata) final voidsetMapper(MethodArgsMessageMapper mapper) voidsetMethodMetadataMap(Map<String, GatewayMethodMetadata> methodMetadataMap) voidsetProxyDefaultMethods(boolean proxyDefaultMethods) Indicate ifdefaultmethods on the interface should be proxied as well.voidsetShouldTrack(boolean shouldTrack) voidsetTypeConverter(TypeConverter typeConverter) Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stopMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.beans.factory.FactoryBean
isSingletonMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getOverrides, getThisAs, isLoggingEnabled, isObserved, registerObservationRegistry, setLoggingEnabled, setManagedName, setManagedTypeMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName, getComponentType
-
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
-
-
Method Details
-
setDefaultRequestChannel
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
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
-
getDefaultRequestChannelName
-
setDefaultReplyChannel
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
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
-
getDefaultReplyChannelName
-
setErrorChannel
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
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
-
getErrorChannelName
-
setDefaultRequestTimeout
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
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
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
-
setDefaultReplyTimeout
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
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
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
-
setShouldTrack
public void setShouldTrack(boolean shouldTrack) - Specified by:
setShouldTrackin interfaceTrackableComponent
-
setAsyncExecutor
Set the executor for use when the gateway method returnsFutureorListenableFuture. Set it to null to disable the async processing, and anyFuturereturn types must be returned by the downstream flow.- Parameters:
executor- The executor.
-
setTypeConverter
-
setMethodMetadataMap
-
setGlobalMethodMetadata
-
getGlobalMethodMetadata
-
setBeanClassLoader
- Specified by:
setBeanClassLoaderin interfaceBeanClassLoaderAware
-
setMapper
- Parameters:
mapper- the mapper.
-
getMapper
-
setProxyDefaultMethods
public void setProxyDefaultMethods(boolean proxyDefaultMethods) Indicate ifdefaultmethods on the interface should be proxied as well. If an explicitGatewayannotation is present on method it is proxied independently of this option. Note: default methods in JDK classes (such asFunction) can be proxied, but cannot be invoked viaMethodHandleby an internal Java security restriction forMethodHandle.Lookup.- Parameters:
proxyDefaultMethods- the boolean flag to proxy default methods or invoke viaMethodHandle.- Since:
- 5.3
-
getAsyncExecutor
-
isAsyncExecutorExplicitlySet
protected boolean isAsyncExecutorExplicitlySet() -
getGateways
Return the Map ofMethodtoMessagingGatewaySupportgenerated by this factory bean.- Returns:
- the map.
- Since:
- 4.3
-
registerMetricsCaptor
Description copied from interface:IntegrationManagementInject aMetricsCaptor. Ignored ifObservationRegistryis provided.- Specified by:
registerMetricsCaptorin interfaceIntegrationManagement- Parameters:
metricsCaptorToRegister- the captor.- See Also:
-
setErrorOnTimeout
public void setErrorOnTimeout(boolean errorOnTimeout) If errorOnTimeout is true, null won't be returned as a result of a gateway method invocation, when a timeout occurs. Instead, aMessageTimeoutExceptionis thrown or an error message is published to the error channel.- Parameters:
errorOnTimeout- true to create the error message on reply timeout.- Since:
- 6.2
- See Also:
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classAbstractEndpoint
-
getObjectType
- Specified by:
getObjectTypein interfaceFactoryBean<T>
-
getObject
- Specified by:
getObjectin interfaceFactoryBean<T>
-
invoke
- Specified by:
invokein interfaceMethodInterceptor- Throws:
Throwable
-
doInvoke
@Nullable protected Object doInvoke(MethodInvocation invocation, boolean runningOnCallerThread) throws Throwable - Throws:
Throwable
-
doStart
protected void doStart()Description copied from class:AbstractEndpointSubclasses must implement this method with the start behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock.- Specified by:
doStartin classAbstractEndpoint
-
doStop
protected void doStop()Description copied from class:AbstractEndpointSubclasses must implement this method with the stop behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock.- Specified by:
doStopin classAbstractEndpoint
-
destroy
public void destroy()- Specified by:
destroyin interfaceDisposableBean- Specified by:
destroyin interfaceIntegrationManagement- Overrides:
destroyin classAbstractEndpoint
-