Class InvokeServiceCmd<T>
java.lang.Object
com.flowable.serviceregistry.engine.impl.cmd.InvokeServiceCmd<T>
- All Implemented Interfaces:
Command<T>
- Direct Known Subclasses:
InvokeListServiceCmd
,InvokeSingleServiceCmd
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
protected static enum
protected static class
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected ServiceInvocationResult
convertToServiceInvocationResult
(ServiceInvocationResponse invocationResponse, ServiceInvocationResultResponse result) protected ServiceInvocationResultResponse
createServiceInvocationResultResponseForJsonNode
(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Object responseObject) createValidateAndCompleteServiceInvocationInputDataMap
(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ExpressionManager expressionManager) Creates, validates and completes the service invocation data according the input parameter definition of the service.execute
(CommandContext commandContext) protected InvokeServiceCmd.ValueWrapper
extractValue
(com.fasterxml.jackson.databind.node.ObjectNode objectNode, ServiceOutputParameter outputParameter) protected InvokeServiceCmd.ValueWrapper
extractValue
(Object responseDataObject, ServiceOutputParameter outputParameter, ServiceInvocationResponse response, com.fasterxml.jackson.databind.ObjectMapper objectMapper) protected InvokeServiceCmd.ValueWrapper
extractValue
(Map<String, Object> responseMap, ServiceOutputParameter outputParameter) protected InvokeServiceCmd.ValueWrapper
extractValue
(VariableContainer container, ServiceOutputParameter outputParameter) protected Object
getDefaultValue
(ServiceOutputParameter outputParameter, String defaultValue, ServiceInvocationContext context, ExpressionManager expressionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper) protected String
protected Object
getLookupId
(ServiceDefinitionModel serviceDefinitionModel, ServiceInvocationResponse invocationResponse, Map<String, Object> resultMap, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Search for the lookup id value in the response according the mapping in the service definition and do proper handling of the response type (e.g.protected Collection<ServiceOutputParameter>
getNestedMappingOutputParameters
(NestedOutputMapping nestedOutputMapping, ServiceRegistryEngineConfiguration engineConfiguration, ServiceInvocationContextImpl context) protected ServiceDefinitionEntity
getServiceDefinition
(String tenantId, CommandContext commandContext) protected ServiceDefinitionModel
getServiceDefinitionModel
(ServiceDefinitionEntity serviceDefinition, CommandContext commandContext) protected ServiceInvoker
getServiceInvoker
(ServiceDefinitionModel serviceDefinitionModel, CommandContext commandContext) protected ServiceOperation
getServiceOperation
(ServiceDefinitionModel serviceDefinitionModel) handleObjectOutputTypeForArrayResponse
(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse, Iterable<?> responseObject) Handles service object output for array responses.handleOutputParametersValues
(Object responseData, ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, Collection<ServiceOutputParameter> outputParameters, ServiceInvocationResponse invocationResponse) handleOutputParameterValues
(Object responseData, ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse) Verifies and handles output values according the output paramter definition of the service (specially missing and null-value output).protected ServiceInvocationResultResponse
handleServiceInvocationResponse
(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvoker serviceInvoker, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse) protected boolean
hasNestedOutputMapping
(ServiceOutputParameter outputParameter) protected abstract T
invoke
(ServiceInvoker serviceInvoker, ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, CommandContext commandContext) protected T
invokeService
(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvoker serviceInvoker, ServiceInvocationContextImpl context, CommandContext commandContext) protected boolean
isErrorResponse
(ServiceInvocationResponse invocationResponse) protected void
processAndValidateInputParameter
(ServiceDefinitionModel serviceDefinitionModel, ServiceInputParameter inputParameter, Map<String, Object> serviceInvocationInputData, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ExpressionManager expressionManager) Internal method to process a single input parameter by looking at its definition and checking its value.protected ServiceDefinitionEntity
resolveServiceDefinitionByKey
(String tenantId, ServiceRegistryEngineConfiguration serviceEngineConfiguration) protected ServiceDefinitionEntity
resolveServiceDefinitionByReferenceKey
(String tenantId, ServiceDefinitionEntityManager serviceDefinitionEntityManager, CommandContext commandContext) protected boolean
shouldMapParameter
(boolean isErrorResponse, ServiceOutputParameter outputParameter, ServiceDefinitionModel model, ServiceOperation operation) protected void
validateOperationTypeMatchesRequestedType
(ServiceOperation operation, String requestedOperationType) protected void
-
Field Details
-
serviceInvocationBuilder
-
-
Constructor Details
-
InvokeServiceCmd
-
-
Method Details
-
execute
-
validateParameters
protected void validateParameters() -
createValidateAndCompleteServiceInvocationInputDataMap
protected Map<String,Object> createValidateAndCompleteServiceInvocationInputDataMap(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ExpressionManager expressionManager) Creates, validates and completes the service invocation data according the input parameter definition of the service.- Parameters:
serviceDefinitionModel
- the service definition model the invocation is based onserviceOperation
- the service operation representing the service to be invokedobjectMapper
- the object mapper used for creating and initializing variable values in JSONexpressionManager
- the expression manager used for evaluating default values for input parameters- Returns:
- the initialized and validated variable data map
- Throws:
FlowableIllegalArgumentException
- if the input parameter validation failed (e.g. a required parameter value was missing)
-
processAndValidateInputParameter
protected void processAndValidateInputParameter(ServiceDefinitionModel serviceDefinitionModel, ServiceInputParameter inputParameter, Map<String, Object> serviceInvocationInputData, com.fasterxml.jackson.databind.ObjectMapper objectMapper, ExpressionManager expressionManager) Internal method to process a single input parameter by looking at its definition and checking its value. If a required input parameters value is missing and no default one is provided, it will throw an exception.- Parameters:
serviceDefinitionModel
- the service definition model the invocation is based oninputParameter
- the input parameter to be processedserviceInvocationInputData
- the service invocation input data map to be validated and completed for the given parameterobjectMapper
- the object mapper used for creating and initializing variable values in JSONexpressionManager
- the expression manager used for evaluating default values for input parameters- Throws:
FlowableIllegalArgumentException
- if the input parameter validation failed (e.g. a required parameter value was missing)
-
getServiceDefinition
protected ServiceDefinitionEntity getServiceDefinition(String tenantId, CommandContext commandContext) -
resolveServiceDefinitionByKey
protected ServiceDefinitionEntity resolveServiceDefinitionByKey(String tenantId, ServiceRegistryEngineConfiguration serviceEngineConfiguration) -
resolveServiceDefinitionByReferenceKey
protected ServiceDefinitionEntity resolveServiceDefinitionByReferenceKey(String tenantId, ServiceDefinitionEntityManager serviceDefinitionEntityManager, CommandContext commandContext) -
getServiceDefinitionModel
protected ServiceDefinitionModel getServiceDefinitionModel(ServiceDefinitionEntity serviceDefinition, CommandContext commandContext) -
getServiceInvoker
protected ServiceInvoker getServiceInvoker(ServiceDefinitionModel serviceDefinitionModel, CommandContext commandContext) -
getServiceOperation
-
validateOperationTypeMatchesRequestedType
protected void validateOperationTypeMatchesRequestedType(ServiceOperation operation, String requestedOperationType) -
invokeService
protected T invokeService(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvoker serviceInvoker, ServiceInvocationContextImpl context, CommandContext commandContext) -
invoke
protected abstract T invoke(ServiceInvoker serviceInvoker, ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, CommandContext commandContext) -
handleServiceInvocationResponse
protected ServiceInvocationResultResponse handleServiceInvocationResponse(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvoker serviceInvoker, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse) -
createServiceInvocationResultResponseForJsonNode
protected ServiceInvocationResultResponse createServiceInvocationResultResponseForJsonNode(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse, com.fasterxml.jackson.databind.ObjectMapper objectMapper, Object responseObject) -
handleObjectOutputTypeForArrayResponse
protected Map<String,Object> handleObjectOutputTypeForArrayResponse(ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse, Iterable<?> responseObject) Handles service object output for array responses. Mappings extract the values into an array:GIVEN
- output parameter mappings:
[ {name: 'rawResponse', source: 'responseBody', type: 'json'}, {name: 'muppetName', mappingName: 'muppetCharacterNames', type: 'string'} ]
- payload:
[{id: 1, muppetName: 'Kermit'}, {id: 2, muppetName: 'Gonzo'}]
The resulting service output object looks like:
{ rawResponse: [{id: 1, muppetName: 'Kermit'}, {id: 2, muppetName: 'Gonzo'}], muppetCharacterNames: ['Kermit', 'Gonzo'] }
- output parameter mappings:
-
convertToServiceInvocationResult
protected ServiceInvocationResult convertToServiceInvocationResult(ServiceInvocationResponse invocationResponse, ServiceInvocationResultResponse result) -
handleOutputParameterValues
protected Map<String,Object> handleOutputParameterValues(Object responseData, ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, ServiceInvocationResponse invocationResponse) Verifies and handles output values according the output paramter definition of the service (specially missing and null-value output).- Parameters:
responseData
- the response returned by the invokerserviceDefinitionModel
- the service modelserviceOperation
- the operation which was invokedcontext
- the context within which the service was invokedinvocationResponse
- , theServiceInvocationResponse
for which the output params are handeled
-
handleOutputParametersValues
protected Map<String,Object> handleOutputParametersValues(Object responseData, ServiceDefinitionModel serviceDefinitionModel, ServiceOperation serviceOperation, ServiceInvocationContextImpl context, ServiceRegistryEngineConfiguration serviceEngineConfiguration, Collection<ServiceOutputParameter> outputParameters, ServiceInvocationResponse invocationResponse) -
shouldMapParameter
protected boolean shouldMapParameter(boolean isErrorResponse, ServiceOutputParameter outputParameter, ServiceDefinitionModel model, ServiceOperation operation) -
isErrorResponse
-
getNestedMappingOutputParameters
protected Collection<ServiceOutputParameter> getNestedMappingOutputParameters(NestedOutputMapping nestedOutputMapping, ServiceRegistryEngineConfiguration engineConfiguration, ServiceInvocationContextImpl context) -
getDefaultValue
protected Object getDefaultValue(ServiceOutputParameter outputParameter, String defaultValue, ServiceInvocationContext context, ExpressionManager expressionManager, com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
extractValue
protected InvokeServiceCmd.ValueWrapper extractValue(com.fasterxml.jackson.databind.node.ObjectNode objectNode, ServiceOutputParameter outputParameter) -
extractValue
protected InvokeServiceCmd.ValueWrapper extractValue(Map<String, Object> responseMap, ServiceOutputParameter outputParameter) -
extractValue
protected InvokeServiceCmd.ValueWrapper extractValue(VariableContainer container, ServiceOutputParameter outputParameter) -
extractValue
protected InvokeServiceCmd.ValueWrapper extractValue(Object responseDataObject, ServiceOutputParameter outputParameter, ServiceInvocationResponse response, com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
hasNestedOutputMapping
-
getLookupId
protected Object getLookupId(ServiceDefinitionModel serviceDefinitionModel, ServiceInvocationResponse invocationResponse, Map<String, Object> resultMap, com.fasterxml.jackson.databind.ObjectMapper objectMapper) Search for the lookup id value in the response according the mapping in the service definition and do proper handling of the response type (e.g. JSON vs map).- Parameters:
serviceDefinitionModel
- the service definition model where the lookup id mapping is taken frominvocationResponse
- the invocation response containing the lookup id field and its valueresultMap
- the result map containing the lookup idobjectMapper
- the object mapper needed for converting the value- Returns:
- the lookup id value, if available, null otherwise
-
getHeaderValue
-