use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class BaseGatewayConstraintValidator method isValidGateway.
protected <T extends Gateway> boolean isValidGateway(T gateway, ConstraintValidatorContext context, Function<String, GatewayValidator<T>> validatorGetter) {
if (gateway.getType() == null) {
addConstraintViolation(context, GATEWAY_TYPE_MISSING_ERROR, Collections.singletonMap(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName()));
return false;
}
if (gateway.getParameters() == null) {
addConstraintViolation(context, GATEWAY_PARAMETERS_MISSING_ERROR, Collections.singletonMap(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName()));
return false;
}
GatewayValidator<T> validator;
try {
validator = validatorGetter.apply(gateway.getType());
} catch (GatewayProviderException e) {
addConstraintViolation(context, GATEWAY_TYPE_NOT_RECOGNISED_ERROR, Map.of(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName(), TYPE_PARAM, gateway.getType()));
return false;
}
ValidationResult v = validator.isValid(gateway);
if (!v.isValid()) {
String message = v.getMessage();
if (message == null) {
addConstraintViolation(context, GATEWAY_PARAMETERS_NOT_VALID_ERROR, Map.of(GATEWAY_CLASS_PARAM, gateway.getClass().getSimpleName(), TYPE_PARAM, gateway.getType()));
} else {
addConstraintViolation(context, InterpolationHelper.escapeMessageParameter(message), Collections.emptyMap());
}
}
return v.isValid();
}
use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ExecutorImplTest method setup.
@BeforeEach
void setup() {
actionInvokerMock = mock(ActionInvoker.class);
ActionInvokerBuilder actionInvokerBuilder = mock(ActionInvokerBuilder.class);
when(actionInvokerBuilder.build(any(), any())).thenReturn(actionInvokerMock);
actionRuntime = mock(ActionRuntime.class);
when(actionRuntime.getInvokerBuilder(KafkaTopicAction.TYPE)).thenReturn(actionInvokerBuilder);
when(actionRuntime.getInvokerBuilder(WebhookAction.TYPE)).thenReturn(actionInvokerBuilder);
when(actionRuntime.getInvokerBuilder(not(or(eq(KafkaTopicAction.TYPE), eq(WebhookAction.TYPE))))).thenThrow(new GatewayProviderException("Unknown action type"));
meterRegistry = new SimpleMeterRegistry();
}
use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class ProcessorGatewayConstraintValidatorTest method beforeEach.
@BeforeEach
public void beforeEach() {
lenient().when(actionValidatorMock.isValid(any(Action.class))).thenReturn(ValidationResult.valid());
lenient().when(sourceValidatorMock.isValid(any(Source.class))).thenReturn(ValidationResult.valid());
lenient().when(gatewayConfiguratorMock.getActionValidator(TEST_ACTION_TYPE)).thenReturn(actionValidatorMock);
lenient().when(gatewayConfiguratorMock.getActionValidator(not(eq(TEST_ACTION_TYPE)))).thenThrow(new GatewayProviderException("No action provider found"));
lenient().when(gatewayConfiguratorMock.getSourceValidator(TEST_SOURCE_TYPE)).thenReturn(sourceValidatorMock);
lenient().when(gatewayConfiguratorMock.getSourceValidator(not(eq(TEST_SOURCE_TYPE)))).thenThrow(new GatewayProviderException("No source provider found"));
lenient().when(validatorContextMock.buildConstraintViolationWithTemplate(any(String.class))).thenReturn(builderMock);
lenient().when(validatorContextMock.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(validatorContextMock);
constraintValidator = new ProcessorGatewayConstraintValidator(gatewayConfiguratorMock);
}
use of com.redhat.service.smartevents.infra.exceptions.definitions.user.GatewayProviderException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class SendToBridgeActionResolver method resolve.
@Override
public Action resolve(Action action, String customerId, String bridgeId, String processorId) {
String destinationBridgeId = action.getParameterOrDefault(SendToBridgeAction.BRIDGE_ID_PARAM, bridgeId);
Map<String, String> parameters = new HashMap<>();
try {
String bridgeEndpoint = gatewayConfiguratorService.getBridgeEndpoint(destinationBridgeId, customerId);
String bridgeWebhookUrl = getBridgeWebhookUrl(bridgeEndpoint);
parameters.put(WebhookAction.ENDPOINT_PARAM, bridgeWebhookUrl);
parameters.put(WebhookAction.USE_TECHNICAL_BEARER_TOKEN_PARAM, "true");
} catch (MalformedURLException e) {
throw new GatewayProviderException("Can't find events webhook for bridge " + destinationBridgeId);
}
Action transformedAction = new Action();
transformedAction.setType(WebhookAction.TYPE);
transformedAction.setMapParameters(parameters);
return transformedAction;
}
Aggregations