Search in sources :

Example 1 with ComponentVerifierExtension

use of org.apache.camel.component.extension.ComponentVerifierExtension in project syndesis by syndesisio.

the class ComponentProxyComponent method getComponentVerifierExtension.

/**
 * Build a ComponentVerifierExtension using options bound to this component.
 */
@SuppressWarnings("PMD.AvoidCatchingGenericException")
private ComponentVerifierExtension getComponentVerifierExtension() {
    try {
        // 
        final Component component = getCamelContext().getComponent(componentScheme, true, false);
        final Optional<ComponentVerifierExtension> extension = component.getExtension(ComponentVerifierExtension.class);
        if (extension.isPresent()) {
            return (ComponentVerifierExtension.Scope scope, Map<String, Object> 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.class.cast(buildEndpointOptions(null, map));
                } catch (Exception e) {
                    // and stop the validation step.
                    return ResultBuilder.withStatusAndScope(ComponentVerifierExtension.Result.Status.OK, scope).error(ResultErrorBuilder.withException(e).build()).build();
                }
                return extension.get().verify(scope, options);
            };
        } else {
            return (scope, map) -> {
                return ResultBuilder.withStatusAndScope(ComponentVerifierExtension.Result.Status.UNSUPPORTED, scope).error(ResultErrorBuilder.withCode(ComponentVerifierExtension.VerificationError.StandardCode.UNSUPPORTED).detail("camel_connector_id", componentId).detail("camel_component_scheme", componentScheme).detail("camel_component_scheme_alias", componentSchemeAlias).build()).build();
            };
        }
    } catch (Exception e) {
        return (scope, map) -> {
            return ResultBuilder.withStatusAndScope(ComponentVerifierExtension.Result.Status.OK, scope).error(ResultErrorBuilder.withException(e).build()).build();
        };
    }
}
Also used : URISupport(org.apache.camel.util.URISupport) LoggerFactory(org.slf4j.LoggerFactory) ComponentExtension(org.apache.camel.component.extension.ComponentExtension) HashMap(java.util.HashMap) Component(org.apache.camel.Component) ComponentVerifierExtension(org.apache.camel.component.extension.ComponentVerifierExtension) Endpoint(org.apache.camel.Endpoint) DefaultCamelCatalog(org.apache.camel.catalog.DefaultCamelCatalog) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Processor(org.apache.camel.Processor) CamelCatalog(org.apache.camel.catalog.CamelCatalog) IntrospectionSupport(org.apache.camel.util.IntrospectionSupport) Map(java.util.Map) ResultBuilder(org.apache.camel.component.extension.verifier.ResultBuilder) DefaultComponent(org.apache.camel.impl.DefaultComponent) CamelContext(org.apache.camel.CamelContext) Logger(org.slf4j.Logger) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) ResultErrorBuilder(org.apache.camel.component.extension.verifier.ResultErrorBuilder) List(java.util.List) TypeConverter(org.apache.camel.TypeConverter) Optional(java.util.Optional) ObjectHelper(org.apache.camel.util.ObjectHelper) Predicates(org.apache.camel.util.function.Predicates) ComponentVerifierExtension(org.apache.camel.component.extension.ComponentVerifierExtension) Component(org.apache.camel.Component) DefaultComponent(org.apache.camel.impl.DefaultComponent) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) IOException(java.io.IOException)

Example 2 with ComponentVerifierExtension

use of org.apache.camel.component.extension.ComponentVerifierExtension in project syndesis by syndesisio.

the class ComponentVerifier method verify.

// *************************************
// Impl
// *************************************
@Override
public List<VerifierResponse> verify(CamelContext context, String connectorId, Map<String, Object> params) {
    final String scheme = getConnectorAction().orElse(connectorId);
    final ComponentVerifierExtension verifier = resolveComponentVerifierExtension(context, scheme);
    if (verifier == null) {
        return Collections.singletonList(createUnsupportedResponse(scheme));
    }
    customize(params);
    return doVerify(verifier, scheme, params);
}
Also used : ComponentVerifierExtension(org.apache.camel.component.extension.ComponentVerifierExtension)

Aggregations

ComponentVerifierExtension (org.apache.camel.component.extension.ComponentVerifierExtension)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 CamelContext (org.apache.camel.CamelContext)1 Component (org.apache.camel.Component)1 Endpoint (org.apache.camel.Endpoint)1 Processor (org.apache.camel.Processor)1 TypeConverter (org.apache.camel.TypeConverter)1 CamelCatalog (org.apache.camel.catalog.CamelCatalog)1 DefaultCamelCatalog (org.apache.camel.catalog.DefaultCamelCatalog)1 ComponentExtension (org.apache.camel.component.extension.ComponentExtension)1 ResultBuilder (org.apache.camel.component.extension.verifier.ResultBuilder)1