Tabnine Logo
ErrorModelBuilder.newError
Code IndexAdd Tabnine to your IDE (free)

How to use
newError
method
in
org.mule.runtime.api.meta.model.error.ErrorModelBuilder

Best Java code snippets using org.mule.runtime.api.meta.model.error.ErrorModelBuilder.newError (Showing top 19 results out of 315)

origin: mulesoft/mule

 private void initErrorModelMap(Map<String, ErrorModel> errorModelMap) {
  errorModelMap.put(toIdentifier(ANY), newError(ANY.getType(), MULE).build());
 }
}
origin: mulesoft/mule

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());
   }));
}
origin: mulesoft/mule

/**
 * @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;
 }
}
origin: mulesoft/mule

@Test
public void handleThrowingOfNotRegisteredErrorType() {
 when(operationModel.getErrorModels()).thenReturn(singleton(newError(CONNECTIVITY_ERROR_IDENTIFIER, ERROR_NAMESPACE).build()));
 ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
 ModuleException moduleException =
   new ModuleException(CONNECTIVITY, new RuntimeException());
 assertThatThrownBy(() -> handler.processException(moduleException))
   .isInstanceOf(MuleRuntimeException.class)
   .hasMessage("The component 'testOperation' from the connector 'Test Extension' attempted to throw 'TEST-EXTENSION:CONNECTIVITY',"
     +
     " but it was not registered in the Error Repository");
}
origin: mulesoft/mule

@Test
public void operationTriesToAddInternalErrorType() {
 ErrorTypeRepository repository = mock(ErrorTypeRepository.class);
 when(repository.getErrorType(any())).then((e) -> typeRepository.getErrorType(((ComponentIdentifier) e.getArguments()[0])));
 ErrorModel internalRepeatedError = ErrorModelBuilder.newError(SOURCE_RESPONSE_GENERATE).build();
 when(operationWithError.getErrorModels()).thenReturn(singleton(internalRepeatedError));
 when(extensionModel.getOperationModels()).thenReturn(singletonList(operationWithError));
 when(extensionModel.getErrorModels()).thenReturn(singleton(internalRepeatedError));
 ErrorTypeLocator mockTypeLocator = mock(ErrorTypeLocator.class);
 errorsRegistrant = new ExtensionErrorsRegistrant(typeRepository, mockTypeLocator);
 errorsRegistrant.registerErrors(extensionModel);
 verify(repository, times(0)).addErrorType(any(), any());
}
origin: mulesoft/mule

DslSyntaxResolver syntaxResolver = DslSyntaxResolver.getDefault(extensionModel, new SingleExtensionImportTypesStrategy());
ErrorModel connectivityErrorModel = newError(CONNECTIVITY_ERROR_IDENTIFIER, errorExtensionNamespace)
  .withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build();
ErrorModel retryExhaustedError = newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, errorExtensionNamespace)
  .withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
origin: mulesoft/mule

@Test
public void handleThrowingOfNotDeclaredErrorType() {
 typeRepository.addErrorType(buildFromStringRepresentation(ERROR_NAMESPACE + ":" + CONNECTIVITY_ERROR_IDENTIFIER),
               typeRepository.getAnyErrorType());
 when(operationModel.getErrorModels())
   .thenReturn(singleton(newError(TRANSFORMATION_ERROR_IDENTIFIER, ERROR_NAMESPACE).build()));
 ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
 ModuleException moduleException =
   new ModuleException(CONNECTIVITY, new RuntimeException());
 assertThatThrownBy(() -> handler.processException(moduleException))
   .isInstanceOf(MuleRuntimeException.class)
   .hasMessage("The component 'testOperation' from the connector 'Test Extension' attempted to throw 'TEST-EXTENSION:CONNECTIVITY', "
     +
     "but only [TEST-EXTENSION:TRANSFORMATION] errors are allowed.");
}
origin: mulesoft/mule

@Test
public void handleTypedException() {
 when(operationModel.getErrorModels()).thenReturn(singleton(newError(CONNECTIVITY_ERROR_IDENTIFIER, ERROR_NAMESPACE).build()));
 ModuleExceptionHandler handler = new ModuleExceptionHandler(operationModel, extensionModel, typeRepository);
 typeRepository.addErrorType(builder()
   .name(CONNECTIVITY_ERROR_IDENTIFIER)
   .namespace(ERROR_NAMESPACE)
   .build(),
               typeRepository.getAnyErrorType());
 ModuleException moduleException =
   new ModuleException(CONNECTIVITY, new RuntimeException());
 Throwable exception = handler.processException(moduleException);
 assertThat(exception, is(instanceOf(TypedException.class)));
 ErrorType errorType = ((TypedException) exception).getErrorType();
 assertThat(errorType.getIdentifier(), is(CONNECTIVITY_ERROR_IDENTIFIER));
 assertThat(errorType.getNamespace(), is(ERROR_NAMESPACE));
}
origin: mulesoft/mule

@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));
}
origin: mulesoft/mule

assertThat(operationModel.getErrorModels(),
      containsInAnyOrder(
               ErrorModelBuilder.newError("CUSTOM_ERROR_HERE", extensionModel
                 .getXmlDslModel().getPrefix().toUpperCase())
                 .withParent(ErrorModelBuilder
                   .newError(ANY).build())
                 .build(),
               ErrorModelBuilder
                 .newError("ANOTHER_CUSTOM_ERROR_HERE", extensionModel
                   .getXmlDslModel().getPrefix().toUpperCase())
                 .withParent(ErrorModelBuilder
                   .newError(ANY).build())
                 .build()));
origin: mulesoft/mule

hasItem(newError(TRANSFORMATION).withParent(errorMuleAny).build()));
origin: org.mule.runtime/mule-extensions-api-persistence

 private ErrorModel buildSimpleError(ComponentIdentifier identifier, Map<String, ErrorModel> builtErrors) {
  ErrorModel errorModel = newError(identifier).build();
  builtErrors.put(identifier.toString(), errorModel);
  return errorModel;
 }
}
origin: org.mule.runtime/mule-extensions-api-persistence

 private static ErrorModel createErrorModel(String errorIdentifier) {
  ComponentIdentifier componentIdentifier = buildFromStringRepresentation(errorIdentifier);
  return newError(componentIdentifier).build();
 }
}
origin: org.mule.runtime/mule-module-extensions-support

 private void initErrorModelMap(Map<String, ErrorModel> errorModelMap) {
  errorModelMap.put(toIdentifier(ANY), newError(ANY.getType(), MULE).build());
 }
}
origin: org.mule.runtime/mule-extensions-api-persistence

/**
 * Given a {@link JsonArray} representing a {@link Set} of {@link ErrorModel}, it will deserialize them.
 * Also contribute with the given {@link this#errorModelRespository}.
 *
 * @param errors The json array
 * @return The a {@link Map} with the Error Identifier as key and the represented {@link ErrorModel}
 */
Map<String, ErrorModel> parseErrors(JsonArray errors) {
 Map<String, Pair<String, ErrorModelBuilder>> buildingErrors = new LinkedHashMap<>();
 errors.iterator().forEachRemaining(element -> {
  JsonObject error = element.getAsJsonObject();
  String anError = error.get(ERROR).getAsString();
  String parentError = EMPTY;
  if (error.has(PARENT)) {
   parentError = error.get(PARENT).getAsString();
  }
  ErrorModelBuilder errorModelBuilder = newError(buildFromStringRepresentation(anError));
  if (error.has(HANDLEABLE)) {
   errorModelBuilder.handleable(error.get(HANDLEABLE).getAsBoolean());
  }
  buildingErrors.put(anError, new Pair<>(parentError, errorModelBuilder));
 });
 buildingErrors.keySet().forEach(key -> buildError(key, buildingErrors, errorModelRespository));
 return errorModelRespository;
}
origin: org.mule.runtime/mule-module-extensions-support

/**
 * @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;
 }
}
origin: org.mule.runtime/mule-module-extensions-support

DslSyntaxResolver syntaxResolver = DslSyntaxResolver.getDefault(extensionModel, new SingleExtensionImportTypesStrategy());
ErrorModel connectivityErrorModel = newError(CONNECTIVITY_ERROR_IDENTIFIER, errorExtensionNamespace)
  .withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build();
ErrorModel retryExhaustedError = newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, errorExtensionNamespace)
  .withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
origin: org.mule.runtime/mule-core

private void declareErrors(ExtensionDeclarer extensionDeclarer) {
 final ErrorModel criticalError = newError(CRITICAL).handleable(false).build();
 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());
origin: org.mule.runtime/mule-core-tests

hasItem(newError(TRANSFORMATION).withParent(errorMuleAny).build()));
org.mule.runtime.api.meta.model.errorErrorModelBuildernewError

Popular methods of ErrorModelBuilder

  • build
  • withParent
  • handleable

Popular in Java

  • Parsing JSON documents to java classes using gson
  • findViewById (Activity)
  • setScale (BigDecimal)
  • putExtra (Intent)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • ArrayList (java.util)
    ArrayList is an implementation of List, backed by an array. All optional operations including adding
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • LogFactory (org.apache.commons.logging)
    Factory for creating Log instances, with discovery and configuration features similar to that employ
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now