To define acting parameters as parts of parameters, components must define
bindings for their references for value providers and sample data providers.
These bindings enable an acting parameter of the provider to take the value of
the evaluated DataWeave expression.
When no binding is defined for an acting parameter, the same implicit binding
is applied. The name of the acting parameter must be the same as the name
of the parameter in the component to take that parameter’s value.
Use the @Binding annotation to define an acting parameter. The @FieldValues
annotation and the @SampleData annotation takes an array of bindings
to define the values the acting parameter takes.
A defined binding declares the value that an acting parameter
takes by providing an extraction expression. This extraction expression is a
DataWeave expression that uses only selectors to retrieve the value for the
acting parameter.
The extraction expression used for the extraction of the value of the acting
parameter has some limitations:
-
It does not aggregate any data from the context. It is limited to
access only the value of a field in the parameter.
-
The first part of the extraction expression corresponds only to the
name of a parameter from the component.
-
The output media type is always application/java when executing the extraction
expression to give values to the acting parameters of a value provider or sample
data provider. This means that the provider does not expect other media types,
such as application/json or application/xml.
The available context for the expression has the value of all the component’s
parameters. The expression must start with the name of the parameter of the
component. If the value comes from a part of the parameter, the expression
follows the selector to the desired field.
The following example shows a parameter named body that has a field with
values that depend on the acting parameter workspace:
public class ChatOperations {
public void sendChatMessage(@Connection ChatConnection chatConnection,
@FieldValues(value = ChannelsValueProvider.class, targetSelectors = "channelId",
bindings = {@Binding(actingParameter = "workspace", extractionExpression = "body.routingInfo.workspace")}))
@TypeResolver(ChatMessageResolver.class) @Content InputStream body) {
// Do message sending
}
}
This acting parameter is taken from the same body parameter.
The following syntax shows the value provider used in this example:
public class ChannelsValueProvider implements ValueProvider {
@Connection
private ChatConnection chatConnection;
@Parameter
private String workspace;
@Override
public Set<Value> resolve() {
return ValueBuilder.getValuesFor(chatConnection.getChannels(workspace));
}
@Override
public String getId() {
return "Channels value provider";
}
}
The workspace acting parameter defined in the value provider is bound to the
extraction expression that takes the value of the field from the context
of the component.