Class R2dbcMessageHandler

All Implemented Interfaces:
Aware, BeanFactoryAware, BeanNameAware, DisposableBean, InitializingBean, ApplicationContextAware, Ordered, ComponentSourceAware, ExpressionCapable, Orderable, IntegrationPattern, NamedComponent, IntegrationManagement, TrackableComponent, ReactiveMessageHandler

public class R2dbcMessageHandler extends AbstractReactiveMessageHandler
Implementation of 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
  • Constructor Details

    • R2dbcMessageHandler

      public R2dbcMessageHandler(org.springframework.data.r2dbc.core.R2dbcEntityOperations r2dbcEntityOperations)
      Construct this instance using a fully created and initialized instance of provided R2dbcEntityOperations.
      Parameters:
      r2dbcEntityOperations - The R2dbcEntityOperations implementation.
  • Method Details

    • setQueryType

      public void setQueryType(R2dbcMessageHandler.Type type)
      Set a R2dbcMessageHandler.Type for query to execute.
      Parameters:
      type - the R2dbcMessageHandler.Type to use.
    • setQueryTypeExpression

      public void setQueryTypeExpression(Expression queryTypeExpression)
      Set a SpEL expression to evaluate a R2dbcMessageHandler.Type for query to execute.
      Parameters:
      queryTypeExpression - the expression to use.
    • setTableName

      public void setTableName(String tableName)
      Specify a table in the target database to execute the query.
      Parameters:
      tableName - the name of the table to use.
    • setTableNameExpression

      public void setTableNameExpression(Expression tableNameExpression)
      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

      public void setValuesExpression(Expression valuesExpression)
      Set a SpEL expression to evaluate a Map for 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

      public void setCriteriaExpression(Expression criteriaExpression)
      Set a SpEL expression to evaluate a Criteria for query to execute.
      Parameters:
      criteriaExpression - the expression to use.
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface NamedComponent
      Overrides:
      getComponentType in class MessageHandlerSupport
    • onInit

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

      protected reactor.core.publisher.Mono<Void> handleMessageInternal(Message<?> message)
      Specified by:
      handleMessageInternal in class AbstractReactiveMessageHandler