private void declareErrorModels(OperationDeclarer operationDeclarer, XmlDslModel xmlDslModel, String operationName, ComponentModel operationModel) { Optional<ComponentModel> optionalParametersComponentModel = operationModel.getInnerComponents() .stream() .filter(child -> child.getIdentifier().equals(OPERATION_ERRORS_IDENTIFIER)).findAny(); optionalParametersComponentModel.ifPresent(componentModel -> componentModel.getInnerComponents() .stream() .filter(child -> child.getIdentifier().equals(OPERATION_ERROR_IDENTIFIER)) .forEach(param -> { final String namespace = xmlDslModel.getPrefix().toUpperCase(); final String typeName = param.getParameters().get(ERROR_TYPE_ATTRIBUTE); if (StringUtils.isBlank(typeName)) { throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> with an empty 'type' attribute", operationName)); } if (typeName.contains(NAMESPACE_SEPARATOR)) { throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> [%s] that contains a reserved character [%s]", operationName, typeName, NAMESPACE_SEPARATOR)); } operationDeclarer.withErrorModel(ErrorModelBuilder.newError(typeName, namespace) .withParent(ErrorModelBuilder.newError(ANY).build()) .build()); })); }
/** * @param errorTypeDefinition * @param errorModelMap * @return */ private ErrorModel toErrorModel(ErrorTypeDefinition<?> errorTypeDefinition, Map<String, ErrorModel> errorModelMap) { if (errorModelMap.containsKey(toIdentifier(errorTypeDefinition))) { return errorModelMap.get(toIdentifier(errorTypeDefinition)); } else { ErrorModelBuilder builder = newError(errorTypeDefinition.getType(), getErrorNamespace(errorTypeDefinition)); builder.withParent(toErrorModel(errorTypeDefinition.getParent().orElse(ANY), errorModelMap)); ErrorModel errorModel = builder.build(); errorModelMap.put(toIdentifier(errorTypeDefinition), errorModel); return errorModel; } }
@Test public void handleThrowingChildErrorsFromTheOneDeclared() { Set<ErrorModel> errors = new HashSet<>(); ErrorModel parent = newError(PARENT.getType(), ERROR_NAMESPACE).build(); ErrorModel child = newError(CHILD.getType(), ERROR_NAMESPACE).withParent(parent).build(); errors.add(parent); ErrorType parentErrorType = typeRepository.addErrorType(getIdentifier(parent), typeRepository.getAnyErrorType()); typeRepository.addErrorType(getIdentifier(child), parentErrorType); when(operationModel.getErrorModels()).thenReturn(errors); ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository); ModuleException moduleException = new ModuleException(CHILD, new RuntimeException()); Throwable throwable = handler.processException(moduleException); assertThat(throwable, is(instanceOf(TypedException.class))); ErrorType errorType = ((TypedException) throwable).getErrorType(); assertThat(errorType.getIdentifier(), is(CHILD.getType())); assertThat(errorType.getNamespace(), is(ERROR_NAMESPACE)); }
ErrorModelBuilder.newError("CUSTOM_ERROR_HERE", extensionModel .getXmlDslModel().getPrefix().toUpperCase()) .withParent(ErrorModelBuilder .newError(ANY).build()) .build(), .newError("ANOTHER_CUSTOM_ERROR_HERE", extensionModel .getXmlDslModel().getPrefix().toUpperCase()) .withParent(ErrorModelBuilder .newError(ANY).build()) .build()));
.withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build(); .withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
hasItem(newError(TRANSFORMATION).withParent(errorMuleAny).build()));
private ErrorModel buildError(String errorIdentifier, Map<String, Pair<String, ErrorModelBuilder>> buildingErrors, Map<String, ErrorModel> builtErrorModels) { if (builtErrorModels.containsKey(errorIdentifier)) { return builtErrorModels.get(errorIdentifier); } else { Pair<String, ErrorModelBuilder> builderPair = buildingErrors.get(errorIdentifier); if (builderPair != null) { String parentError = builderPair.getFirst(); ErrorModel errorModel; ErrorModelBuilder errorBuilder = builderPair.getSecond(); if (!isEmpty(parentError)) { errorModel = errorBuilder.withParent(buildError(parentError, buildingErrors, builtErrorModels)).build(); } else { errorModel = errorBuilder.build(); } builtErrorModels.put(errorIdentifier, errorModel); return errorModel; } else { ComponentIdentifier identifier = buildFromStringRepresentation(errorIdentifier); return buildSimpleError(identifier, builtErrorModels); } } }
/** * @param errorTypeDefinition * @param errorModelMap * @return */ private ErrorModel toErrorModel(ErrorTypeDefinition<?> errorTypeDefinition, Map<String, ErrorModel> errorModelMap) { if (errorModelMap.containsKey(toIdentifier(errorTypeDefinition))) { return errorModelMap.get(toIdentifier(errorTypeDefinition)); } else { ErrorModelBuilder builder = newError(errorTypeDefinition.getType(), getErrorNamespace(errorTypeDefinition)); builder.withParent(toErrorModel(errorTypeDefinition.getParent().orElse(ANY), errorModelMap)); ErrorModel errorModel = builder.build(); errorModelMap.put(toIdentifier(errorTypeDefinition), errorModel); return errorModel; } }
private void declareErrors(ExtensionDeclarer extensionDeclarer) { final ErrorModel overloadError = newError(OVERLOAD).withParent(criticalError).build(); final ErrorModel securityError = newError(SECURITY).withParent(anyError).build(); final ErrorModel sourceError = newError(SOURCE).withParent(anyError).build(); final ErrorModel sourceResponseError = newError(SOURCE_RESPONSE).withParent(anyError).build(); final ErrorModel serverSecurityError = newError(SERVER_SECURITY).withParent(securityError).build(); extensionDeclarer.withErrorModel(newError(EXPRESSION).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(TRANSFORMATION).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(CONNECTIVITY).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(RETRY_EXHAUSTED).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(REDELIVERY_EXHAUSTED).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(STREAM_MAXIMUM_SIZE_EXCEEDED).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(TIMEOUT).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(UNKNOWN).handleable(false).withParent(anyError).build()); extensionDeclarer.withErrorModel(newError(CLIENT_SECURITY).withParent(securityError).build()); extensionDeclarer.withErrorModel(newError(NOT_PERMITTED).withParent(securityError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_GENERATE).handleable(false).withParent(sourceError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_ERROR_RESPONSE_SEND).handleable(false).withParent(sourceError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_GENERATE).withParent(sourceResponseError).build()); extensionDeclarer.withErrorModel(newError(SOURCE_RESPONSE_SEND).handleable(false).withParent(sourceResponseError).build()); extensionDeclarer.withErrorModel(newError(FLOW_BACK_PRESSURE).handleable(false).withParent(overloadError).build()); extensionDeclarer.withErrorModel(newError(FATAL).handleable(false).withParent(criticalError).build());
.withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build(); .withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
hasItem(newError(TRANSFORMATION).withParent(errorMuleAny).build()));