You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2017/08/04 16:09:56 UTC
[05/19] camel git commit: CAMEL-11550: Component extensions
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/main/java/org/apache/camel/impl/verifier/OptionsGroup.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/verifier/OptionsGroup.java b/camel-core/src/main/java/org/apache/camel/impl/verifier/OptionsGroup.java
deleted file mode 100644
index 1df4383..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/verifier/OptionsGroup.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.impl.verifier;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-/**
- * A named group of options. A group of options requires that a set of
- * component parameters is given as a whole.
- *
- * <a id="#syntax">The option syntax can be
- * {@code "propertyName"} to denote required property and
- * {@code "!propertyName"} to denote required absence of a property.
- */
-public final class OptionsGroup implements Serializable {
- private final String name;
- private final Set<String> options;
-
- /**
- * Creates new named {@link OptionsGroup}.
- *
- * @param name the name of the group
- */
- public OptionsGroup(String name) {
- this.name = name;
- this.options = new HashSet<>();
- }
-
- /**
- * Creates new named {@link OptionsGroup} with a set of option
- * definitions.
- *
- * @param name the name of the group
- * @param options names of properties in the syntax mentioned in {@link OptionsGroup}
- */
- public OptionsGroup(String name, Collection<String> options) {
- this.name = name;
- this.options = new LinkedHashSet<>(options);
- }
-
- /**
- * Adds a option definition to this group. The option syntax can be
- * {@code "propertyName"} to denote required property and
- * {@code "!propertyName"} to denote required absence of a property.
- *
- * @param option definition.
- */
- public void addOption(String option) {
- this.options.add(option);
- }
-
- /**
- * The name of the group.
- */
- public String getName() {
- return name;
- }
-
- /**
- * The option definitions in this group.
- */
- public Set<String> getOptions() {
- return this.options;
- }
-
- /**
- * Adds a option definition to this group. The option syntax can be
- * {@code "propertyName"} to denote required property and
- * {@code "!propertyName"} to denote required absence of a property.
- *
- * @param option definition.
- */
- public OptionsGroup option(String option) {
- this.options.add(option);
- return this;
- }
-
- /**
- * Adds a number of option definitions to this group. The option
- * syntax can be {@code "propertyName"} to denote required
- * property and {@code "!propertyName"} to denote required absence
- * of a property.
- *
- * @param options options definition
- */
- public OptionsGroup options(String... options) {
- for (String option : options) {
- addOption(option);
- }
-
- return this;
- }
-
- /**
- * Creates new group with the specified name.
- *
- * @param name the name of the group
- */
- public static OptionsGroup withName(String name) {
- return new OptionsGroup(name);
- }
-
- /**
- * Creates new group with the specified name of the given
- * {@link Enum} name.
- *
- * @param enumItem the name of the group
- * @see Enum#name()
- */
- public static OptionsGroup withName(Enum<?> enumItem) {
- return new OptionsGroup(enumItem.name());
- }
-
- /**
- * Creates new group with the specified name and option definitions.
- *
- * @param name the name of the group
- * @param options options definition
- */
- public static OptionsGroup withNameAndOptions(String name, String... options) {
- return new OptionsGroup(name, Arrays.asList(options));
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultBuilder.java b/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultBuilder.java
deleted file mode 100644
index 5e8ddae..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultBuilder.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.impl.verifier;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.function.Supplier;
-
-import org.apache.camel.ComponentVerifier;
-import org.apache.camel.IllegalOptionException;
-import org.apache.camel.NoSuchOptionException;
-import org.apache.camel.util.function.ThrowingBiConsumer;
-import org.apache.camel.util.function.ThrowingConsumer;
-
-public final class ResultBuilder {
- private Optional<ComponentVerifier.Scope> scope;
- private Optional<ComponentVerifier.Result.Status> status;
- private List<ComponentVerifier.VerificationError> verificationErrors;
-
- public ResultBuilder() {
- this.scope = Optional.empty();
- this.status = scope.empty();
- }
-
- // **********************************
- // Accessors
- // **********************************
-
- public ResultBuilder scope(ComponentVerifier.Scope scope) {
- this.scope = Optional.of(scope);
- return this;
- }
-
- public ResultBuilder status(ComponentVerifier.Result.Status status) {
- this.status = Optional.of(status);
- return this;
- }
-
- public ResultBuilder error(ComponentVerifier.VerificationError verificationError) {
- if (this.verificationErrors == null) {
- this.verificationErrors = new ArrayList<>();
- }
-
- this.verificationErrors.add(verificationError);
- this.status = Optional.of(ComponentVerifier.Result.Status.ERROR);
-
- return this;
- }
-
- public ResultBuilder error(Optional<ComponentVerifier.VerificationError> error) {
- error.ifPresent(e -> error(e));
- return this;
- }
-
- public ResultBuilder error(Supplier<Optional<ComponentVerifier.VerificationError>> supplier) {
- return error(supplier.get());
- }
-
- public ResultBuilder error(ThrowingConsumer<ResultBuilder, Exception> consumer) {
- try {
- consumer.accept(this);
- } catch (NoSuchOptionException e) {
- error(ResultErrorBuilder.withMissingOption(e.getOptionName()).build());
- } catch (IllegalOptionException e) {
- error(ResultErrorBuilder.withIllegalOption(e.getOptionName(), e.getOptionValue()).build());
- } catch (Exception e) {
- error(ResultErrorBuilder.withException(e).build());
- }
-
- return this;
- }
-
- public <T> ResultBuilder error(T data, ThrowingBiConsumer<ResultBuilder, T, Exception> consumer) {
- try {
- consumer.accept(this, data);
- } catch (NoSuchOptionException e) {
- error(ResultErrorBuilder.withMissingOption(e.getOptionName()).build());
- } catch (IllegalOptionException e) {
- error(ResultErrorBuilder.withIllegalOption(e.getOptionName(), e.getOptionValue()).build());
- } catch (Exception e) {
- error(ResultErrorBuilder.withException(e).build());
- }
-
- return this;
- }
-
- public ResultBuilder errors(List<ComponentVerifier.VerificationError> verificationErrors) {
- verificationErrors.forEach(this::error);
- return this;
- }
-
- // **********************************
- // Build
- // **********************************
-
- public ComponentVerifier.Result build() {
- return new DefaultResult(
- scope.orElse(ComponentVerifier.Scope.PARAMETERS),
- status.orElse(ComponentVerifier.Result.Status.UNSUPPORTED),
- verificationErrors != null ? Collections.unmodifiableList(verificationErrors) : Collections.emptyList()
- );
- }
-
- // **********************************
- // Helpers
- // **********************************
-
- public static ResultBuilder withStatus(ComponentVerifier.Result.Status status) {
- return new ResultBuilder().status(status);
- }
-
- public static ResultBuilder withStatusAndScope(ComponentVerifier.Result.Status status, ComponentVerifier.Scope scope) {
- return new ResultBuilder().status(status).scope(scope);
- }
-
- public static ResultBuilder withScope(ComponentVerifier.Scope scope) {
- return new ResultBuilder().scope(scope);
- }
-
- public static ResultBuilder unsupported() {
- return withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED, ComponentVerifier.Scope.PARAMETERS);
- }
-
- public static ResultBuilder unsupportedScope(ComponentVerifier.Scope scope) {
- return withStatusAndScope(ComponentVerifier.Result.Status.UNSUPPORTED, scope);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorBuilder.java b/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorBuilder.java
deleted file mode 100644
index daadb48..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorBuilder.java
+++ /dev/null
@@ -1,213 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.impl.verifier;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Supplier;
-
-import org.apache.camel.ComponentVerifier.VerificationError;
-import org.apache.camel.util.ObjectHelper;
-
-public final class ResultErrorBuilder {
- private VerificationError.Code code;
- private String description;
- private Set<String> parameters;
- private Map<VerificationError.Attribute, Object> attributes;
-
- public ResultErrorBuilder() {
- }
-
- // **********************************
- // Accessors
- // **********************************
-
- public ResultErrorBuilder code(VerificationError.Code code) {
- this.code = code;
- return this;
- }
-
- public ResultErrorBuilder code(String code) {
- code(VerificationError.asCode(code));
- return this;
- }
-
- public ResultErrorBuilder description(String description) {
- this.description = description;
- return this;
- }
-
- public ResultErrorBuilder parameterKey(String parameter) {
- if (parameter != null) {
- if (this.parameters == null) {
- this.parameters = new HashSet<>();
- }
-
- this.parameters.add(parameter);
- }
- return this;
- }
-
- public ResultErrorBuilder parameterKeys(Collection<String> parameterList) {
- if (parameterList != null) {
- parameterList.forEach(this::parameterKey);
- }
-
- return this;
- }
-
- public ResultErrorBuilder detail(String key, Object value) {
- detail(VerificationError.asAttribute(key), value);
- return this;
- }
-
- public ResultErrorBuilder detail(VerificationError.Attribute key, Object value) {
- if (value != null) {
- if (this.attributes == null) {
- this.attributes = new HashMap<>();
- }
-
- this.attributes.put(key, value);
- }
- return this;
- }
-
- public <T> ResultErrorBuilder detail(String key, Supplier<Optional<T>> supplier) {
- detail(VerificationError.asAttribute(key), supplier);
- return this;
- }
-
- public <T> ResultErrorBuilder detail(VerificationError.Attribute key, Supplier<Optional<T>> supplier) {
- supplier.get().ifPresent(value -> detail(key, value));
- return this;
- }
-
- public ResultErrorBuilder details(Map<VerificationError.Attribute, Object> details) {
- for (Map.Entry<VerificationError.Attribute, Object> entry : details.entrySet()) {
- detail(entry.getKey(), entry.getValue());
- }
-
- return this;
- }
-
- // **********************************
- // Build
- // **********************************
-
- public VerificationError build() {
- return new DefaultResultVerificationError(
- code,
- description,
- parameters != null ? Collections.unmodifiableSet(parameters) : Collections.emptySet(),
- attributes != null ? Collections.unmodifiableMap(attributes) : Collections.emptyMap()
- );
- }
-
- // **********************************
- // Helpers
- // **********************************
-
- public static ResultErrorBuilder fromError(VerificationError error) {
- return new ResultErrorBuilder()
- .code(error.getCode())
- .description(error.getDescription())
- .parameterKeys(error.getParameterKeys())
- .details(error.getDetails());
- }
-
- public static ResultErrorBuilder withCode(VerificationError.Code code) {
- return new ResultErrorBuilder().code(code);
- }
-
- public static ResultErrorBuilder withCode(String code) {
- return new ResultErrorBuilder().code(code);
- }
-
- public static ResultErrorBuilder withHttpCode(int code) {
- return withCode(convertHttpCodeToErrorCode(code))
- .detail(VerificationError.HttpAttribute.HTTP_CODE, code);
- }
-
- public static ResultErrorBuilder withHttpCodeAndText(int code, String text) {
- return withCodeAndDescription(convertHttpCodeToErrorCode(code), text)
- .detail(VerificationError.HttpAttribute.HTTP_CODE, code)
- .detail(VerificationError.HttpAttribute.HTTP_TEXT, text);
- }
-
- private static VerificationError.StandardCode convertHttpCodeToErrorCode(int code) {
- return code >= 400 && code < 500 ? VerificationError.StandardCode.AUTHENTICATION : VerificationError.StandardCode.GENERIC;
- }
-
- public static ResultErrorBuilder withCodeAndDescription(VerificationError.Code code, String description) {
- return new ResultErrorBuilder().code(code).description(description);
- }
-
- public static ResultErrorBuilder withUnsupportedScope(String scope) {
- return new ResultErrorBuilder()
- .code(VerificationError.StandardCode.UNSUPPORTED_SCOPE)
- .description("Unsupported scope: " + scope);
- }
-
- public static ResultErrorBuilder withUnsupportedComponent(String component) {
- return new ResultErrorBuilder()
- .code(VerificationError.StandardCode.UNSUPPORTED_COMPONENT)
- .description("Unsupported component: " + component);
- }
-
- public static ResultErrorBuilder withException(Exception exception) {
- return new ResultErrorBuilder()
- .code(VerificationError.StandardCode.EXCEPTION)
- .description(exception.getMessage())
- .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, exception)
- .detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, exception.getClass().getName());
- }
-
- public static ResultErrorBuilder withMissingOption(String optionName) {
- return new ResultErrorBuilder()
- .code(VerificationError.StandardCode.MISSING_PARAMETER)
- .description(optionName + " should be set")
- .parameterKey(optionName);
- }
-
- public static ResultErrorBuilder withUnknownOption(String optionName) {
- return new ResultErrorBuilder()
- .code(VerificationError.StandardCode.UNKNOWN_PARAMETER)
- .description("Unknown option " + optionName)
- .parameterKey(optionName);
- }
-
- public static ResultErrorBuilder withIllegalOption(String optionName) {
- return new ResultErrorBuilder()
- .code(VerificationError.StandardCode.ILLEGAL_PARAMETER)
- .description("Illegal option " + optionName)
- .parameterKey(optionName);
- }
-
- public static ResultErrorBuilder withIllegalOption(String optionName, String optionValue) {
- return ObjectHelper.isNotEmpty(optionValue)
- ? new ResultErrorBuilder()
- .code(VerificationError.StandardCode.ILLEGAL_PARAMETER_VALUE)
- .description(optionName + " has wrong value (" + optionValue + ")")
- .parameterKey(optionName)
- : withIllegalOption(optionName);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java b/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java
deleted file mode 100644
index fb0dfc0..0000000
--- a/camel-core/src/main/java/org/apache/camel/impl/verifier/ResultErrorHelper.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.impl.verifier;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import java.util.TreeSet;
-import java.util.stream.Collectors;
-
-import org.apache.camel.ComponentVerifier.VerificationError;
-import org.apache.camel.util.ObjectHelper;
-
-/**
- * Helper that validates component parameters.
- */
-public final class ResultErrorHelper {
-
- private ResultErrorHelper() {
- }
-
- // **********************************
- // Helpers
- // **********************************
-
- /**
- *
- * @param parameterName the required option
- * @param parameters the
- * @return
- */
- public static Optional<VerificationError> requiresOption(String parameterName, Map<String, Object> parameters) {
- if (ObjectHelper.isEmpty(parameters.get(parameterName))) {
- return Optional.of(ResultErrorBuilder.withMissingOption(parameterName).build());
- }
-
- return Optional.empty();
- }
-
- /**
- * Validates that the given parameters satisfy any grouped options
- * ({@link OptionsGroup}). A parameter set is valid if it is
- * present and required by least one of the groups.
- *
- * <p>As an example consider that there are two option groups that
- * can be specified:
- * <ul>
- * <li>optionA: requires param1 and param2
- * <li>optionB: requires param1 and param3
- * </ul>
- *
- * Valid parameters are those that include param1 and either param2
- * and/or param3.
- *
- * <p>Note the special syntax of {@link OptionsGroup#getOptions()}
- * that can require an property ({@code "propertyName"}) or can
- * forbid the presence of a property ({@code "!propertyName"}).
- *
- * <p>With that if in the example above if param2 is specified
- * specifying param3 is not allowed, and vice versa option groups
- * should be defined with options:
- * <ul>
- * <li>optionA: ["param1", "param2", "!param3"]
- * <li>optionB: ["param1", "!param2", "param3"]
- * </ul>
- *
- * @param parameters given parameters of a component
- * @param groups groups of options
- * @see OptionsGroup
- */
- public static List<VerificationError> requiresAny(Map<String, Object> parameters, OptionsGroup... groups) {
- return requiresAny(parameters, Arrays.asList(groups));
- }
-
- /**
- * Validates that the given parameters satisfy any grouped options
- * ({@link OptionsGroup}). A parameter set is valid if it is
- * present and required by least one of the groups.
- *
- * @param parameters given parameters of a component
- * @param groups groups of options
- * @see #requiresAny(Map, OptionsGroup...)
- * @see OptionsGroup
- */
- public static List<VerificationError> requiresAny(Map<String, Object> parameters, Collection<OptionsGroup> groups) {
- final List<VerificationError> verificationErrors = new ArrayList<>();
- final Set<String> keys = new HashSet<>(parameters.keySet());
-
- for (OptionsGroup group : groups) {
- final Set<String> required = required(group.getOptions());
- final Set<String> excluded = excluded(group.getOptions());
-
- final ResultErrorBuilder builder = new ResultErrorBuilder()
- .code(VerificationError.StandardCode.ILLEGAL_PARAMETER_GROUP_COMBINATION)
- .detail(VerificationError.GroupAttribute.GROUP_NAME, group.getName())
- .detail(VerificationError.GroupAttribute.GROUP_OPTIONS, String.join(",", parameters(group.getOptions())));
-
- if (keys.containsAll(required)) {
- // All the options of this group are found so we are good
- final Set<String> shouldBeExcluded = new HashSet<>(keys);
- shouldBeExcluded.retainAll(excluded);
-
- if (shouldBeExcluded.isEmpty()) {
- // None of the excluded properties is present, also good
- return Collections.emptyList();
- }
-
- shouldBeExcluded.forEach(builder::parameterKey);
- verificationErrors.add(builder.build());
- } else {
-
- for (String option : required) {
- if (!parameters.containsKey(option)) {
- builder.parameterKey(option);
- }
- }
-
- for (String option : excluded) {
- if (parameters.containsKey(option)) {
- builder.parameterKey(option);
- }
- }
-
- verificationErrors.add(builder.build());
- }
- }
-
- return verificationErrors;
- }
-
- static Set<String> required(final Set<String> options) {
- return options.stream().filter(o -> !o.startsWith("!")).collect(Collectors.toSet());
- }
-
- static Set<String> excluded(final Set<String> options) {
- return options.stream().filter(o -> o.startsWith("!")).map(o -> o.substring(1)).collect(Collectors.toSet());
- }
-
- static Set<String> parameters(final Set<String> options) {
- final Set<String> withoutExclusionMark = options.stream().map(o -> o.replaceFirst("!", "")).collect(Collectors.toSet());
-
- return new TreeSet<String>(withoutExclusionMark);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedComponent.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedComponent.java
index 78af22a..931690f 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedComponent.java
@@ -34,8 +34,8 @@ import org.apache.camel.api.management.ManagedInstance;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.api.management.mbean.CamelOpenMBeanTypes;
import org.apache.camel.api.management.mbean.ManagedComponentMBean;
-import org.apache.camel.impl.verifier.ResultBuilder;
-import org.apache.camel.impl.verifier.ResultErrorBuilder;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
import org.apache.camel.spi.ManagementStrategy;
import org.apache.camel.util.CastUtils;
import org.apache.camel.util.JsonSchemaHelper;
@@ -158,7 +158,6 @@ public class ManagedComponent implements ManagedInstance, ManagedComponentMBean
return ResultBuilder.withStatus(ComponentVerifier.Result.Status.UNSUPPORTED)
.error(ResultErrorBuilder.withUnsupportedScope(scope).build())
.build();
-
}
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
index 1ee219c..c368d03 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java
@@ -32,6 +32,7 @@ import java.util.StringTokenizer;
import java.util.TreeMap;
import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
import org.apache.camel.Component;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
@@ -766,5 +767,4 @@ public final class CamelContextHelper {
}
}
}
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/ComponentVerifierTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/ComponentVerifierTest.java b/camel-core/src/test/java/org/apache/camel/ComponentVerifierTest.java
deleted file mode 100644
index 2eb944c..0000000
--- a/camel-core/src/test/java/org/apache/camel/ComponentVerifierTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel;
-import junit.framework.TestCase;
-import org.apache.camel.ComponentVerifier.VerificationError;
-import org.apache.camel.impl.verifier.ResultErrorBuilder;
-import org.junit.Assert;
-
-public class ComponentVerifierTest extends TestCase {
-
- public void testGetErrorDetails() {
- VerificationError error = ResultErrorBuilder.withCodeAndDescription(VerificationError.asCode("test_code"), "test error desc")
- .detail(VerificationError.asAttribute("test_attr_1"), "test_detail_1")
- .detail(VerificationError.HttpAttribute.HTTP_CODE, "test_detail_2")
- .build();
-
- Assert.assertEquals("test_detail_1", error.getDetail(VerificationError.asAttribute("test_attr_1")));
- Assert.assertEquals("test_detail_1", error.getDetail("test_attr_1"));
- Assert.assertEquals("test_detail_2", error.getDetail(VerificationError.HttpAttribute.HTTP_CODE));
- Assert.assertNull(error.getDetail(VerificationError.HttpAttribute.HTTP_TEXT));
-
- Assert.assertNull(error.getDetail(VerificationError.asAttribute("test_attr_non_existant")));
- }
-
- public void testNullCode() {
- try {
- VerificationError.asCode(null);
- fail("Code must not be null");
- } catch (IllegalArgumentException exp) {
- Assert.assertTrue(exp.getMessage().contains("null"));
- }
- }
-
- public void testNullAttribute() {
- try {
- VerificationError.asAttribute(null);
- fail("Attribute must not be null");
- } catch (IllegalArgumentException exp) {
- Assert.assertTrue(exp.getMessage().contains("null"));
- }
- }
-
- public void testScopeFromString() {
- Assert.assertEquals(ComponentVerifier.Scope.PARAMETERS, ComponentVerifier.Scope.fromString("PaRaMeTeRS"));
-
- try {
- ComponentVerifier.Scope.fromString("unknown");
- fail();
- } catch (IllegalArgumentException exp) {
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/component/extension/verifier/ComponentVerifierTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/extension/verifier/ComponentVerifierTest.java b/camel-core/src/test/java/org/apache/camel/component/extension/verifier/ComponentVerifierTest.java
new file mode 100644
index 0000000..1111e67
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/extension/verifier/ComponentVerifierTest.java
@@ -0,0 +1,66 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.extension.verifier;
+import junit.framework.TestCase;
+import org.apache.camel.ComponentVerifier;
+import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError;
+import org.junit.Assert;
+
+public class ComponentVerifierTest extends TestCase {
+
+ public void testGetErrorDetails() {
+ VerificationError error = ResultErrorBuilder.withCodeAndDescription(VerificationError.asCode("test_code"), "test error desc")
+ .detail(VerificationError.asAttribute("test_attr_1"), "test_detail_1")
+ .detail(VerificationError.HttpAttribute.HTTP_CODE, "test_detail_2")
+ .build();
+
+ Assert.assertEquals("test_detail_1", error.getDetail(VerificationError.asAttribute("test_attr_1")));
+ Assert.assertEquals("test_detail_1", error.getDetail("test_attr_1"));
+ Assert.assertEquals("test_detail_2", error.getDetail(VerificationError.HttpAttribute.HTTP_CODE));
+ Assert.assertNull(error.getDetail(VerificationError.HttpAttribute.HTTP_TEXT));
+
+ Assert.assertNull(error.getDetail(VerificationError.asAttribute("test_attr_non_existant")));
+ }
+
+ public void testNullCode() {
+ try {
+ VerificationError.asCode(null);
+ fail("Code must not be null");
+ } catch (IllegalArgumentException exp) {
+ Assert.assertTrue(exp.getMessage().contains("null"));
+ }
+ }
+
+ public void testNullAttribute() {
+ try {
+ VerificationError.asAttribute(null);
+ fail("Attribute must not be null");
+ } catch (IllegalArgumentException exp) {
+ Assert.assertTrue(exp.getMessage().contains("null"));
+ }
+ }
+
+ public void testScopeFromString() {
+ Assert.assertEquals(ComponentVerifier.Scope.PARAMETERS, ComponentVerifier.Scope.fromString("PaRaMeTeRS"));
+
+ try {
+ ComponentVerifier.Scope.fromString("unknown");
+ fail();
+ } catch (IllegalArgumentException exp) {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierExtensionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierExtensionTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierExtensionTest.java
new file mode 100644
index 0000000..a5adc8c
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierExtensionTest.java
@@ -0,0 +1,141 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.rest;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.spi.RestConfiguration;
+import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.spi.RestProducerFactory;
+import org.junit.Assert;
+
+public class RestComponentVerifierExtensionTest extends ContextTestSupport {
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry registry = super.createRegistry();
+ registry.bind("rest", new RestComponent());
+ registry.bind("rest-component", new MyComponent());
+ return registry;
+ }
+
+ public void testParameters() throws Exception {
+ RestComponent component = context.getComponent("rest", RestComponent.class);
+ RestComponentVerifierExtension verifier = component.getExtension(RestComponentVerifierExtension.class).orElseThrow(() -> new IllegalStateException());
+
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("componentName", "rest-component");
+ parameters.put("host", "http://localhost:1234");
+ parameters.put("path", "verify");
+ parameters.put("method", "get");
+
+ // This parameter does not belong to the rest component and validation
+ // is delegated to the underlying component
+ parameters.put("authProxy", "http://localhost:8080");
+
+ RestComponentVerifierExtension.Result result = verifier.verify(RestComponentVerifierExtension.Scope.PARAMETERS, parameters);
+
+ Assert.assertEquals(RestComponentVerifierExtension.Result.Status.OK, result.getStatus());
+ }
+
+ public void testMissingParameters() throws Exception {
+ RestComponent component = context.getComponent("rest", RestComponent.class);
+ RestComponentVerifierExtension verifier = component.getExtension(RestComponentVerifierExtension.class).orElseThrow(() -> new IllegalStateException());
+
+ Map<String, Object> parameters = new HashMap<>();
+ parameters.put("componentName", "rest-component");
+ parameters.put("host", "http://localhost:" + 1234);
+ parameters.put("path", "verify");
+
+ // This parameter does not belong to the rest component and validation
+ // is delegated to the underlying component
+ parameters.put("authProxy", "http://localhost:8080");
+
+ RestComponentVerifierExtension.Result result = verifier.verify(RestComponentVerifierExtension.Scope.PARAMETERS, parameters);
+
+ Assert.assertEquals(RestComponentVerifierExtension.Result.Status.ERROR, result.getStatus());
+ Assert.assertEquals(1, result.getErrors().size());
+ Assert.assertEquals(RestComponentVerifierExtension.VerificationError.StandardCode.MISSING_PARAMETER, result.getErrors().get(0).getCode());
+ Assert.assertEquals(1, result.getErrors().get(0).getParameterKeys().size());
+ Assert.assertTrue(result.getErrors().get(0).getParameterKeys().contains("method"));
+ }
+
+ // ***************************************************
+ //
+ // ***************************************************
+
+ private final class MyComponent extends DefaultComponent implements RestProducerFactory, RestConsumerFactory {
+
+ public MyComponent() {
+ registerExtension(
+ new ComponentVerifierExtension() {
+ @Override
+ public Result verify(Scope scope, Map<String, Object> parameters) {
+ return ResultBuilder.withStatusAndScope(RestComponentVerifierExtension.Result.Status.OK, scope)
+ .error(ResultErrorHelper.requiresOption("authProxy", parameters))
+ .build();
+ }
+ }
+ );
+ }
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Producer createProducer(
+ CamelContext camelContext,
+ String host,
+ String verb,
+ String basePath,
+ String uriTemplate,
+ String queryParameters,
+ String consumes,
+ String produces,
+ Map<String, Object> parameters)
+ throws Exception {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Consumer createConsumer(
+ CamelContext camelContext,
+ Processor processor,
+ String verb,
+ String basePath,
+ String uriTemplate,
+ String consumes,
+ String produces,
+ RestConfiguration configuration,
+ Map<String, Object> parameters)
+ throws Exception {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierTest.java
index 73fb130..ca8851e 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/RestComponentVerifierTest.java
@@ -26,11 +26,11 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
-import org.apache.camel.VerifiableComponent;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
import org.apache.camel.impl.DefaultComponent;
import org.apache.camel.impl.JndiRegistry;
-import org.apache.camel.impl.verifier.ResultBuilder;
-import org.apache.camel.impl.verifier.ResultErrorHelper;
import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.spi.RestProducerFactory;
@@ -47,7 +47,7 @@ public class RestComponentVerifierTest extends ContextTestSupport {
public void testParameters() throws Exception {
RestComponent component = context.getComponent("rest", RestComponent.class);
- RestComponentVerifier verifier = (RestComponentVerifier)component.getVerifier();
+ ComponentVerifier verifier = component.getVerifier();
Map<String, Object> parameters = new HashMap<>();
parameters.put("componentName", "rest-component");
@@ -66,7 +66,7 @@ public class RestComponentVerifierTest extends ContextTestSupport {
public void testMissingParameters() throws Exception {
RestComponent component = context.getComponent("rest", RestComponent.class);
- RestComponentVerifier verifier = (RestComponentVerifier)component.getVerifier();
+ ComponentVerifier verifier = component.getVerifier();
Map<String, Object> parameters = new HashMap<>();
parameters.put("componentName", "rest-component");
@@ -90,7 +90,19 @@ public class RestComponentVerifierTest extends ContextTestSupport {
//
// ***************************************************
- private final class MyComponent extends DefaultComponent implements RestProducerFactory, RestConsumerFactory, VerifiableComponent {
+ private final class MyComponent extends DefaultComponent implements RestProducerFactory, RestConsumerFactory {
+ public MyComponent() {
+ registerExtension(
+ new ComponentVerifierExtension() {
+ @Override
+ public Result verify(Scope scope, Map<String, Object> parameters) {
+ return ResultBuilder.withStatusAndScope(RestComponentVerifierExtension.Result.Status.OK, scope)
+ .error(ResultErrorHelper.requiresOption("authProxy", parameters))
+ .build();
+ }
+ }
+ );
+ }
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
throw new UnsupportedOperationException();
@@ -125,13 +137,5 @@ public class RestComponentVerifierTest extends ContextTestSupport {
throws Exception {
throw new UnsupportedOperationException();
}
-
- @Override
- public ComponentVerifier getVerifier() {
- return (scope, parameters) ->
- ResultBuilder.withStatusAndScope(ComponentVerifier.Result.Status.OK, scope)
- .error(ResultErrorHelper.requiresOption("authProxy", parameters))
- .build();
- }
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/impl/verifier/DefaultComponentVerifierTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/verifier/DefaultComponentVerifierTest.java b/camel-core/src/test/java/org/apache/camel/impl/verifier/DefaultComponentVerifierTest.java
index 8a903b8..9ade841 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/verifier/DefaultComponentVerifierTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/verifier/DefaultComponentVerifierTest.java
@@ -19,13 +19,16 @@ package org.apache.camel.impl.verifier;
import java.util.HashMap;
import java.util.Map;
-import org.apache.camel.ComponentVerifier;
-import org.apache.camel.ComponentVerifier.VerificationError;
import org.apache.camel.ContextTestSupport;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.component.extension.ComponentVerifierExtension.Result;
+import org.apache.camel.component.extension.ComponentVerifierExtension.Scope;
+import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError;
+import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
import org.junit.Assert;
public class DefaultComponentVerifierTest extends ContextTestSupport {
- private ComponentVerifier verifier;
+ private ComponentVerifierExtension verifier;
@Override
public boolean isUseRouteBuilder() {
@@ -36,7 +39,7 @@ public class DefaultComponentVerifierTest extends ContextTestSupport {
protected void setUp() throws Exception {
super.setUp();
- this.verifier = new DefaultComponentVerifier("timer", context);
+ this.verifier = new DefaultComponentVerifierExtension("timer", context);
}
// *************************************
@@ -48,16 +51,16 @@ public class DefaultComponentVerifierTest extends ContextTestSupport {
parameters.put("timerName", "dummy");
parameters.put("period", "1s");
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.PARAMETERS, parameters);
- Assert.assertEquals(ComponentVerifier.Result.Status.OK, result.getStatus());
+ Result result = verifier.verify(Scope.PARAMETERS, parameters);
+ Assert.assertEquals(Result.Status.OK, result.getStatus());
}
public void testParametersWithMissingMandatoryOptions() throws Exception {
Map<String, Object> parameters = new HashMap<>();
parameters.put("period", "1s");
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.PARAMETERS, parameters);
- Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
+ Result result = verifier.verify(Scope.PARAMETERS, parameters);
+ Assert.assertEquals(Result.Status.ERROR, result.getStatus());
Assert.assertEquals(1, result.getErrors().size());
Assert.assertEquals(VerificationError.StandardCode.MISSING_PARAMETER, result.getErrors().get(0).getCode());
@@ -70,8 +73,8 @@ public class DefaultComponentVerifierTest extends ContextTestSupport {
parameters.put("period", "1s");
parameters.put("fixedRate", "wrong");
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.PARAMETERS, parameters);
- Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
+ Result result = verifier.verify(Scope.PARAMETERS, parameters);
+ Assert.assertEquals(Result.Status.ERROR, result.getStatus());
Assert.assertEquals(1, result.getErrors().size());
Assert.assertEquals(VerificationError.StandardCode.ILLEGAL_PARAMETER_VALUE, result.getErrors().get(0).getCode());
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/impl/verifier/ResultErrorHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/verifier/ResultErrorHelperTest.java b/camel-core/src/test/java/org/apache/camel/impl/verifier/ResultErrorHelperTest.java
index 15b82fc..0c72829 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/verifier/ResultErrorHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/verifier/ResultErrorHelperTest.java
@@ -21,8 +21,11 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import org.apache.camel.ComponentVerifier.VerificationError;
-import org.apache.camel.ComponentVerifier.VerificationError.StandardCode;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
+import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError;
+import org.apache.camel.component.extension.ComponentVerifierExtension.VerificationError.StandardCode;
+import org.apache.camel.component.extension.verifier.OptionsGroup;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -49,7 +52,7 @@ public class ResultErrorHelperTest {
@Test
public void shouldValidateParameterExclusions() {
// combining param2 and param3 is not OK
- final List<VerificationError> results = ResultErrorHelper.requiresAny(map("param1", "param2", "param3"),
+ final List<ComponentVerifierExtension.VerificationError> results = ResultErrorHelper.requiresAny(map("param1", "param2", "param3"),
groups);
assertEquals(3, results.size());
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/camel-core/src/test/java/org/apache/camel/management/ManagedComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedComponentTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedComponentTest.java
index 491e766..ce1737c 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedComponentTest.java
@@ -26,9 +26,9 @@ import org.apache.camel.ComponentVerifier;
import org.apache.camel.Endpoint;
import org.apache.camel.VerifiableComponent;
import org.apache.camel.component.direct.DirectComponent;
+import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.impl.verifier.DefaultComponentVerifier;
-import org.apache.camel.impl.verifier.ResultBuilder;
public class ManagedComponentTest extends ManagementTestSupport {
private static final String[] VERIFY_SIGNATURE = new String[] {
@@ -100,7 +100,7 @@ public class ManagedComponentTest extends ManagementTestSupport {
private static class MyVerifiableComponent extends DefaultComponent implements VerifiableComponent {
@Override
public ComponentVerifier getVerifier() {
- return new DefaultComponentVerifier("my-verifiable-component", getCamelContext()) {
+ return new DefaultComponentVerifierExtension("my-verifiable-component", getCamelContext()) {
@Override
protected Result verifyConnectivity(Map<String, Object> parameters) {
return ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY).build();
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index 01c1730..2e2f6ed 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -30,6 +30,7 @@ import org.apache.camel.Producer;
import org.apache.camel.ResolveEndpointFailedException;
import org.apache.camel.SSLContextParametersAware;
import org.apache.camel.VerifiableComponent;
+import org.apache.camel.component.extension.ComponentVerifierExtension;
import org.apache.camel.http.common.HttpBinding;
import org.apache.camel.http.common.HttpCommonComponent;
import org.apache.camel.http.common.HttpConfiguration;
@@ -64,11 +65,13 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
private boolean useGlobalSslContextParameters;
public HttpComponent() {
- super(HttpEndpoint.class);
+ this(HttpEndpoint.class);
}
public HttpComponent(Class<? extends HttpEndpoint> endpointClass) {
super(endpointClass);
+
+ registerExtension(HttpComponentVerifierExtension::new);
}
/**
@@ -387,10 +390,8 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
this.useGlobalSslContextParameters = useGlobalSslContextParameters;
}
- /**
- * TODO: document
- */
+ @Override
public ComponentVerifier getVerifier() {
- return new HttpComponentVerifier(this);
+ return (scope, parameters) -> getExtension(ComponentVerifierExtension.class).orElseThrow(UnsupportedOperationException::new).verify(scope, parameters);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifier.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifier.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifier.java
deleted file mode 100644
index 309ff3e..0000000
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifier.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http;
-
-import java.net.UnknownHostException;
-import java.util.Map;
-import java.util.Optional;
-
-import org.apache.camel.ComponentVerifier;
-import org.apache.camel.http.common.HttpHelper;
-import org.apache.camel.impl.verifier.DefaultComponentVerifier;
-import org.apache.camel.impl.verifier.ResultBuilder;
-import org.apache.camel.impl.verifier.ResultErrorBuilder;
-import org.apache.camel.impl.verifier.ResultErrorHelper;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpMethod;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.params.HttpClientParams;
-
-final class HttpComponentVerifier extends DefaultComponentVerifier {
- private final HttpComponent component;
-
- HttpComponentVerifier(HttpComponent component) {
- super("http", component.getCamelContext());
-
- this.component = component;
- }
-
- // *********************************
- // Parameters validation
- // *********************************
-
- @Override
- protected Result verifyParameters(Map<String, Object> parameters) {
- // The default is success
- ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS);
-
- // Validate using the catalog
- super.verifyParametersAgainstCatalog(builder, parameters);
-
- // Validate if the auth/proxy combination is properly set-up
- Optional<String> authMethod = getOption(parameters, "authMethod", String.class);
- if (authMethod.isPresent()) {
- // If auth method is set, username and password must be provided
- builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
- builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
-
- // Check if the AuthMethod is known
- AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get());
- if (auth != AuthMethod.Basic && auth != AuthMethod.Digest && auth != AuthMethod.NTLM) {
- builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
- }
-
- // If auth method is NTLM, authDomain is mandatory
- if (auth == AuthMethod.NTLM) {
- builder.error(ResultErrorHelper.requiresOption("authDomain", parameters));
- }
- }
-
- return builder.build();
- }
-
- // *********************************
- // Connectivity validation
- // *********************************
-
- @Override
- protected Result verifyConnectivity(Map<String, Object> parameters) {
- // Default is success
- ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
-
- Optional<String> uri = getOption(parameters, "httpUri", String.class);
- if (!uri.isPresent()) {
- // lack of httpUri is a blocking issue
- builder.error(ResultErrorHelper.requiresOption("httpUri", parameters));
- } else {
- builder.error(parameters, this::verifyHttpConnectivity);
- }
-
- return builder.build();
- }
-
- private void verifyHttpConnectivity(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
- Optional<String> uri = getOption(parameters, "httpUri", String.class);
-
- HttpClient httpclient = createHttpClient(builder, parameters);
- HttpMethod method = new GetMethod(uri.get());
-
- try {
- int code = httpclient.executeMethod(method);
- String okCodes = getOption(parameters, "okStatusCodeRange", String.class).orElse("200-299");
-
- if (!HttpHelper.isStatusCodeOk(code, okCodes)) {
- if (code == 401) {
- // Unauthorized, add authUsername and authPassword to the list
- // of parameters in error
- builder.error(
- ResultErrorBuilder.withHttpCode(code)
- .description(method.getStatusText())
- .parameterKey("authUsername")
- .parameterKey("authPassword")
- .build()
- );
- } else if (code >= 300 && code < 400) {
- // redirect
- builder.error(
- ResultErrorBuilder.withHttpCode(code)
- .description(method.getStatusText())
- .parameterKey("httpUri")
- .detail(VerificationError.HttpAttribute.HTTP_REDIRECT, () -> HttpUtil.responseHeaderValue(method, "location"))
- .build()
- );
- } else if (code >= 400) {
- // generic http error
- builder.error(
- ResultErrorBuilder.withHttpCode(code)
- .description(method.getStatusText())
- .build()
- );
- }
- }
- } catch (UnknownHostException e) {
- builder.error(
- ResultErrorBuilder.withException(e)
- .parameterKey("httpUri")
- .build()
- );
- }
- }
-
- // *********************************
- // Helpers
- // *********************************
-
- private Optional<HttpClientConfigurer> configureAuthentication(ResultBuilder builder, Map<String, Object> parameters) {
- Optional<String> authMethod = getOption(parameters, "authMethod", String.class);
-
- if (authMethod.isPresent()) {
- Optional<String> authUsername = getOption(parameters, "authUsername", String.class);
- Optional<String> authPassword = getOption(parameters, "authPassword", String.class);
-
- if (authUsername.isPresent() && authUsername.isPresent()) {
- AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get());
- if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) {
- return Optional.of(
- new BasicAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get())
- );
- } else if (auth == AuthMethod.NTLM) {
- Optional<String> authDomain = getOption(parameters, "authDomain", String.class);
- Optional<String> authHost = getOption(parameters, "authHost", String.class);
-
- if (!authDomain.isPresent()) {
- builder.error(ResultErrorBuilder.withMissingOption("authDomain").build());
- } else {
- return Optional.of(
- new NTLMAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get(), authDomain.get(), authHost.orElse(null))
- );
- }
- } else {
- builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
- }
- } else {
- builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
- builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
- }
- }
- return Optional.empty();
- }
-
- private Optional<HttpClientConfigurer> configureProxy(ResultBuilder builder, Map<String, Object> parameters) {
- CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
-
- // Add a Proxy
- Optional<String> proxyHost = getOption(parameters, "proxyAuthHost", String.class);
- if (!proxyHost.isPresent()) {
- proxyHost = getOption(parameters, "proxyHost", String.class);
- }
-
- Optional<Integer> proxyPort = getOption(parameters, "proxyAuthPort", Integer.class);
- if (!proxyPort.isPresent()) {
- proxyPort = getOption(parameters, "proxyPort", Integer.class);
- }
-
- if (proxyHost.isPresent() || proxyPort.isPresent()) {
- configurer.addConfigurer(new HttpProxyConfigurer(proxyHost, proxyPort));
- }
-
-
- // Configure proxy auth
- Optional<String> authMethod = getOption(parameters, "proxyAuthMethod", String.class);
- if (authMethod.isPresent()) {
- Optional<String> authUsername = getOption(parameters, "proxyAuthUsername", String.class);
- Optional<String> authPassword = getOption(parameters, "proxyAuthPassword", String.class);
-
- if (authUsername.isPresent() && authUsername.isPresent()) {
- AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod);
- if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) {
- configurer.addConfigurer(
- new BasicAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get())
- );
- } else if (auth == AuthMethod.NTLM) {
- Optional<String> authDomain = getOption(parameters, "proxyAuthDomain", String.class);
- Optional<String> authHost = getOption(parameters, "proxyAuthHost", String.class);
-
- if (!authDomain.isPresent()) {
- builder.error(ResultErrorBuilder.withMissingOption("authDomain").build());
- } else {
- return Optional.of(
- new NTLMAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get(), authDomain.get(), authHost.orElse(null))
- );
- }
- } else {
- builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
- }
- } else {
- builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
- builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
- }
- }
-
- return Optional.of(configurer);
- }
-
- private HttpClient createHttpClient(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
- HttpClientParams clientParams = setProperties(new HttpClientParams(), "httpClient.", parameters);
- HttpClient client = new HttpClient(clientParams);
-
- CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
- configureProxy(builder, parameters).ifPresent(configurer::addConfigurer);
- configureAuthentication(builder, parameters).ifPresent(configurer::addConfigurer);
-
- configurer.configureHttpClient(client);
-
- return client;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java
new file mode 100644
index 0000000..620c688
--- /dev/null
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java
@@ -0,0 +1,246 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.http;
+
+import java.net.UnknownHostException;
+import java.util.Map;
+import java.util.Optional;
+
+import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
+import org.apache.camel.http.common.HttpHelper;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.params.HttpClientParams;
+
+final class HttpComponentVerifierExtension extends DefaultComponentVerifierExtension {
+
+ HttpComponentVerifierExtension() {
+ super("http");
+ }
+
+ // *********************************
+ // Parameters validation
+ // *********************************
+
+ @Override
+ protected Result verifyParameters(Map<String, Object> parameters) {
+ // The default is success
+ ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS);
+
+ // Validate using the catalog
+ super.verifyParametersAgainstCatalog(builder, parameters);
+
+ // Validate if the auth/proxy combination is properly set-up
+ Optional<String> authMethod = getOption(parameters, "authMethod", String.class);
+ if (authMethod.isPresent()) {
+ // If auth method is set, username and password must be provided
+ builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
+ builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
+
+ // Check if the AuthMethod is known
+ AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get());
+ if (auth != AuthMethod.Basic && auth != AuthMethod.Digest && auth != AuthMethod.NTLM) {
+ builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
+ }
+
+ // If auth method is NTLM, authDomain is mandatory
+ if (auth == AuthMethod.NTLM) {
+ builder.error(ResultErrorHelper.requiresOption("authDomain", parameters));
+ }
+ }
+
+ return builder.build();
+ }
+
+ // *********************************
+ // Connectivity validation
+ // *********************************
+
+ @Override
+ protected Result verifyConnectivity(Map<String, Object> parameters) {
+ // Default is success
+ ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
+
+ Optional<String> uri = getOption(parameters, "httpUri", String.class);
+ if (!uri.isPresent()) {
+ // lack of httpUri is a blocking issue
+ builder.error(ResultErrorHelper.requiresOption("httpUri", parameters));
+ } else {
+ builder.error(parameters, this::verifyHttpConnectivity);
+ }
+
+ return builder.build();
+ }
+
+ private void verifyHttpConnectivity(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
+ Optional<String> uri = getOption(parameters, "httpUri", String.class);
+
+ HttpClient httpclient = createHttpClient(builder, parameters);
+ HttpMethod method = new GetMethod(uri.get());
+
+ try {
+ int code = httpclient.executeMethod(method);
+ String okCodes = getOption(parameters, "okStatusCodeRange", String.class).orElse("200-299");
+
+ if (!HttpHelper.isStatusCodeOk(code, okCodes)) {
+ if (code == 401) {
+ // Unauthorized, add authUsername and authPassword to the list
+ // of parameters in error
+ builder.error(
+ ResultErrorBuilder.withHttpCode(code)
+ .description(method.getStatusText())
+ .parameterKey("authUsername")
+ .parameterKey("authPassword")
+ .build()
+ );
+ } else if (code >= 300 && code < 400) {
+ // redirect
+ builder.error(
+ ResultErrorBuilder.withHttpCode(code)
+ .description(method.getStatusText())
+ .parameterKey("httpUri")
+ .detail(VerificationError.HttpAttribute.HTTP_REDIRECT, () -> HttpUtil.responseHeaderValue(method, "location"))
+ .build()
+ );
+ } else if (code >= 400) {
+ // generic http error
+ builder.error(
+ ResultErrorBuilder.withHttpCode(code)
+ .description(method.getStatusText())
+ .build()
+ );
+ }
+ }
+ } catch (UnknownHostException e) {
+ builder.error(
+ ResultErrorBuilder.withException(e)
+ .parameterKey("httpUri")
+ .build()
+ );
+ }
+ }
+
+ // *********************************
+ // Helpers
+ // *********************************
+
+ private Optional<HttpClientConfigurer> configureAuthentication(ResultBuilder builder, Map<String, Object> parameters) {
+ Optional<String> authMethod = getOption(parameters, "authMethod", String.class);
+
+ if (authMethod.isPresent()) {
+ Optional<String> authUsername = getOption(parameters, "authUsername", String.class);
+ Optional<String> authPassword = getOption(parameters, "authPassword", String.class);
+
+ if (authUsername.isPresent() && authUsername.isPresent()) {
+ AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod.get());
+ if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) {
+ return Optional.of(
+ new BasicAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get())
+ );
+ } else if (auth == AuthMethod.NTLM) {
+ Optional<String> authDomain = getOption(parameters, "authDomain", String.class);
+ Optional<String> authHost = getOption(parameters, "authHost", String.class);
+
+ if (!authDomain.isPresent()) {
+ builder.error(ResultErrorBuilder.withMissingOption("authDomain").build());
+ } else {
+ return Optional.of(
+ new NTLMAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get(), authDomain.get(), authHost.orElse(null))
+ );
+ }
+ } else {
+ builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
+ }
+ } else {
+ builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
+ builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
+ }
+ }
+ return Optional.empty();
+ }
+
+ private Optional<HttpClientConfigurer> configureProxy(ResultBuilder builder, Map<String, Object> parameters) {
+ CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
+
+ // Add a Proxy
+ Optional<String> proxyHost = getOption(parameters, "proxyAuthHost", String.class);
+ if (!proxyHost.isPresent()) {
+ proxyHost = getOption(parameters, "proxyHost", String.class);
+ }
+
+ Optional<Integer> proxyPort = getOption(parameters, "proxyAuthPort", Integer.class);
+ if (!proxyPort.isPresent()) {
+ proxyPort = getOption(parameters, "proxyPort", Integer.class);
+ }
+
+ if (proxyHost.isPresent() || proxyPort.isPresent()) {
+ configurer.addConfigurer(new HttpProxyConfigurer(proxyHost, proxyPort));
+ }
+
+
+ // Configure proxy auth
+ Optional<String> authMethod = getOption(parameters, "proxyAuthMethod", String.class);
+ if (authMethod.isPresent()) {
+ Optional<String> authUsername = getOption(parameters, "proxyAuthUsername", String.class);
+ Optional<String> authPassword = getOption(parameters, "proxyAuthPassword", String.class);
+
+ if (authUsername.isPresent() && authUsername.isPresent()) {
+ AuthMethod auth = getCamelContext().getTypeConverter().convertTo(AuthMethod.class, authMethod);
+ if (auth == AuthMethod.Basic || auth == AuthMethod.Digest) {
+ configurer.addConfigurer(
+ new BasicAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get())
+ );
+ } else if (auth == AuthMethod.NTLM) {
+ Optional<String> authDomain = getOption(parameters, "proxyAuthDomain", String.class);
+ Optional<String> authHost = getOption(parameters, "proxyAuthHost", String.class);
+
+ if (!authDomain.isPresent()) {
+ builder.error(ResultErrorBuilder.withMissingOption("authDomain").build());
+ } else {
+ return Optional.of(
+ new NTLMAuthenticationHttpClientConfigurer(false, authUsername.get(), authPassword.get(), authDomain.get(), authHost.orElse(null))
+ );
+ }
+ } else {
+ builder.error(ResultErrorBuilder.withIllegalOption("authMethod", authMethod.get()).build());
+ }
+ } else {
+ builder.error(ResultErrorHelper.requiresOption("authUsername", parameters));
+ builder.error(ResultErrorHelper.requiresOption("authPassword", parameters));
+ }
+ }
+
+ return Optional.of(configurer);
+ }
+
+ private HttpClient createHttpClient(ResultBuilder builder, Map<String, Object> parameters) throws Exception {
+ HttpClientParams clientParams = setProperties(new HttpClientParams(), "httpClient.", parameters);
+ HttpClient client = new HttpClient(clientParams);
+
+ CompositeHttpConfigurer configurer = new CompositeHttpConfigurer();
+ configureProxy(builder, parameters).ifPresent(configurer::addConfigurer);
+ configureAuthentication(builder, parameters).ifPresent(configurer::addConfigurer);
+
+ configurer.configureHttpClient(client);
+
+ return client;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/42529399/components/camel-http/src/test/java/org/apache/camel/component/http/CamelComponentVerifierTest.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/test/java/org/apache/camel/component/http/CamelComponentVerifierTest.java b/components/camel-http/src/test/java/org/apache/camel/component/http/CamelComponentVerifierTest.java
deleted file mode 100644
index 76d918e..0000000
--- a/components/camel-http/src/test/java/org/apache/camel/component/http/CamelComponentVerifierTest.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.component.http;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.camel.ComponentVerifier;
-import org.apache.camel.ComponentVerifier.VerificationError;
-import org.apache.camel.component.http.handler.BasicValidationHandler;
-import org.apache.camel.test.AvailablePortFinder;
-import org.eclipse.jetty.server.Server;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class CamelComponentVerifierTest extends BaseHttpTest {
- private static final String AUTH_USERNAME = "camel";
- private static final String AUTH_PASSWORD = "password";
- private static final int PORT = AvailablePortFinder.getNextAvailable();
-
- private Server localServer;
-
- @Before
- @Override
- public void setUp() throws Exception {
- localServer = new Server(PORT);
- localServer.setHandler(handlers(
- contextHandler("/basic", new BasicValidationHandler("GET", null, null, getExpectedContent()))
- ));
-
- localServer.start();
-
- super.setUp();
- }
-
- @After
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
-
- if (localServer != null) {
- localServer.stop();
- }
- }
-
- @Override
- public boolean isUseRouteBuilder() {
- return false;
- }
-
- // *************************************************
- // Helpers
- // *************************************************
-
- protected String getLocalServerUri(String contextPath) throws Exception {
- return new StringBuilder()
- .append("http://")
- .append("localhost")
- .append(":")
- .append(PORT)
- .append(contextPath != null ? contextPath : "")
- .toString();
- }
-
- // *************************************************
- // Tests
- // *************************************************
-
- @Test
- public void testParameters() throws Exception {
- HttpComponent component = context().getComponent("http", HttpComponent.class);
- HttpComponentVerifier verifier = (HttpComponentVerifier)component.getVerifier();
-
- Map<String, Object> parameters = new HashMap<>();
- parameters.put("httpUri", getLocalServerUri("/basic"));
-
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.PARAMETERS, parameters);
-
- Assert.assertEquals(ComponentVerifier.Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testMissingMandatoryParameters() throws Exception {
- HttpComponent component = context().getComponent("http", HttpComponent.class);
- HttpComponentVerifier verifier = (HttpComponentVerifier)component.getVerifier();
-
- Map<String, Object> parameters = new HashMap<>();
-
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.PARAMETERS, parameters);
-
- Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
- Assert.assertEquals(1, result.getErrors().size());
-
- VerificationError error = result.getErrors().get(0);
-
- Assert.assertEquals(VerificationError.StandardCode.MISSING_PARAMETER, error.getCode());
- Assert.assertTrue(error.getParameterKeys().contains("httpUri"));
- }
-
- // *************************************************
- // Tests
- // *************************************************
-
- @Test
- public void testConnectivity() throws Exception {
- HttpComponent component = context().getComponent("http", HttpComponent.class);
- HttpComponentVerifier verifier = (HttpComponentVerifier)component.getVerifier();
-
- Map<String, Object> parameters = new HashMap<>();
- parameters.put("httpUri", getLocalServerUri("/basic"));
-
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.CONNECTIVITY, parameters);
-
- Assert.assertEquals(ComponentVerifier.Result.Status.OK, result.getStatus());
- }
-
- @Test
- public void testConnectivityWithWrongUri() throws Exception {
- HttpComponent component = context().getComponent("http", HttpComponent.class);
- HttpComponentVerifier verifier = (HttpComponentVerifier)component.getVerifier();
-
- Map<String, Object> parameters = new HashMap<>();
- parameters.put("httpUri", "http://www.not-existing-uri.unknown");
-
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.CONNECTIVITY, parameters);
-
- Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
- Assert.assertEquals(1, result.getErrors().size());
-
- VerificationError error = result.getErrors().get(0);
-
- Assert.assertEquals(VerificationError.StandardCode.EXCEPTION, error.getCode());
- Assert.assertTrue(error.getParameterKeys().contains("httpUri"));
- }
-
- @Ignore
- @Test
- public void testConnectivityWithAuthentication() throws Exception {
- HttpComponent component = context().getComponent("http", HttpComponent.class);
- HttpComponentVerifier verifier = (HttpComponentVerifier)component.getVerifier();
-
- Map<String, Object> parameters = new HashMap<>();
- parameters.put("httpUri", getLocalServerUri("/auth"));
- parameters.put("authUsername", AUTH_USERNAME);
- parameters.put("authPassword", AUTH_PASSWORD);
-
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.CONNECTIVITY, parameters);
-
- Assert.assertEquals(ComponentVerifier.Result.Status.OK, result.getStatus());
- }
-
- @Ignore
- @Test
- public void testConnectivityWithWrongAuthenticationData() throws Exception {
- HttpComponent component = context().getComponent("http", HttpComponent.class);
- HttpComponentVerifier verifier = (HttpComponentVerifier)component.getVerifier();
-
- Map<String, Object> parameters = new HashMap<>();
- parameters.put("httpUri", getLocalServerUri("/auth"));
- parameters.put("authUsername", "unknown");
- parameters.put("authPassword", AUTH_PASSWORD);
-
- ComponentVerifier.Result result = verifier.verify(ComponentVerifier.Scope.CONNECTIVITY, parameters);
-
- Assert.assertEquals(ComponentVerifier.Result.Status.ERROR, result.getStatus());
- Assert.assertEquals(1, result.getErrors().size());
-
- VerificationError error = result.getErrors().get(0);
-
- Assert.assertEquals(VerificationError.StandardCode.AUTHENTICATION, error.getCode());
- Assert.assertEquals(401, error.getDetails().get(VerificationError.HttpAttribute.HTTP_CODE));
- Assert.assertTrue(error.getParameterKeys().contains("authUsername"));
- Assert.assertTrue(error.getParameterKeys().contains("authPassword"));
- }
-}
\ No newline at end of file