Search in sources :

Example 1 with ComponentVerifier

use of org.apache.camel.ComponentVerifier in project camel by apache.

the class DefaultConnectorComponent method getVerifier.

@SuppressWarnings("unchecked")
@Override
public ComponentVerifier getVerifier() {
    final String scheme = model.getBaseScheme();
    final Component component = getCamelContext().getComponent(scheme);
    if (component instanceof VerifiableComponent) {
        return (scope, map) -> {
            Map<String, Object> options;
            try {
                // A little nasty hack required as verifier uses Map<String, Object>
                // to be compatible with all the methods in CamelContext whereas
                // catalog deals with Map<String, String>
                options = (Map) buildEndpointOptions(null, map);
            } catch (URISyntaxException e) {
                // and stop the validation step.
                return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.OK, scope).error(ResultErrorBuilder.withException(e).build()).build();
            }
            return ((VerifiableComponent) component).getVerifier().verify(scope, options);
        };
    } else {
        return (scope, map) -> {
            return ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED, scope).error(ResultErrorBuilder.withCode("unsupported").attribute("camel.connector.name", getConnectorName()).attribute("camel.component.name", getComponentName()).build()).build();
        };
    }
}
Also used : Logger(org.slf4j.Logger) ComponentVerifier(org.apache.camel.ComponentVerifier) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) ResultBuilder(org.apache.camel.impl.verifier.ResultBuilder) Component(org.apache.camel.Component) Endpoint(org.apache.camel.Endpoint) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultCamelCatalog(org.apache.camel.catalog.DefaultCamelCatalog) Constructor(java.lang.reflect.Constructor) LinkedHashMap(java.util.LinkedHashMap) CamelCatalog(org.apache.camel.catalog.CamelCatalog) IntrospectionSupport(org.apache.camel.util.IntrospectionSupport) Modifier(java.lang.reflect.Modifier) Map(java.util.Map) ResultErrorBuilder(org.apache.camel.impl.verifier.ResultErrorBuilder) DefaultComponent(org.apache.camel.impl.DefaultComponent) URISyntaxException(java.net.URISyntaxException) Component(org.apache.camel.Component) VerifiableComponent(org.apache.camel.VerifiableComponent) DefaultComponent(org.apache.camel.impl.DefaultComponent) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) VerifiableComponent(org.apache.camel.VerifiableComponent)

Aggregations

Constructor (java.lang.reflect.Constructor)1 Modifier (java.lang.reflect.Modifier)1 URISyntaxException (java.net.URISyntaxException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Component (org.apache.camel.Component)1 ComponentVerifier (org.apache.camel.ComponentVerifier)1 Endpoint (org.apache.camel.Endpoint)1 VerifiableComponent (org.apache.camel.VerifiableComponent)1 CamelCatalog (org.apache.camel.catalog.CamelCatalog)1 DefaultCamelCatalog (org.apache.camel.catalog.DefaultCamelCatalog)1 DefaultComponent (org.apache.camel.impl.DefaultComponent)1 ResultBuilder (org.apache.camel.impl.verifier.ResultBuilder)1 ResultErrorBuilder (org.apache.camel.impl.verifier.ResultErrorBuilder)1 IntrospectionSupport (org.apache.camel.util.IntrospectionSupport)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1