Class R2dbcMessageHandler
- All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, ReactiveMessageHandler
ReactiveMessageHandler which writes
Message payload into a Relational Database, using reactive r2dbc support.
Security note: SQL identifiers cannot be bound as parameters.
The table name (see setTableNameExpression(Expression)) and the keys of the Map
produced by setValuesExpression(Expression) are rendered into the SQL statement as is,
without validation or escaping; only the values of that map are bound as parameters.
The same applies to column names in a Criteria built from message data.
If these identifiers are derived from message data which comes from an untrusted source
(for example, a payload converted from JSON into a Map), the application is responsible
for validating them before the message reaches this handler.
For example, use a MessageFilter
(or a MessageSelectingInterceptor)
which accepts only known table and column names, or a transformer which copies only
an expected set of keys into the values map.
Header values can be checked with an
AllowListMessageHeaderSelector.
- Since:
- 5.4
- Author:
- Rohan Mukesh, Artem Bilan, Glenn Renfro
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionR2dbcMessageHandler(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations) Construct this instance using a fully created and initialized instance of providedR2dbcEntityOperations. -
Method Summary
Modifier and TypeMethodDescriptionprotected reactor.core.publisher.Mono<Void> handleMessageInternal(Message<?> message) protected voidonInit()Subclasses may implement this for initialization logic.voidsetCriteriaExpression(Expression criteriaExpression) Set a SpEL expression to evaluate aCriteriafor query to execute.voidSet aR2dbcMessageHandler.Typefor query to execute.voidsetQueryTypeExpression(Expression queryTypeExpression) Set a SpEL expression to evaluate aR2dbcMessageHandler.Typefor query to execute.voidsetTableName(String tableName) Specify a table in the target database to execute the query.voidsetTableNameExpression(Expression tableNameExpression) Set a SpEL expression to evaluate a table name at runtime against request message.voidsetValuesExpression(Expression valuesExpression) Set a SpEL expression to evaluate aMapfor name-value pairs to bind as parameters into a query.Methods inherited from class AbstractReactiveMessageHandler
handleMessageMethods inherited from class MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IntegrationManagement
getThisAsMethods inherited from interface NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
R2dbcMessageHandler
public R2dbcMessageHandler(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations) Construct this instance using a fully created and initialized instance of providedR2dbcEntityOperations.- Parameters:
r2dbcEntityOperations- The R2dbcEntityOperations implementation.
-
-
Method Details
-
setQueryType
Set aR2dbcMessageHandler.Typefor query to execute.- Parameters:
type- theR2dbcMessageHandler.Typeto use.
-
setQueryTypeExpression
Set a SpEL expression to evaluate aR2dbcMessageHandler.Typefor query to execute.- Parameters:
queryTypeExpression- the expression to use.
-
setTableName
Specify a table in the target database to execute the query.- Parameters:
tableName- the name of the table to use.
-
setTableNameExpression
Set a SpEL expression to evaluate a table name at runtime against request message. The result is rendered into the SQL statement as is; it must not come from untrusted message data without prior validation.- Parameters:
tableNameExpression- the expression to use.
-
setValuesExpression
Set a SpEL expression to evaluate aMapfor name-value pairs to bind as parameters into a query. Only the values are bound as parameters: the keys are rendered into the SQL statement as column names as is, so they must not come from untrusted message data without prior validation.- Parameters:
valuesExpression- the expression to use.
-
setCriteriaExpression
Set a SpEL expression to evaluate aCriteriafor query to execute.- Parameters:
criteriaExpression- the expression to use.
-
getComponentType
- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classIntegrationObjectSupport
-
handleMessageInternal
- Specified by:
handleMessageInternalin classAbstractReactiveMessageHandler
-