You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/10/07 08:59:29 UTC
[01/14] camel git commit: CAMEL-9799: Switched to use ResourceEndpoint
Repository: camel
Updated Branches:
refs/heads/master b584b3d30 -> 732ba9d36
CAMEL-9799: Switched to use ResourceEndpoint
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/27127395
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27127395
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27127395
Branch: refs/heads/master
Commit: 2712739524cc9c263b2013fbd19a69a6404620e1
Parents: 7d85a4b
Author: Pontus Ullgren <ul...@gmail.com>
Authored: Fri Oct 6 22:28:18 2017 +0200
Committer: Pontus Ullgren <po...@redpill-linpro.com>
Committed: Fri Oct 6 22:37:42 2017 +0200
----------------------------------------------------------------------
.../src/main/docs/json-validator-component.adoc | 9 +-
.../jsonschema/DefaultJsonSchemaLoader.java | 5 +-
.../everit/jsonschema/JsonSchemaLoader.java | 20 ++-
.../everit/jsonschema/JsonSchemaReader.java | 52 -------
.../jsonschema/JsonSchemaValidatorEndpoint.java | 146 +++++++++++-------
.../jsonschema/JsonSchemaValidatorProducer.java | 56 -------
.../jsonschema/JsonValidatingProcessor.java | 152 -------------------
.../jsonschema/TestCustomSchemaLoader.java | 5 +-
.../component/everit/jsonschema/schema.json | 2 +-
.../everit/jsonschema/schemawithformat.json | 2 +-
10 files changed, 117 insertions(+), 332 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
index 7097e04..9bcca3d 100644
--- a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
+++ b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
@@ -1,9 +1,7 @@
== JSON Schema Validator Component
=== Everit Json Schema Validator Component
-*Available as of Camel version *
-
-*Available as of Camel version 2.20*
+*Available as of Camel version 2.21*
The JSON Schema Validator component performs bean validation of the message body
agains JSON Schemas using the Everit.org JSON Schema library
@@ -57,14 +55,15 @@ with the following path and query parameters:
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
-| *resourceUri* | *Required* URL to a local resource on the classpath or a reference to lookup a bean in the Registry or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against. | | String
+| *resourceUri* | *Required* Path to the resource. You can prefix with: classpath file http ref or bean. classpath file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot eg bean:myBean.myMethod. | | String
|===
-==== Query Parameters (6 parameters):
+==== Query Parameters (7 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
|===
| Name | Description | Default | Type
+| *contentCache* (producer) | Sets whether to use resource content cache or not | false | boolean
| *failOnNullBody* (producer) | Whether to fail if no body exists. | true | boolean
| *failOnNullHeader* (producer) | Whether to fail if no header exists when validating against a header. | true | boolean
| *headerName* (producer) | To validate against a header instead of the message body. | | String
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
index 8548f6e..605fcd0 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.camel.CamelContext;
-import org.apache.camel.util.ResourceHelper;
import org.everit.json.schema.Schema;
import org.everit.json.schema.loader.SchemaLoader;
import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
@@ -32,11 +31,11 @@ public class DefaultJsonSchemaLoader implements
JsonSchemaLoader {
@Override
- public Schema createSchema(CamelContext camelContext, String resourceUri) throws IOException {
+ public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
- try (InputStream inputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, resourceUri)) {
+ try (InputStream inputStream = schemaInputStream) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
return schemaLoaderBuilder.schemaJson(rawSchema).build().load().build();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
index bd7998b..4bab6a8 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
@@ -16,13 +16,29 @@
*/
package org.apache.camel.component.everit.jsonschema;
-import java.io.IOException;
+import java.io.InputStream;
import org.apache.camel.CamelContext;
+import org.everit.json.schema.FormatValidator;
import org.everit.json.schema.Schema;
+/**
+ * Can be used to create custom schema for the JSON validator endpoint.
+ * This interface is useful to add custom {@link FormatValidator} to the {@link Schema}
+ *
+ * For more information see
+ * <a href="https://github.com/everit-org/json-schema#format-validators">Format Validators</a>
+ * in the Everit JSON Schema documentation.
+ */
public interface JsonSchemaLoader {
- Schema createSchema(CamelContext camelContext, String resourceUri) throws IOException;
+ /**
+ * Create a new Schema based on the schema input stream.
+ * @param camelContext camel context
+ * @param schemaInputStream the resource input stream
+ * @return a Schema to be used when validating incoming requests
+ * @throws Exception if
+ */
+ Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
deleted file mode 100644
index 2876a07..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
+++ /dev/null
@@ -1,52 +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.everit.jsonschema;
-
-import java.io.IOException;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.util.ObjectHelper;
-import org.everit.json.schema.Schema;
-
-public class JsonSchemaReader {
- private Schema schema;
-
- private final CamelContext camelContext;
- private final String resourceUri;
- private final JsonSchemaLoader schemaLoader;
-
- public JsonSchemaReader(CamelContext camelContext, String resourceUri, JsonSchemaLoader schemaLoader) {
- ObjectHelper.notNull(camelContext, "camelContext");
- ObjectHelper.notNull(resourceUri, "resourceUri");
- ObjectHelper.notNull(schemaLoader, "schemaLoader");
-
- this.camelContext = camelContext;
- this.resourceUri = resourceUri;
- this.schemaLoader = schemaLoader;
- }
-
- public Schema getSchema() throws IOException {
- if (this.schema == null) {
- this.schema = this.schemaLoader.createSchema(this.camelContext, this.resourceUri);
- }
- return schema;
- }
-
- public void setSchema(Schema schema) {
- this.schema = schema;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
index dd05a33..80d1d32 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
@@ -16,17 +16,26 @@
*/
package org.apache.camel.component.everit.jsonschema;
+import java.io.IOException;
+import java.io.InputStream;
+
import org.apache.camel.Component;
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.api.management.ManagedOperation;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
import org.apache.camel.api.management.ManagedResource;
-import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.spi.Metadata;
+import org.apache.camel.component.ResourceEndpoint;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.IOHelper;
+import org.everit.json.schema.ObjectSchema;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.ValidationException;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
@@ -34,12 +43,10 @@ import org.apache.camel.spi.UriPath;
*/
@ManagedResource(description = "Managed JSON ValidatorEndpoint")
@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "core,validation")
-public class JsonSchemaValidatorEndpoint extends DefaultEndpoint {
+public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
- @UriPath(description = "URL to a local resource on the classpath, or a reference to lookup a bean in the Registry,"
- + " or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against.")
- @Metadata(required = "true")
- private String resourceUri;
+ private static final Logger LOG = LoggerFactory.getLogger(JsonSchemaValidatorEndpoint.class);
+
@UriParam(label = "advanced", description = "To use a custom org.apache.camel.component.everit.jsonschema.JsonValidatorErrorHandler. "
+ "The default error handler captures the errors and throws an exception.")
private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
@@ -52,68 +59,93 @@ public class JsonSchemaValidatorEndpoint extends DefaultEndpoint {
@UriParam(description = "To validate against a header instead of the message body.")
private String headerName;
-
- /**
- * We need a one-to-one relation between endpoint and a JsonSchemaReader
- * to be able to clear the cached schema. See method
- * {@link #clearCachedSchema}.
- */
- private JsonSchemaReader schemaReader;
-
+ private Schema schema;
+
public JsonSchemaValidatorEndpoint(String endpointUri, Component component, String resourceUri) {
- super(endpointUri, component);
- this.resourceUri = resourceUri;
+ super(endpointUri, component, resourceUri);
}
+ @Override
+ public void clearContentCache() {
+ this.schema = null;
+ super.clearContentCache();
+ }
- @ManagedOperation(description = "Clears the cached schema, forcing to re-load the schema on next request")
- public void clearCachedSchema() {
- this.schemaReader.setSchema(null); // will cause to reload the schema
+ @Override
+ public ExchangePattern getExchangePattern() {
+ return ExchangePattern.InOut;
}
@Override
- public Producer createProducer() throws Exception {
- if (this.schemaReader == null) {
- this.schemaReader = new JsonSchemaReader(getCamelContext(), resourceUri, schemaLoader);
- // Load the schema once when creating the producer to fail fast if the schema is invalid.
- this.schemaReader.getSchema();
+ protected void onExchange(Exchange exchange) throws Exception {
+ Object jsonPayload = null;
+ InputStream is = null;
+ // Get a local copy of the current schema to improve concurrency.
+ Schema localSchema = this.schema;
+ if (localSchema == null) {
+ localSchema = getOrCreateSchema();
+ }
+ try {
+ is = getContentToValidate(exchange, InputStream.class);
+ if (shouldUseHeader()) {
+ if (is == null && isFailOnNullHeader()) {
+ throw new NoJsonHeaderValidationException(exchange, headerName);
+ }
+ } else {
+ if (is == null && isFailOnNullBody()) {
+ throw new NoJsonBodyValidationException(exchange);
+ }
+ }
+ if (is != null) {
+ if (schema instanceof ObjectSchema) {
+ jsonPayload = new JSONObject(new JSONTokener(is));
+ } else {
+ jsonPayload = new JSONArray(new JSONTokener(is));
+ }
+ // throws a ValidationException if this object is invalid
+ schema.validate(jsonPayload);
+ LOG.debug("JSON is valid");
+ }
+ } catch (ValidationException e) {
+ this.errorHandler.handleErrors(exchange, schema, e);
+ } catch (JSONException e) {
+ this.errorHandler.handleErrors(exchange, schema, e);
+ } finally {
+ IOHelper.close(is);
}
- JsonValidatingProcessor validator = new JsonValidatingProcessor(this.schemaReader);
- configureValidator(validator);
-
- return new JsonSchemaValidatorProducer(this, validator);
- }
-
- private void configureValidator(JsonValidatingProcessor validator) {
- validator.setErrorHandler(errorHandler);
- validator.setFailOnNullBody(failOnNullBody);
- validator.setFailOnNullHeader(failOnNullHeader);
- validator.setHeaderName(headerName);
}
-
- @Override
- public Consumer createConsumer(Processor processor) throws Exception {
- throw new UnsupportedOperationException("Cannot consume from validator");
+
+ private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
+ if (shouldUseHeader()) {
+ return exchange.getIn().getHeader(headerName, clazz);
+ } else {
+ return exchange.getIn().getBody(clazz);
+ }
}
- @Override
- public boolean isSingleton() {
- return true;
+ private boolean shouldUseHeader() {
+ return headerName != null;
}
-
- public String getResourceUri() {
- return resourceUri;
- }
-
/**
- * URL to a local resource on the classpath, or a reference to lookup a bean in the Registry,
- * or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against.
+ * Synchronized method to create a schema if is does not already exist.
+ *
+ * @return The currently loaded schema
+ * @throws IOException
*/
- public void setResourceUri(String resourceUri) {
- this.resourceUri = resourceUri;
+ private Schema getOrCreateSchema() throws Exception {
+ synchronized (this) {
+ if (this.schema == null) {
+ this.schema = this.schemaLoader.createSchema(getCamelContext(), this.getResourceAsInputStream());
+ }
+ }
+ return this.schema;
}
+ @Override
+ protected String createEndpointUri() {
+ return "json-validator:" + getResourceUri();
+ }
public JsonValidatorErrorHandler getErrorHandler() {
return errorHandler;
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java
deleted file mode 100644
index b7efbee..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java
+++ /dev/null
@@ -1,56 +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.everit.jsonschema;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.impl.DefaultAsyncProducer;
-import org.apache.camel.util.ServiceHelper;
-
-public class JsonSchemaValidatorProducer extends DefaultAsyncProducer {
-
- private final JsonValidatingProcessor validatingProcessor;
-
- public JsonSchemaValidatorProducer(Endpoint endpoint, JsonValidatingProcessor validatingProcessor) {
- super(endpoint);
- this.validatingProcessor = validatingProcessor;
- }
-
- @Override
- public boolean process(Exchange exchange, AsyncCallback callback) {
- return validatingProcessor.process(exchange, callback);
- }
-
- @Override
- protected void doStart() throws Exception {
- super.doStart();
- ServiceHelper.startService(validatingProcessor);
- }
-
- @Override
- protected void doStop() throws Exception {
- super.doStop();
- ServiceHelper.stopService(validatingProcessor);
- }
-
- @Override
- protected void doShutdown() throws Exception {
- super.doStop();
- ServiceHelper.stopAndShutdownService(validatingProcessor);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
deleted file mode 100644
index 68cffaf..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
+++ /dev/null
@@ -1,152 +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.everit.jsonschema;
-
-import java.io.InputStream;
-
-import org.apache.camel.AsyncCallback;
-import org.apache.camel.AsyncProcessor;
-import org.apache.camel.Exchange;
-import org.apache.camel.util.AsyncProcessorHelper;
-import org.apache.camel.util.IOHelper;
-import org.everit.json.schema.ObjectSchema;
-import org.everit.json.schema.Schema;
-import org.everit.json.schema.ValidationException;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A processor which validates the JSON of the inbound message body
- * against some JSON schema
- */
-public class JsonValidatingProcessor implements AsyncProcessor {
- private static final Logger LOG = LoggerFactory.getLogger(JsonValidatingProcessor.class);
- private JsonSchemaReader schemaReader;
- private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
- private boolean failOnNullBody = true;
- private boolean failOnNullHeader = true;
- private String headerName;
-
- public JsonValidatingProcessor() {
-
- }
-
- public JsonValidatingProcessor(JsonSchemaReader schemaReader) {
- this.schemaReader = schemaReader;
- }
-
- public void process(Exchange exchange) throws Exception {
- AsyncProcessorHelper.process(this, exchange);
- }
-
- public boolean process(Exchange exchange, AsyncCallback callback) {
- try {
- doProcess(exchange);
- } catch (Exception e) {
- exchange.setException(e);
- }
- callback.done(true);
- return true;
- }
-
- protected void doProcess(Exchange exchange) throws Exception {
- Object jsonPayload = null;
- InputStream is = null;
- Schema schema = null;
- try {
- is = getContentToValidate(exchange, InputStream.class);
- if (shouldUseHeader()) {
- if (is == null && isFailOnNullHeader()) {
- throw new NoJsonHeaderValidationException(exchange, headerName);
- }
- } else {
- if (is == null && isFailOnNullBody()) {
- throw new NoJsonBodyValidationException(exchange);
- }
- }
- if (is != null) {
- schema = this.schemaReader.getSchema();
- if (schema instanceof ObjectSchema) {
- jsonPayload = new JSONObject(new JSONTokener(is));
- } else {
- jsonPayload = new JSONArray(new JSONTokener(is));
- }
- // throws a ValidationException if this object is invalid
- schema.validate(jsonPayload);
- LOG.debug("JSON is valid");
- }
- } catch (ValidationException e) {
- this.errorHandler.handleErrors(exchange, schema, e);
- } catch (JSONException e) {
- this.errorHandler.handleErrors(exchange, schema, e);
- } finally {
- IOHelper.close(is);
- }
- }
-
- private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
- if (shouldUseHeader()) {
- return exchange.getIn().getHeader(headerName, clazz);
- } else {
- return exchange.getIn().getBody(clazz);
- }
- }
-
- private boolean shouldUseHeader() {
- return headerName != null;
- }
-
- // Properties
- // -----------------------------------------------------------------------
-
-
- public JsonValidatorErrorHandler getErrorHandler() {
- return errorHandler;
- }
-
- public void setErrorHandler(JsonValidatorErrorHandler errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- public boolean isFailOnNullBody() {
- return failOnNullBody;
- }
-
- public void setFailOnNullBody(boolean failOnNullBody) {
- this.failOnNullBody = failOnNullBody;
- }
-
- public boolean isFailOnNullHeader() {
- return failOnNullHeader;
- }
-
- public void setFailOnNullHeader(boolean failOnNullHeader) {
- this.failOnNullHeader = failOnNullHeader;
- }
-
- public String getHeaderName() {
- return headerName;
- }
-
- public void setHeaderName(String headerName) {
- this.headerName = headerName;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
index 7902fc3..1bd9260 100644
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
@@ -4,7 +4,6 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.camel.CamelContext;
-import org.apache.camel.util.ResourceHelper;
import org.everit.json.schema.Schema;
import org.everit.json.schema.loader.SchemaLoader;
import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
@@ -14,12 +13,12 @@ import org.json.JSONTokener;
public class TestCustomSchemaLoader implements JsonSchemaLoader {
@Override
- public Schema createSchema(CamelContext camelContext, String resourceUri)
+ public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream)
throws IOException {
SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
- try (InputStream inputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, resourceUri)) {
+ try (InputStream inputStream = schemaInputStream) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
return schemaLoaderBuilder
.schemaJson(rawSchema)
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
index 6fa28c3..021640d 100644
--- a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
+++ b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
@@ -1,5 +1,5 @@
{
- "$schema": "http://json-schema.org/draft-04/schema#",
+ "$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
http://git-wip-us.apache.org/repos/asf/camel/blob/27127395/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
index 17ba7ad..a365115 100644
--- a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
+++ b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
@@ -1,5 +1,5 @@
{
- "$schema": "http://json-schema.org/draft-04/schema#",
+ "$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
[09/14] camel git commit: CAMEL-9799: Rename component to
json-validator so it has a better name
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
deleted file mode 100644
index 7c0ca28..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
+++ /dev/null
@@ -1,49 +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.everit.jsonschema.springboot;
-
-import javax.annotation.Generated;
-import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * Validates the payload of a message using XML Schema and JAXP Validation.
- *
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
-@ConfigurationProperties(prefix = "camel.component.json-validator")
-public class JsonSchemaValidatorComponentConfiguration
- extends
- ComponentConfigurationPropertiesCommon {
-
- /**
- * Whether the component should resolve property placeholders on itself when
- * starting. Only properties which are of String type can use property
- * placeholders.
- */
- private Boolean resolvePropertyPlaceholders = true;
-
- public Boolean getResolvePropertyPlaceholders() {
- return resolvePropertyPlaceholders;
- }
-
- public void setResolvePropertyPlaceholders(
- Boolean resolvePropertyPlaceholders) {
- this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt
deleted file mode 100644
index 6b0b127..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt
+++ /dev/null
@@ -1,203 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
-
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt
deleted file mode 100644
index 2e215bf..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt
+++ /dev/null
@@ -1,11 +0,0 @@
- =========================================================================
- == NOTICE file corresponding to the section 4 d of ==
- == the Apache License, Version 2.0, ==
- == in this case for the Apache Camel distribution. ==
- =========================================================================
-
- This product includes software developed by
- The Apache Software Foundation (http://www.apache.org/).
-
- Please read the different LICENSE files present in the licenses directory of
- this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 854708c..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,19 +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.
-## ---------------------------------------------------------------------------
-
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.everit.jsonschema.springboot.JsonSchemaValidatorComponentAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides
deleted file mode 100644
index 5a9ab4d..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides
+++ /dev/null
@@ -1,17 +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.
-## ---------------------------------------------------------------------------
-provides: camel-everit-json-schema
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml b/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
new file mode 100644
index 0000000..83d6fb2
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components-starter</artifactId>
+ <version>2.20.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>camel-json-validator-starter</artifactId>
+ <packaging>jar</packaging>
+ <name>Spring-Boot Starter :: Camel :: Everit Kft. JSON Schema validator</name>
+ <description>Spring-Boot Starter for Camel JSON Schema validation based on everit-org json-schema library</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator</artifactId>
+ <version>${project.version}</version>
+ <!--START OF GENERATED CODE-->
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ <!--END OF GENERATED CODE-->
+ </dependency>
+ <!--START OF GENERATED CODE-->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <!--END OF GENERATED CODE-->
+ </dependencies>
+ <!--START OF GENERATED CODE-->
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ </repositories>
+ <!--END OF GENERATED CODE-->
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
new file mode 100644
index 0000000..7d2decc
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
@@ -0,0 +1,129 @@
+/**
+ * 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.everit.jsonschema.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.everit.jsonschema.JsonSchemaValidatorComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ JsonSchemaValidatorComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ JsonSchemaValidatorComponentConfiguration.class})
+public class JsonSchemaValidatorComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(JsonSchemaValidatorComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private JsonSchemaValidatorComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<JsonSchemaValidatorComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.json-validator");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "json-validator-component")
+ @ConditionalOnMissingBean(JsonSchemaValidatorComponent.class)
+ public JsonSchemaValidatorComponent configureJsonSchemaValidatorComponent()
+ throws Exception {
+ JsonSchemaValidatorComponent component = new JsonSchemaValidatorComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<JsonSchemaValidatorComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.json-validator.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.json-validator.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
new file mode 100644
index 0000000..7c0ca28
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.everit.jsonschema.springboot;
+
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Validates the payload of a message using XML Schema and JAXP Validation.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.json-validator")
+public class JsonSchemaValidatorComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java
new file mode 100644
index 0000000..e117da6
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentAutoConfiguration.java
@@ -0,0 +1,129 @@
+/**
+ * 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.jsonvalidator.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.jsonvalidator.JsonValidatorComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ JsonValidatorComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ JsonValidatorComponentConfiguration.class})
+public class JsonValidatorComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(JsonValidatorComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private JsonValidatorComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<JsonValidatorComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.json-validator");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "json-validator-component")
+ @ConditionalOnMissingBean(JsonValidatorComponent.class)
+ public JsonValidatorComponent configureJsonValidatorComponent()
+ throws Exception {
+ JsonValidatorComponent component = new JsonValidatorComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<JsonValidatorComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.json-validator.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.json-validator.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java
new file mode 100644
index 0000000..6a65e34
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/jsonvalidator/springboot/JsonValidatorComponentConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.jsonvalidator.springboot;
+
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Validates the payload of a message using Everit JSON schema validator.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.json-validator")
+public class JsonValidatorComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/LICENSE.txt b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/NOTICE.txt b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..89e1ba4
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,21 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.everit.jsonschema.springboot.JsonSchemaValidatorComponentAutoConfiguration,\
+org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentAutoConfiguration
+
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.provides
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.provides b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.provides
new file mode 100644
index 0000000..dad71f4
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.provides
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+provides: camel-json-validator
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/pom.xml b/platforms/spring-boot/components-starter/pom.xml
index 5769215..e73552e 100644
--- a/platforms/spring-boot/components-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/pom.xml
@@ -132,7 +132,6 @@
<module>camel-elasticsearch5-starter</module>
<module>camel-elsql-starter</module>
<module>camel-etcd-starter</module>
- <module>camel-everit-json-schema-starter</module>
<module>camel-exec-starter</module>
<module>camel-facebook-starter</module>
<module>camel-fastjson-starter</module>
@@ -200,6 +199,7 @@
<module>camel-josql-starter</module>
<module>camel-jpa-starter</module>
<module>camel-jsch-starter</module>
+ <module>camel-json-validator-starter</module>
<module>camel-jsonpath-starter</module>
<module>camel-jt400-starter</module>
<module>camel-juel-starter</module>
[02/14] camel git commit: Fixed source check errors in
camel-everit-json-schema component
Posted by da...@apache.org.
Fixed source check errors in camel-everit-json-schema component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7d85a4b7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7d85a4b7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7d85a4b7
Branch: refs/heads/master
Commit: 7d85a4b7d710f3f6b4433b92a834f624a0bf23f3
Parents: 923f126
Author: Pontus Ullgren <ul...@gmail.com>
Authored: Wed Oct 4 02:03:19 2017 +0200
Committer: Pontus Ullgren <po...@redpill-linpro.com>
Committed: Fri Oct 6 22:37:42 2017 +0200
----------------------------------------------------------------------
.../everit/jsonschema/JsonSchemaReader.java | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7d85a4b7/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
index 1f76f67..2876a07 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
@@ -1,3 +1,19 @@
+/**
+ * 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.everit.jsonschema;
import java.io.IOException;
@@ -24,7 +40,7 @@ public class JsonSchemaReader {
}
public Schema getSchema() throws IOException {
- if ( this.schema == null ) {
+ if (this.schema == null) {
this.schema = this.schemaLoader.createSchema(this.camelContext, this.resourceUri);
}
return schema;
[05/14] camel git commit: Initial version of camel-everit-json-schema
component
Posted by da...@apache.org.
Initial version of camel-everit-json-schema component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8ba38cf8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8ba38cf8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8ba38cf8
Branch: refs/heads/master
Commit: 8ba38cf8d301ff552bf4780df207ad3bd6d42444
Parents: b584b3d
Author: Pontus Ullgren <ul...@gmail.com>
Authored: Fri Sep 29 22:59:48 2017 +0200
Committer: Pontus Ullgren <po...@redpill-linpro.com>
Committed: Fri Oct 6 22:37:42 2017 +0200
----------------------------------------------------------------------
.../src/main/descriptors/common-bin.xml | 2 +
components/camel-everit-json-schema/pom.xml | 89 ++++++++
.../src/main/docs/json-validator-component.adoc | 136 +++++++++++++
.../DefaultJsonValidationErrorHandler.java | 42 ++++
.../JsonSchemaValidationException.java | 41 ++++
.../JsonSchemaValidatorComponent.java | 46 +++++
.../jsonschema/JsonSchemaValidatorEndpoint.java | 176 ++++++++++++++++
.../jsonschema/JsonSchemaValidatorProducer.java | 56 +++++
.../jsonschema/JsonValidatingProcessor.java | 150 ++++++++++++++
.../jsonschema/JsonValidatorErrorHandler.java | 38 ++++
.../NoJsonBodyValidationException.java | 37 ++++
.../NoJsonHeaderValidationException.java | 38 ++++
.../component/everit/jsonschema/package.html | 25 +++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../org/apache/camel/component/json-validator | 18 ++
.../jsonschema/FileValidatorRouteTest.java | 97 +++++++++
.../everit/jsonschema/ValidatorRouteTest.java | 174 ++++++++++++++++
.../src/test/resources/log4j2.properties | 31 +++
.../component/everit/jsonschema/schema.json | 34 ++++
components/pom.xml | 1 +
parent/pom.xml | 8 +
.../camel-everit-json-schema-starter/pom.xml | 69 +++++++
...hemaValidatorComponentAutoConfiguration.java | 129 ++++++++++++
...onSchemaValidatorComponentConfiguration.java | 49 +++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../main/resources/META-INF/spring.factories | 19 ++
.../src/main/resources/META-INF/spring.provides | 17 ++
.../spring-boot/components-starter/pom.xml | 1 +
30 files changed, 1951 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 59d5c5e..64c2c2a 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -88,6 +88,7 @@
<include>org.apache.camel:camel-elsql</include>
<include>org.apache.camel:camel-etcd</include>
<include>org.apache.camel:camel-eventadmin</include>
+ <include>org.apache.camel:camel-everit-json-schema</include>
<include>org.apache.camel:camel-exec</include>
<include>org.apache.camel:camel-facebook</include>
<include>org.apache.camel:camel-fastjson</include>
@@ -383,6 +384,7 @@
<include>org.apache.camel:camel-elasticsearch5-starter</include>
<include>org.apache.camel:camel-elsql-starter</include>
<include>org.apache.camel:camel-etcd-starter</include>
+ <include>org.apache.camel:camel-everit-json-schema-starter</include>
<include>org.apache.camel:camel-exec-starter</include>
<include>org.apache.camel:camel-facebook-starter</include>
<include>org.apache.camel:camel-fastjson-starter</include>
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/pom.xml b/components/camel-everit-json-schema/pom.xml
new file mode 100644
index 0000000..9d7938d
--- /dev/null
+++ b/components/camel-everit-json-schema/pom.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.20.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-everit-json-schema</artifactId>
+ <name>Camel :: Everit Kft. JSON Schema validator</name>
+ <description>Camel JSON Schema validation based on everit-org json-schema library</description>
+ <packaging>jar</packaging>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.everit.jsonschema.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=json-validator</camel.osgi.export.service>
+ </properties>
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ </repositories>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.github.everit-org.json-schema</groupId>
+ <artifactId>org.everit.json.schema</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
new file mode 100644
index 0000000..2f10a7b
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
@@ -0,0 +1,136 @@
+== JSON Schema Validator Component
+=== Everit Json Schema Validator Component
+
+*Available as of Camel version 2.20*
+
+The Validator component performs bean validation of the message body
+agains JSON Schemas using the Everit.org JSON Schema library
+(https://github.com/everit-org/json-schema).
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema</artifactId>
+ <version>x.y.z</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+
+=== URI format
+
+[source,java]
+------------------------------
+json-validator:resourceUri[?options]
+------------------------------
+
+
+Where *label* is an arbitrary text value describing the endpoint. +
+ You can append query options to the URI in the following format,
+?option=value&option=value&...
+
+=== URI Options
+
+
+// component options: START
+The JSON Schema Validator component has no options.
+// component options: END
+
+
+
+// endpoint options: START
+The JSON Schema Validator endpoint is configured using URI syntax:
+
+----
+json-validator:resourceUri
+----
+
+with the following path and query parameters:
+
+==== Path Parameters (1 parameters):
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *resourceUri* | *Required* URL to a local resource on the classpath or a reference to lookup a bean in the Registry or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against. | | String
+|===
+
+==== Query Parameters (5 parameters):
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *failOnNullBody* (producer) | Whether to fail if no body exists. | true | boolean
+| *failOnNullHeader* (producer) | Whether to fail if no header exists when validating against a header. | true | boolean
+| *headerName* (producer) | To validate against a header instead of the message body. | | String
+| *errorHandler* (advanced) | To use a custom org.apache.camel.processor.validation.ValidatorErrorHandler. The default error handler captures the errors and throws an exception. | | JsonValidatorError Handler
+| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+|===
+// endpoint options: END
+
+
+=== Example
+
+Assumed we have the following JSON Schema
+
+*schema.json*
+
+[source,json]
+-----------------------------------------------------------
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "definitions": {},
+ "id": "http://example.com/example.json",
+ "properties": {
+ "id": {
+ "default": 1,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/id",
+ "title": "The id schema",
+ "type": "integer"
+ },
+ "name": {
+ "default": "A green door",
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/name",
+ "title": "The name schema",
+ "type": "string"
+ },
+ "price": {
+ "default": 12.5,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/price",
+ "title": "The price schema",
+ "type": "number"
+ }
+ },
+ "required": [
+ "name",
+ "id",
+ "price"
+ ],
+ "type": "object"
+}
+-----------------------------------------------------------
+
+we can validate incomming JSON with the following Camel route.
+
+[source,java]
+-------------------------
+from("direct:start")
+ .to("json-validator:schema.json")
+ .to("mock:end")
+-------------------------
+
+--------------------------------------------------------------------------------------------------
+
+=== See Also
+
+* link:configuring-camel.html[Configuring Camel]
+* link:component.html[Component]
+* link:endpoint.html[Endpoint]
+* link:getting-started.html[Getting Started]
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
new file mode 100644
index 0000000..b6ef7c2
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
@@ -0,0 +1,42 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+public class DefaultJsonValidationErrorHandler implements
+ JsonValidatorErrorHandler {
+
+ @Override
+ public void reset() {
+ // Do nothing since we do not keep state
+ }
+
+ @Override
+ public void handleErrors(Exchange exchange,
+ org.everit.json.schema.Schema schema,
+ Exception e)
+ throws ValidationException {
+ if (e instanceof org.everit.json.schema.ValidationException) {
+ throw new JsonSchemaValidationException(exchange, schema, (org.everit.json.schema.ValidationException)e);
+ } else {
+ throw new JsonSchemaValidationException(exchange, schema, e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
new file mode 100644
index 0000000..ade36d5
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
@@ -0,0 +1,41 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.util.stream.Collectors;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+import org.everit.json.schema.Schema;
+
+public class JsonSchemaValidationException extends ValidationException {
+
+ private static final long serialVersionUID = 1L;
+
+ public JsonSchemaValidationException(Exchange exchange, Schema schema,
+ org.everit.json.schema.ValidationException e) {
+ super(e.getAllMessages().stream().collect(Collectors.joining(", ")),
+ exchange,
+ e
+ );
+ }
+
+ public JsonSchemaValidationException(Exchange exchange, Schema schema,
+ Exception e) {
+ super(e.getMessage(), exchange, e);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
new file mode 100644
index 0000000..61cdd05
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
@@ -0,0 +1,46 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+
+/**
+ * The JSON Schema Validator Component is for validating JSON against a schema.
+ *
+ * @version
+ */
+public class JsonSchemaValidatorComponent extends UriEndpointComponent {
+
+ public JsonSchemaValidatorComponent() {
+ this(JsonSchemaValidatorEndpoint.class);
+ }
+
+ public JsonSchemaValidatorComponent(Class<? extends Endpoint> endpointClass) {
+ super(endpointClass);
+ }
+
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ JsonSchemaValidatorEndpoint endpoint = new JsonSchemaValidatorEndpoint(uri, this, remaining);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
new file mode 100644
index 0000000..ea0db62
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
@@ -0,0 +1,176 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.api.management.ManagedOperation;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.spi.UriPath;
+import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ResourceHelper;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.loader.SchemaLoader;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+
+/**
+ * Validates the payload of a message using XML Schema and JAXP Validation.
+ */
+@ManagedResource(description = "Managed JSON ValidatorEndpoint")
+@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "core,validation")
+public class JsonSchemaValidatorEndpoint extends DefaultEndpoint {
+
+ @UriPath(description = "URL to a local resource on the classpath, or a reference to lookup a bean in the Registry,"
+ + " or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against.")
+ @Metadata(required = "true")
+ private String resourceUri;
+ @UriParam(label = "advanced", description = "To use a custom org.apache.camel.component.everit.jsonschema.JsonValidatorErrorHandler. "
+ + "The default error handler captures the errors and throws an exception.")
+ private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
+ @UriParam(defaultValue = "true", description = "Whether to fail if no body exists.")
+ private boolean failOnNullBody = true;
+ @UriParam(defaultValue = "true", description = "Whether to fail if no header exists when validating against a header.")
+ private boolean failOnNullHeader = true;
+ @UriParam(description = "To validate against a header instead of the message body.")
+ private String headerName;
+
+ /**
+ * We need a one-to-one relation between endpoint and a Schema
+ * to be able to clear the cached schema. See method
+ * {@link #clearCachedSchema}.
+ */
+ private Schema schema;
+
+ public JsonSchemaValidatorEndpoint(String endpointUri, Component component, String resourceUri) {
+ super(endpointUri, component);
+ this.resourceUri = resourceUri;
+ }
+
+ private Schema loadSchema() throws IOException {
+ ObjectHelper.notNull(getCamelContext(), "camelContext");
+ ObjectHelper.notNull(this.resourceUri, "resourceUri");
+ try (InputStream inputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), this.resourceUri)) {
+ JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
+ // LOG.debug("JSON schema: {}", rawSchema);
+ return SchemaLoader.load(rawSchema);
+ }
+ }
+
+ @ManagedOperation(description = "Clears the cached schema, forcing to re-load the schema on next request")
+ public void clearCachedSchema() {
+ this.schema = null; // will cause to reload the schema
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ if (this.schema == null) {
+ this.schema = loadSchema();
+ }
+ JsonValidatingProcessor validator = new JsonValidatingProcessor(this.schema);
+ configureValidator(validator);
+
+ return new JsonSchemaValidatorProducer(this, validator);
+ }
+
+ private void configureValidator(JsonValidatingProcessor validator) {
+ validator.setErrorHandler(errorHandler);
+ validator.setFailOnNullBody(failOnNullBody);
+ validator.setFailOnNullHeader(failOnNullHeader);
+ validator.setHeaderName(headerName);
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ throw new UnsupportedOperationException("Cannot consume from validator");
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+
+ public String getResourceUri() {
+ return resourceUri;
+ }
+
+ /**
+ * URL to a local resource on the classpath, or a reference to lookup a bean in the Registry,
+ * or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against.
+ */
+ public void setResourceUri(String resourceUri) {
+ this.resourceUri = resourceUri;
+ }
+
+
+ public JsonValidatorErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
+ /**
+ * To use a custom org.apache.camel.processor.validation.ValidatorErrorHandler.
+ * <p/>
+ * The default error handler captures the errors and throws an exception.
+ */
+ public void setErrorHandler(JsonValidatorErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ public boolean isFailOnNullBody() {
+ return failOnNullBody;
+ }
+
+ /**
+ * Whether to fail if no body exists.
+ */
+ public void setFailOnNullBody(boolean failOnNullBody) {
+ this.failOnNullBody = failOnNullBody;
+ }
+
+ public boolean isFailOnNullHeader() {
+ return failOnNullHeader;
+ }
+
+ /**
+ * Whether to fail if no header exists when validating against a header.
+ */
+ public void setFailOnNullHeader(boolean failOnNullHeader) {
+ this.failOnNullHeader = failOnNullHeader;
+ }
+
+ public String getHeaderName() {
+ return headerName;
+ }
+
+ /**
+ * To validate against a header instead of the message body.
+ */
+ public void setHeaderName(String headerName) {
+ this.headerName = headerName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java
new file mode 100644
index 0000000..b7efbee
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorProducer.java
@@ -0,0 +1,56 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultAsyncProducer;
+import org.apache.camel.util.ServiceHelper;
+
+public class JsonSchemaValidatorProducer extends DefaultAsyncProducer {
+
+ private final JsonValidatingProcessor validatingProcessor;
+
+ public JsonSchemaValidatorProducer(Endpoint endpoint, JsonValidatingProcessor validatingProcessor) {
+ super(endpoint);
+ this.validatingProcessor = validatingProcessor;
+ }
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ return validatingProcessor.process(exchange, callback);
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ ServiceHelper.startService(validatingProcessor);
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+ ServiceHelper.stopService(validatingProcessor);
+ }
+
+ @Override
+ protected void doShutdown() throws Exception {
+ super.doStop();
+ ServiceHelper.stopAndShutdownService(validatingProcessor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
new file mode 100644
index 0000000..7b5fb68
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
@@ -0,0 +1,150 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.io.InputStream;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.AsyncProcessor;
+import org.apache.camel.Exchange;
+import org.apache.camel.util.AsyncProcessorHelper;
+import org.apache.camel.util.IOHelper;
+import org.everit.json.schema.ObjectSchema;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.ValidationException;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A processor which validates the JSON of the inbound message body
+ * against some JSON schema
+ */
+public class JsonValidatingProcessor implements AsyncProcessor {
+ private static final Logger LOG = LoggerFactory.getLogger(JsonValidatingProcessor.class);
+ private Schema schema;
+ private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
+ private boolean failOnNullBody = true;
+ private boolean failOnNullHeader = true;
+ private String headerName;
+
+ public JsonValidatingProcessor() {
+
+ }
+
+ public JsonValidatingProcessor(Schema schema) {
+ this.schema = schema;
+ }
+
+ public void process(Exchange exchange) throws Exception {
+ AsyncProcessorHelper.process(this, exchange);
+ }
+
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ try {
+ doProcess(exchange);
+ } catch (Exception e) {
+ exchange.setException(e);
+ }
+ callback.done(true);
+ return true;
+ }
+
+ protected void doProcess(Exchange exchange) throws Exception {
+ Object jsonPayload = null;
+ InputStream is = null;
+ try {
+ is = getContentToValidate(exchange, InputStream.class);
+ if (shouldUseHeader()) {
+ if (is == null && isFailOnNullHeader()) {
+ throw new NoJsonHeaderValidationException(exchange, headerName);
+ }
+ } else {
+ if (is == null && isFailOnNullBody()) {
+ throw new NoJsonBodyValidationException(exchange);
+ }
+ }
+ if (is != null) {
+ if (schema instanceof ObjectSchema) {
+ jsonPayload = new JSONObject(new JSONTokener(is));
+ } else {
+ jsonPayload = new JSONArray(new JSONTokener(is));
+ }
+ // throws a ValidationException if this object is invalid
+ schema.validate(jsonPayload);
+ LOG.debug("JSON is valid");
+ }
+ } catch (ValidationException e) {
+ this.errorHandler.handleErrors(exchange, schema, e);
+ } catch (JSONException e) {
+ this.errorHandler.handleErrors(exchange, schema, e);
+ } finally {
+ IOHelper.close(is);
+ }
+ }
+
+ private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
+ if (shouldUseHeader()) {
+ return exchange.getIn().getHeader(headerName, clazz);
+ } else {
+ return exchange.getIn().getBody(clazz);
+ }
+ }
+
+ private boolean shouldUseHeader() {
+ return headerName != null;
+ }
+
+ // Properties
+ // -----------------------------------------------------------------------
+
+
+ public JsonValidatorErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
+ public void setErrorHandler(JsonValidatorErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ public boolean isFailOnNullBody() {
+ return failOnNullBody;
+ }
+
+ public void setFailOnNullBody(boolean failOnNullBody) {
+ this.failOnNullBody = failOnNullBody;
+ }
+
+ public boolean isFailOnNullHeader() {
+ return failOnNullHeader;
+ }
+
+ public void setFailOnNullHeader(boolean failOnNullHeader) {
+ this.failOnNullHeader = failOnNullHeader;
+ }
+
+ public String getHeaderName() {
+ return headerName;
+ }
+
+ public void setHeaderName(String headerName) {
+ this.headerName = headerName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
new file mode 100644
index 0000000..4594e97
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
@@ -0,0 +1,38 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+public interface JsonValidatorErrorHandler {
+ /**
+ * Resets any state within this error handler
+ */
+ void reset();
+
+ /**
+ * Process any errors which may have occurred during validation
+ *
+ * @param exchange the exchange
+ * @param schema the schema
+ * @param e the exception triggering the error
+ * @throws ValidationException is thrown in case of validation errors
+ */
+ void handleErrors(Exchange exchange, org.everit.json.schema.Schema schema, Exception e) throws ValidationException;
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
new file mode 100644
index 0000000..3000579
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
@@ -0,0 +1,37 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+/**
+ * An exception found if no JSON body is available on the inbound message
+ *
+ * @version
+ */
+public class NoJsonBodyValidationException extends ValidationException {
+ private static final long serialVersionUID = 4502520681354358599L;
+
+ public NoJsonBodyValidationException(Exchange exchange) {
+ super(exchange, "No JSON body could be found on the input message");
+ }
+
+ public NoJsonBodyValidationException(Exchange exchange, Throwable cause) {
+ super("No JSON body could be found on the input message", exchange, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
new file mode 100644
index 0000000..582a685
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
@@ -0,0 +1,38 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+/**
+ * An exception found if no JSON body is available on the inbound message
+ *
+ * @version
+ */
+public class NoJsonHeaderValidationException extends ValidationException {
+ private static final long serialVersionUID = 4502520681354358599L;
+
+ public NoJsonHeaderValidationException(Exchange exchange, String header) {
+ this(exchange, header, null);
+ }
+
+ public NoJsonHeaderValidationException(Exchange exchange, String header, Throwable cause) {
+ super("No JSON header \"" + header + "\" could be found on the input message", exchange, cause);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
new file mode 100644
index 0000000..64cf1d8
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
@@ -0,0 +1,25 @@
+<!--
+ 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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+The <a href="http://activemq.apache.org/camel/validator.html">Validator Component</a> for validating XML against some schema
+
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt b/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt
new file mode 100755
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt b/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator b/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
new file mode 100644
index 0000000..447b785
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.everit.jsonschema.JsonSchemaValidatorComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
new file mode 100644
index 0000000..2979326
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
@@ -0,0 +1,97 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.FileUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class FileValidatorRouteTest extends CamelTestSupport {
+
+ protected MockEndpoint validEndpoint;
+ protected MockEndpoint finallyEndpoint;
+ protected MockEndpoint invalidEndpoint;
+
+ @Test
+ public void testValidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ invalidEndpoint.expectedMessageCount(0);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file:target/validator",
+ "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }",
+ Exchange.FILE_NAME, "valid.json");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+
+ assertTrue("Should be able to delete the file", FileUtil.deleteFile(new File("target/validator/valid.json")));
+ }
+
+ @Test
+ public void testInvalidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(0);
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file:target/validator",
+ "{ \"name\": \"Joe Doe\", \"id\": \"AA1\", \"price\": 12.5 }",
+ Exchange.FILE_NAME, "invalid.json");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+
+ // should be able to delete the file
+ assertTrue("Should be able to delete the file", FileUtil.deleteFile(new File("target/validator/invalid.json")));
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ deleteDirectory("target/validator");
+ super.setUp();
+ validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class);
+ invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
+ finallyEndpoint = resolveMandatoryEndpoint("mock:finally", MockEndpoint.class);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/validator?noop=true")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java
new file mode 100644
index 0000000..fb41490
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java
@@ -0,0 +1,174 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ValidatorRouteTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:valid")
+ protected MockEndpoint validEndpoint;
+
+ @EndpointInject(uri = "mock:finally")
+ protected MockEndpoint finallyEndpoint;
+
+ @EndpointInject(uri = "mock:invalid")
+ protected MockEndpoint invalidEndpoint;
+
+ @Test
+ public void testValidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testValidMessageInHeader() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startHeaders",
+ null,
+ "headerToValidate",
+ "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidMessage() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidMessageInHeader() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startHeaders",
+ null,
+ "headerToValidate",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testNullHeaderNoFail() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startNullHeaderNoFail", null, "headerToValidate", null);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint);
+ }
+
+ @Test
+ public void testNullHeader() throws Exception {
+ validEndpoint.setExpectedMessageCount(0);
+
+ Exchange in = resolveMandatoryEndpoint("direct:startNoHeaderException").createExchange(ExchangePattern.InOut);
+
+ in.getIn().setBody(null);
+ in.getIn().setHeader("headerToValidate", null);
+
+ Exchange out = template.send("direct:startNoHeaderException", in);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+
+ Exception exception = out.getException();
+ assertTrue("Should be failed", out.isFailed());
+ assertTrue("Exception should be correct type", exception instanceof NoJsonHeaderValidationException);
+ assertTrue("Exception should mention missing header", exception.getMessage().contains("headerToValidate"));
+ }
+
+ @Test
+ public void testInvalideBytesMessage() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }".getBytes());
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidBytesMessageInHeader() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startHeaders",
+ null,
+ "headerToValidate",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }".getBytes());
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+
+ from("direct:startHeaders")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json?headerName=headerToValidate")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+
+ from("direct:startNoHeaderException")
+ .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json?headerName=headerToValidate")
+ .to("mock:valid");
+
+ from("direct:startNullHeaderNoFail")
+ .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json?headerName=headerToValidate&failOnNullHeader=false")
+ .to("mock:valid");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/log4j2.properties b/components/camel-everit-json-schema/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..9374f09
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/resources/log4j2.properties
@@ -0,0 +1,31 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-json-validator-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d %-5p %c{1} - %m %n
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+logger.springframework.name = org.springframework
+logger.springframework.level = WARN
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file
+rootLogger.appenderRef.out.ref = out
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
new file mode 100644
index 0000000..6fa28c3
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
@@ -0,0 +1,34 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "definitions": {},
+ "id": "http://example.com/example.json",
+ "properties": {
+ "id": {
+ "default": 1,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/id",
+ "title": "The id schema",
+ "type": "integer"
+ },
+ "name": {
+ "default": "A green door",
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/name",
+ "title": "The name schema",
+ "type": "string"
+ },
+ "price": {
+ "default": 12.5,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/price",
+ "title": "The price schema",
+ "type": "number"
+ }
+ },
+ "required": [
+ "name",
+ "id",
+ "price"
+ ],
+ "type": "object"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 83d4b52..60f3850 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -121,6 +121,7 @@
<module>camel-elsql</module>
<module>camel-etcd</module>
<module>camel-eventadmin</module>
+ <module>camel-everit-json-schema</module>
<module>camel-exec</module>
<module>camel-facebook</module>
<module>camel-fastjson</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 92cf7f1..ca1d8be 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -209,6 +209,7 @@
<!-- embedmongo 1.50.2 do not work -->
<embedmongo-version>1.50.1</embedmongo-version>
<etcd4j-version>2.13.0</etcd4j-version>
+ <everit-org-json-schema-version>1.6.0</everit-org-json-schema-version>
<exec-maven-plugin-version>1.6.0</exec-maven-plugin-version>
<ezmorph-bundle-version>1.0.6_1</ezmorph-bundle-version>
<fabric8-maven-plugin-version>3.5.30</fabric8-maven-plugin-version>
@@ -4485,6 +4486,13 @@
<version>${jira-rest-client-version}</version>
</dependency>
+ <!-- Optional Everit.org JSON Schema -->
+ <dependency>
+ <groupId>com.github.everit-org.json-schema</groupId>
+ <artifactId>org.everit.json.schema</artifactId>
+ <version>${everit-org-json-schema-version}</version>
+ </dependency>
+
<!-- optional misc -->
<dependency>
<groupId>com.google.code.scriptengines</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml
new file mode 100644
index 0000000..5ee84a3
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components-starter</artifactId>
+ <version>2.20.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>camel-everit-json-schema-starter</artifactId>
+ <packaging>jar</packaging>
+ <name>Spring-Boot Starter :: Camel :: Everit Kft. JSON Schema validator</name>
+ <description>Spring-Boot Starter for Camel JSON Schema validation based on everit-org json-schema library</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema</artifactId>
+ <version>${project.version}</version>
+ <!--START OF GENERATED CODE-->
+ <exclusions>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ <!--END OF GENERATED CODE-->
+ </dependency>
+ <!--START OF GENERATED CODE-->
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <!--END OF GENERATED CODE-->
+ </dependencies>
+ <!--START OF GENERATED CODE-->
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ </repositories>
+ <!--END OF GENERATED CODE-->
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
new file mode 100644
index 0000000..7d2decc
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
@@ -0,0 +1,129 @@
+/**
+ * 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.everit.jsonschema.springboot;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Generated;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.everit.jsonschema.JsonSchemaValidatorComponent;
+import org.apache.camel.spi.ComponentCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.apache.camel.spring.boot.ComponentConfigurationProperties;
+import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
+import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
+import org.apache.camel.spring.boot.util.GroupCondition;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
+import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.AutoConfigureAfter;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Conditional;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+
+/**
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@Configuration
+@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
+ JsonSchemaValidatorComponentAutoConfiguration.GroupConditions.class})
+@AutoConfigureAfter(CamelAutoConfiguration.class)
+@EnableConfigurationProperties({ComponentConfigurationProperties.class,
+ JsonSchemaValidatorComponentConfiguration.class})
+public class JsonSchemaValidatorComponentAutoConfiguration {
+
+ private static final Logger LOGGER = LoggerFactory
+ .getLogger(JsonSchemaValidatorComponentAutoConfiguration.class);
+ @Autowired
+ private ApplicationContext applicationContext;
+ @Autowired
+ private CamelContext camelContext;
+ @Autowired
+ private JsonSchemaValidatorComponentConfiguration configuration;
+ @Autowired(required = false)
+ private List<ComponentCustomizer<JsonSchemaValidatorComponent>> customizers;
+
+ static class GroupConditions extends GroupCondition {
+ public GroupConditions() {
+ super("camel.component", "camel.component.json-validator");
+ }
+ }
+
+ @Lazy
+ @Bean(name = "json-validator-component")
+ @ConditionalOnMissingBean(JsonSchemaValidatorComponent.class)
+ public JsonSchemaValidatorComponent configureJsonSchemaValidatorComponent()
+ throws Exception {
+ JsonSchemaValidatorComponent component = new JsonSchemaValidatorComponent();
+ component.setCamelContext(camelContext);
+ Map<String, Object> parameters = new HashMap<>();
+ IntrospectionSupport.getProperties(configuration, parameters, null,
+ false);
+ for (Map.Entry<String, Object> entry : parameters.entrySet()) {
+ Object value = entry.getValue();
+ Class<?> paramClass = value.getClass();
+ if (paramClass.getName().endsWith("NestedConfiguration")) {
+ Class nestedClass = null;
+ try {
+ nestedClass = (Class) paramClass.getDeclaredField(
+ "CAMEL_NESTED_CLASS").get(null);
+ HashMap<String, Object> nestedParameters = new HashMap<>();
+ IntrospectionSupport.getProperties(value, nestedParameters,
+ null, false);
+ Object nestedProperty = nestedClass.newInstance();
+ CamelPropertiesHelper.setCamelProperties(camelContext,
+ nestedProperty, nestedParameters, false);
+ entry.setValue(nestedProperty);
+ } catch (NoSuchFieldException e) {
+ }
+ }
+ }
+ CamelPropertiesHelper.setCamelProperties(camelContext, component,
+ parameters, false);
+ if (ObjectHelper.isNotEmpty(customizers)) {
+ for (ComponentCustomizer<JsonSchemaValidatorComponent> customizer : customizers) {
+ boolean useCustomizer = (customizer instanceof HasId)
+ ? HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.json-validator.customizer",
+ ((HasId) customizer).getId())
+ : HierarchicalPropertiesEvaluator.evaluate(
+ applicationContext.getEnvironment(),
+ "camel.component.customizer",
+ "camel.component.json-validator.customizer");
+ if (useCustomizer) {
+ LOGGER.debug("Configure component {}, with customizer {}",
+ component, customizer);
+ customizer.customize(component);
+ }
+ }
+ }
+ return component;
+ }
+}
\ No newline at end of file
[04/14] camel git commit: Initial version of camel-everit-json-schema
component
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
new file mode 100644
index 0000000..7c0ca28
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
@@ -0,0 +1,49 @@
+/**
+ * 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.everit.jsonschema.springboot;
+
+import javax.annotation.Generated;
+import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * Validates the payload of a message using XML Schema and JAXP Validation.
+ *
+ * Generated by camel-package-maven-plugin - do not edit this file!
+ */
+@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
+@ConfigurationProperties(prefix = "camel.component.json-validator")
+public class JsonSchemaValidatorComponentConfiguration
+ extends
+ ComponentConfigurationPropertiesCommon {
+
+ /**
+ * Whether the component should resolve property placeholders on itself when
+ * starting. Only properties which are of String type can use property
+ * placeholders.
+ */
+ private Boolean resolvePropertyPlaceholders = true;
+
+ public Boolean getResolvePropertyPlaceholders() {
+ return resolvePropertyPlaceholders;
+ }
+
+ public void setResolvePropertyPlaceholders(
+ Boolean resolvePropertyPlaceholders) {
+ this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt
new file mode 100644
index 0000000..6b0b127
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories
new file mode 100644
index 0000000..854708c
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.factories
@@ -0,0 +1,19 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
+org.apache.camel.component.everit.jsonschema.springboot.JsonSchemaValidatorComponentAutoConfiguration
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides
new file mode 100644
index 0000000..5a9ab4d
--- /dev/null
+++ b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/resources/META-INF/spring.provides
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+provides: camel-everit-json-schema
http://git-wip-us.apache.org/repos/asf/camel/blob/8ba38cf8/platforms/spring-boot/components-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/pom.xml b/platforms/spring-boot/components-starter/pom.xml
index 61139c5..5769215 100644
--- a/platforms/spring-boot/components-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/pom.xml
@@ -132,6 +132,7 @@
<module>camel-elasticsearch5-starter</module>
<module>camel-elsql-starter</module>
<module>camel-etcd-starter</module>
+ <module>camel-everit-json-schema-starter</module>
<module>camel-exec-starter</module>
<module>camel-facebook-starter</module>
<module>camel-fastjson-starter</module>
[08/14] camel git commit: CAMEL-9799: Add karaf feature and test
Posted by da...@apache.org.
CAMEL-9799: Add karaf feature and test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/408a7465
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/408a7465
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/408a7465
Branch: refs/heads/master
Commit: 408a7465c180b380efd5a9f695ea092b7efea0be
Parents: f7c2780
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 10:03:26 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 10:03:26 2017 +0200
----------------------------------------------------------------------
components/camel-everit-json-schema/pom.xml | 1 +
.../jsonschema/JsonSchemaValidatorEndpoint.java | 2 +-
parent/pom.xml | 7 -----
.../features/src/main/resources/features.xml | 13 ++++++++
.../itest/karaf/CamelEveritJsonSchemaTest.java | 33 ++++++++++++++++++++
5 files changed, 48 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/408a7465/components/camel-everit-json-schema/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/pom.xml b/components/camel-everit-json-schema/pom.xml
index b913a3c..cab2c27 100644
--- a/components/camel-everit-json-schema/pom.xml
+++ b/components/camel-everit-json-schema/pom.xml
@@ -52,6 +52,7 @@
<dependency>
<groupId>com.github.everit-org.json-schema</groupId>
<artifactId>org.everit.json.schema</artifactId>
+ <version>${everit-org-json-schema-version}</version>
</dependency>
<!-- for testing -->
http://git-wip-us.apache.org/repos/asf/camel/blob/408a7465/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
index 4fa04d0..afca7a3 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
@@ -37,7 +37,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Validates the payload of a message using XML Schema and JAXP Validation.
+ * Validates the payload of a message using Everit JSON schema validator.
*/
@ManagedResource(description = "Managed JsonSchemaValidatorEndpoint")
@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "validation,json")
http://git-wip-us.apache.org/repos/asf/camel/blob/408a7465/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 796b069..0a3cacc 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -4496,13 +4496,6 @@
<version>${jira-rest-client-version}</version>
</dependency>
- <!-- Optional Everit.org JSON Schema -->
- <dependency>
- <groupId>com.github.everit-org.json-schema</groupId>
- <artifactId>org.everit.json.schema</artifactId>
- <version>${everit-org-json-schema-version}</version>
- </dependency>
-
<!-- optional misc -->
<dependency>
<groupId>com.google.code.scriptengines</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/408a7465/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index ecb736e..9fb3cee 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -622,6 +622,19 @@
<feature>eventadmin</feature>
<bundle>mvn:org.apache.camel/camel-eventadmin/${project.version}</bundle>
</feature>
+ <feature name='camel-everit-json-schema' version='${project.version}' resolver='(obr)' start-level='50'>
+ <feature version='${project.version}'>camel-core</feature>
+ <bundle dependency='true'>mvn:com.github.everit-org.json-schema/org.everit.json.schema/${everit-org-json-schema-version}</bundle>
+ <bundle dependency='true'>mvn:org.json/json/20170516</bundle>
+ <bundle dependency='true'>mvn:com.damnhandy/handy-uri-templates/2.1.6</bundle>
+ <bundle dependency='true'>mvn:joda-time/joda-time/${jodatime2-bundle-version}</bundle>
+ <bundle dependency='true'>mvn:com.google.guava/guava/22.0</bundle>
+ <bundle dependency='true'>mvn:commons-collections/commons-collections/${commons-collections-version}</bundle>
+ <bundle dependency='true'>mvn:commons-validator/commons-validator/1.6</bundle>
+ <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-beanutils/${commons-beanutils-bundle-version}</bundle>
+ <bundle dependency='true'>mvn:commons-digester/commons-digester/${commons-digester-version}</bundle>
+ <bundle>mvn:org.apache.camel/camel-everit-json-schema/${project.version}</bundle>
+ </feature>
<feature name='camel-exec' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:org.apache.commons/commons-exec/${commons-exec-version}</bundle>
http://git-wip-us.apache.org/repos/asf/camel/blob/408a7465/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java
new file mode 100644
index 0000000..7288b55
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelEveritJsonSchemaTest extends BaseKarafTest {
+
+ public static final String COMPONENT = "json-validator";
+
+ @Test
+ public void test() throws Exception {
+ testComponent("camel-everit-json-schema", COMPONENT);
+ }
+
+}
\ No newline at end of file
[12/14] camel git commit: CAMEL-9799: Add karaf feature and test
Posted by da...@apache.org.
CAMEL-9799: Add karaf feature and test
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a6172f80
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a6172f80
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a6172f80
Branch: refs/heads/master
Commit: a6172f807fb1d5fd8d7e36e73f7bbce57604aab8
Parents: 1fa64e6
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 10:19:52 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 10:19:52 2017 +0200
----------------------------------------------------------------------
.../features/src/main/resources/features.xml | 26 +++++++--------
.../itest/karaf/CamelEveritJsonSchemaTest.java | 33 --------------------
.../itest/karaf/CamelJsonValidatorTest.java | 33 ++++++++++++++++++++
3 files changed, 46 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a6172f80/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 9fb3cee..39f2336 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -622,19 +622,6 @@
<feature>eventadmin</feature>
<bundle>mvn:org.apache.camel/camel-eventadmin/${project.version}</bundle>
</feature>
- <feature name='camel-everit-json-schema' version='${project.version}' resolver='(obr)' start-level='50'>
- <feature version='${project.version}'>camel-core</feature>
- <bundle dependency='true'>mvn:com.github.everit-org.json-schema/org.everit.json.schema/${everit-org-json-schema-version}</bundle>
- <bundle dependency='true'>mvn:org.json/json/20170516</bundle>
- <bundle dependency='true'>mvn:com.damnhandy/handy-uri-templates/2.1.6</bundle>
- <bundle dependency='true'>mvn:joda-time/joda-time/${jodatime2-bundle-version}</bundle>
- <bundle dependency='true'>mvn:com.google.guava/guava/22.0</bundle>
- <bundle dependency='true'>mvn:commons-collections/commons-collections/${commons-collections-version}</bundle>
- <bundle dependency='true'>mvn:commons-validator/commons-validator/1.6</bundle>
- <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-beanutils/${commons-beanutils-bundle-version}</bundle>
- <bundle dependency='true'>mvn:commons-digester/commons-digester/${commons-digester-version}</bundle>
- <bundle>mvn:org.apache.camel/camel-everit-json-schema/${project.version}</bundle>
- </feature>
<feature name='camel-exec' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle dependency='true'>mvn:org.apache.commons/commons-exec/${commons-exec-version}</bundle>
@@ -1238,6 +1225,19 @@
<feature version='${project.version}'>camel-ftp</feature>
<bundle>mvn:org.apache.camel/camel-jsch/${project.version}</bundle>
</feature>
+ <feature name='camel-json-validator' version='${project.version}' resolver='(obr)' start-level='50'>
+ <feature version='${project.version}'>camel-core</feature>
+ <bundle dependency='true'>mvn:com.github.everit-org.json-schema/org.everit.json.schema/${everit-org-json-schema-version}</bundle>
+ <bundle dependency='true'>mvn:org.json/json/20170516</bundle>
+ <bundle dependency='true'>mvn:com.damnhandy/handy-uri-templates/2.1.6</bundle>
+ <bundle dependency='true'>mvn:joda-time/joda-time/${jodatime2-bundle-version}</bundle>
+ <bundle dependency='true'>mvn:com.google.guava/guava/22.0</bundle>
+ <bundle dependency='true'>mvn:commons-collections/commons-collections/${commons-collections-version}</bundle>
+ <bundle dependency='true'>mvn:commons-validator/commons-validator/1.6</bundle>
+ <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-beanutils/${commons-beanutils-bundle-version}</bundle>
+ <bundle dependency='true'>mvn:commons-digester/commons-digester/${commons-digester-version}</bundle>
+ <bundle>mvn:org.apache.camel/camel-json-validator/${project.version}</bundle>
+ </feature>
<feature name='camel-jsonpath' version='${project.version}' resolver='(obr)' start-level='50'>
<feature version='${project.version}'>camel-core</feature>
<bundle>mvn:com.jayway.jsonpath/json-path/${json-path-version}</bundle>
http://git-wip-us.apache.org/repos/asf/camel/blob/a6172f80/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java
deleted file mode 100644
index 7288b55..0000000
--- a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelEveritJsonSchemaTest.java
+++ /dev/null
@@ -1,33 +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.itest.karaf;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.PaxExam;
-
-@RunWith(PaxExam.class)
-public class CamelEveritJsonSchemaTest extends BaseKarafTest {
-
- public static final String COMPONENT = "json-validator";
-
- @Test
- public void test() throws Exception {
- testComponent("camel-everit-json-schema", COMPONENT);
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/a6172f80/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelJsonValidatorTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelJsonValidatorTest.java b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelJsonValidatorTest.java
new file mode 100644
index 0000000..b377366
--- /dev/null
+++ b/tests/camel-itest-karaf/src/test/java/org/apache/camel/itest/karaf/CamelJsonValidatorTest.java
@@ -0,0 +1,33 @@
+/**
+ * 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.itest.karaf;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+
+@RunWith(PaxExam.class)
+public class CamelJsonValidatorTest extends BaseKarafTest {
+
+ public static final String COMPONENT = extractName(CamelJsonValidatorTest.class);
+
+ @Test
+ public void test() throws Exception {
+ testComponent(COMPONENT);
+ }
+
+}
\ No newline at end of file
[13/14] camel git commit: CAMEL-9799: Regen
Posted by da...@apache.org.
CAMEL-9799: Regen
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d8a9ea30
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d8a9ea30
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d8a9ea30
Branch: refs/heads/master
Commit: d8a9ea302f5433b44936c9abd2d931b79ccb8075
Parents: a6172f8
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 10:57:11 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 10:57:11 2017 +0200
----------------------------------------------------------------------
bom/camel-bom/pom.xml | 10 ++
.../src/main/docs/json-validator-component.adoc | 2 +-
components/readme.adoc | 5 +-
docs/user-manual/en/SUMMARY.md | 1 +
.../camel-json-validator-starter/pom.xml | 4 +-
...hemaValidatorComponentAutoConfiguration.java | 129 -------------------
...onSchemaValidatorComponentConfiguration.java | 49 -------
.../main/resources/META-INF/spring.factories | 2 -
.../camel-spring-boot-dependencies/pom.xml | 10 ++
9 files changed, 28 insertions(+), 184 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/bom/camel-bom/pom.xml
----------------------------------------------------------------------
diff --git a/bom/camel-bom/pom.xml b/bom/camel-bom/pom.xml
index 7b968de..69b3a60 100644
--- a/bom/camel-bom/pom.xml
+++ b/bom/camel-bom/pom.xml
@@ -1400,6 +1400,16 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/components/camel-json-validator/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/docs/json-validator-component.adoc b/components/camel-json-validator/src/main/docs/json-validator-component.adoc
index d0e6d56..1bb3e20 100644
--- a/components/camel-json-validator/src/main/docs/json-validator-component.adoc
+++ b/components/camel-json-validator/src/main/docs/json-validator-component.adoc
@@ -124,4 +124,4 @@ we can validate incoming JSON with the following Camel route, where `myschema.js
from("direct:start")
.to("json-validator:myschema.json")
.to("mock:end")
-----
\ No newline at end of file
+----
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/components/readme.adoc
----------------------------------------------------------------------
diff --git a/components/readme.adoc b/components/readme.adoc
index 7085dbf..9520eae 100644
--- a/components/readme.adoc
+++ b/components/readme.adoc
@@ -2,7 +2,7 @@ Components
^^^^^^^^^^
// components: START
-Number of Components: 283 in 194 JAR artifacts (17 deprecated)
+Number of Components: 284 in 195 JAR artifacts (17 deprecated)
[width="100%",cols="4,1,5",options="header"]
|===
@@ -440,6 +440,9 @@ Number of Components: 283 in 194 JAR artifacts (17 deprecated)
| link:camel-jpa/src/main/docs/jpa-component.adoc[JPA] (camel-jpa) +
`jpa:entityType` | 1.0 | The jpa component enables you to store and retrieve Java objects from databases using JPA.
+| link:camel-json-validator/src/main/docs/json-validator-component.adoc[JSON Schema Validator] (camel-json-validator) +
+`json-validator:resourceUri` | | Validates the payload of a message using Everit JSON schema validator.
+
| link:camel-jt400/src/main/docs/jt400-component.adoc[JT400] (camel-jt400) +
`jt400:userID:password/systemName/objectPath.type` | 1.5 | The jt400 component allows you to exchanges messages with an AS/400 system using data queues or program call.
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/docs/user-manual/en/SUMMARY.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/SUMMARY.md b/docs/user-manual/en/SUMMARY.md
index 1ca6513..332940e 100644
--- a/docs/user-manual/en/SUMMARY.md
+++ b/docs/user-manual/en/SUMMARY.md
@@ -259,6 +259,7 @@
* [JMX](jmx-component.adoc)
* [JOLT](jolt-component.adoc)
* [JPA](jpa-component.adoc)
+ * [JSON Schema Validator](json-validator-component.adoc)
* [JT400](jt400-component.adoc)
* [Kafka](kafka-component.adoc)
* [Kestrel](kestrel-component.adoc)
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml b/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
index 83d6fb2..0756538 100644
--- a/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/pom.xml
@@ -26,8 +26,8 @@
</parent>
<artifactId>camel-json-validator-starter</artifactId>
<packaging>jar</packaging>
- <name>Spring-Boot Starter :: Camel :: Everit Kft. JSON Schema validator</name>
- <description>Spring-Boot Starter for Camel JSON Schema validation based on everit-org json-schema library</description>
+ <name>Spring-Boot Starter :: Camel :: JSON validator</name>
+ <description>Spring-Boot Starter for Camel JSON Schema validation based on Everit JSON-schema library</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
deleted file mode 100644
index 7d2decc..0000000
--- a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
+++ /dev/null
@@ -1,129 +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.everit.jsonschema.springboot;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Generated;
-import org.apache.camel.CamelContext;
-import org.apache.camel.component.everit.jsonschema.JsonSchemaValidatorComponent;
-import org.apache.camel.spi.ComponentCustomizer;
-import org.apache.camel.spi.HasId;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.ComponentConfigurationProperties;
-import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
-import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
-import org.apache.camel.util.IntrospectionSupport;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-
-/**
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
-@Configuration
-@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
- JsonSchemaValidatorComponentAutoConfiguration.GroupConditions.class})
-@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties({ComponentConfigurationProperties.class,
- JsonSchemaValidatorComponentConfiguration.class})
-public class JsonSchemaValidatorComponentAutoConfiguration {
-
- private static final Logger LOGGER = LoggerFactory
- .getLogger(JsonSchemaValidatorComponentAutoConfiguration.class);
- @Autowired
- private ApplicationContext applicationContext;
- @Autowired
- private CamelContext camelContext;
- @Autowired
- private JsonSchemaValidatorComponentConfiguration configuration;
- @Autowired(required = false)
- private List<ComponentCustomizer<JsonSchemaValidatorComponent>> customizers;
-
- static class GroupConditions extends GroupCondition {
- public GroupConditions() {
- super("camel.component", "camel.component.json-validator");
- }
- }
-
- @Lazy
- @Bean(name = "json-validator-component")
- @ConditionalOnMissingBean(JsonSchemaValidatorComponent.class)
- public JsonSchemaValidatorComponent configureJsonSchemaValidatorComponent()
- throws Exception {
- JsonSchemaValidatorComponent component = new JsonSchemaValidatorComponent();
- component.setCamelContext(camelContext);
- Map<String, Object> parameters = new HashMap<>();
- IntrospectionSupport.getProperties(configuration, parameters, null,
- false);
- for (Map.Entry<String, Object> entry : parameters.entrySet()) {
- Object value = entry.getValue();
- Class<?> paramClass = value.getClass();
- if (paramClass.getName().endsWith("NestedConfiguration")) {
- Class nestedClass = null;
- try {
- nestedClass = (Class) paramClass.getDeclaredField(
- "CAMEL_NESTED_CLASS").get(null);
- HashMap<String, Object> nestedParameters = new HashMap<>();
- IntrospectionSupport.getProperties(value, nestedParameters,
- null, false);
- Object nestedProperty = nestedClass.newInstance();
- CamelPropertiesHelper.setCamelProperties(camelContext,
- nestedProperty, nestedParameters, false);
- entry.setValue(nestedProperty);
- } catch (NoSuchFieldException e) {
- }
- }
- }
- CamelPropertiesHelper.setCamelProperties(camelContext, component,
- parameters, false);
- if (ObjectHelper.isNotEmpty(customizers)) {
- for (ComponentCustomizer<JsonSchemaValidatorComponent> customizer : customizers) {
- boolean useCustomizer = (customizer instanceof HasId)
- ? HierarchicalPropertiesEvaluator.evaluate(
- applicationContext.getEnvironment(),
- "camel.component.customizer",
- "camel.component.json-validator.customizer",
- ((HasId) customizer).getId())
- : HierarchicalPropertiesEvaluator.evaluate(
- applicationContext.getEnvironment(),
- "camel.component.customizer",
- "camel.component.json-validator.customizer");
- if (useCustomizer) {
- LOGGER.debug("Configure component {}, with customizer {}",
- component, customizer);
- customizer.customize(component);
- }
- }
- }
- return component;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
deleted file mode 100644
index 7c0ca28..0000000
--- a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentConfiguration.java
+++ /dev/null
@@ -1,49 +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.everit.jsonschema.springboot;
-
-import javax.annotation.Generated;
-import org.apache.camel.spring.boot.ComponentConfigurationPropertiesCommon;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * Validates the payload of a message using XML Schema and JAXP Validation.
- *
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
-@ConfigurationProperties(prefix = "camel.component.json-validator")
-public class JsonSchemaValidatorComponentConfiguration
- extends
- ComponentConfigurationPropertiesCommon {
-
- /**
- * Whether the component should resolve property placeholders on itself when
- * starting. Only properties which are of String type can use property
- * placeholders.
- */
- private Boolean resolvePropertyPlaceholders = true;
-
- public Boolean getResolvePropertyPlaceholders() {
- return resolvePropertyPlaceholders;
- }
-
- public void setResolvePropertyPlaceholders(
- Boolean resolvePropertyPlaceholders) {
- this.resolvePropertyPlaceholders = resolvePropertyPlaceholders;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
index 89e1ba4..84720cd 100644
--- a/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
+++ b/platforms/spring-boot/components-starter/camel-json-validator-starter/src/main/resources/META-INF/spring.factories
@@ -16,6 +16,4 @@
## ---------------------------------------------------------------------------
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.apache.camel.component.everit.jsonschema.springboot.JsonSchemaValidatorComponentAutoConfiguration,\
org.apache.camel.component.jsonvalidator.springboot.JsonValidatorComponentAutoConfiguration
-
http://git-wip-us.apache.org/repos/asf/camel/blob/d8a9ea30/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
index 32a4d37..53c44ff 100644
--- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
+++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
@@ -1576,6 +1576,16 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>${project.version}</version>
</dependency>
[11/14] camel git commit: CAMEL-9799: Rename component to
json-validator so it has a better name
Posted by da...@apache.org.
CAMEL-9799: Rename component to json-validator so it has a better name
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1fa64e6d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1fa64e6d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1fa64e6d
Branch: refs/heads/master
Commit: 1fa64e6d9cf72b39ff6d92623b0603a803bdc9a4
Parents: 408a746
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 10:17:51 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 10:17:51 2017 +0200
----------------------------------------------------------------------
apache-camel/pom.xml | 18 +-
.../src/main/descriptors/common-bin.xml | 4 +-
components/camel-everit-json-schema/pom.xml | 91 ---------
.../src/main/docs/json-validator-component.adoc | 127 ------------
.../jsonschema/DefaultJsonSchemaLoader.java | 40 ----
.../DefaultJsonValidationErrorHandler.java | 38 ----
.../everit/jsonschema/JsonSchemaLoader.java | 44 ----
.../JsonSchemaValidationException.java | 36 ----
.../JsonSchemaValidatorComponent.java | 35 ----
.../jsonschema/JsonSchemaValidatorEndpoint.java | 201 ------------------
.../jsonschema/JsonValidatorErrorHandler.java | 39 ----
.../NoJsonBodyValidationException.java | 35 ----
.../NoJsonHeaderValidationException.java | 36 ----
.../component/everit/jsonschema/package.html | 25 ---
.../src/main/resources/META-INF/LICENSE.txt | 203 -------------------
.../src/main/resources/META-INF/NOTICE.txt | 11 -
.../org/apache/camel/component/json-validator | 18 --
.../CustomSchemaLoaderValidatorRouteTest.java | 84 --------
.../everit/jsonschema/EvenCharNumValidator.java | 38 ----
.../jsonschema/FileValidatorRouteTest.java | 94 ---------
.../jsonschema/TestCustomSchemaLoader.java | 42 ----
.../everit/jsonschema/ValidatorRouteTest.java | 174 ----------------
.../src/test/resources/log4j2.properties | 29 ---
.../component/everit/jsonschema/schema.json | 34 ----
.../everit/jsonschema/schemawithformat.json | 35 ----
components/camel-json-validator/pom.xml | 91 +++++++++
.../src/main/docs/json-validator-component.adoc | 127 ++++++++++++
.../jsonvalidator/DefaultJsonSchemaLoader.java | 40 ++++
.../DefaultJsonValidationErrorHandler.java | 38 ++++
.../jsonvalidator/JsonSchemaLoader.java | 44 ++++
.../jsonvalidator/JsonValidationException.java | 36 ++++
.../jsonvalidator/JsonValidatorComponent.java | 35 ++++
.../jsonvalidator/JsonValidatorEndpoint.java | 201 ++++++++++++++++++
.../JsonValidatorErrorHandler.java | 39 ++++
.../NoJsonBodyValidationException.java | 35 ++++
.../NoJsonHeaderValidationException.java | 36 ++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../org/apache/camel/component/json-validator | 18 ++
.../CustomSchemaLoaderValidatorRouteTest.java | 84 ++++++++
.../jsonvalidator/EvenCharNumValidator.java | 38 ++++
.../jsonvalidator/FileValidatorRouteTest.java | 94 +++++++++
.../jsonvalidator/TestCustomSchemaLoader.java | 42 ++++
.../jsonvalidator/ValidatorRouteTest.java | 174 ++++++++++++++++
.../src/test/resources/log4j2.properties | 29 +++
.../camel/component/jsonvalidator/schema.json | 34 ++++
.../jsonvalidator/schemawithformat.json | 35 ++++
components/pom.xml | 2 +-
parent/pom.xml | 20 +-
.../camel-everit-json-schema-starter/pom.xml | 69 -------
...hemaValidatorComponentAutoConfiguration.java | 129 ------------
...onSchemaValidatorComponentConfiguration.java | 49 -----
.../src/main/resources/META-INF/LICENSE.txt | 203 -------------------
.../src/main/resources/META-INF/NOTICE.txt | 11 -
.../main/resources/META-INF/spring.factories | 19 --
.../src/main/resources/META-INF/spring.provides | 17 --
.../camel-json-validator-starter/pom.xml | 69 +++++++
...hemaValidatorComponentAutoConfiguration.java | 129 ++++++++++++
...onSchemaValidatorComponentConfiguration.java | 49 +++++
...JsonValidatorComponentAutoConfiguration.java | 129 ++++++++++++
.../JsonValidatorComponentConfiguration.java | 49 +++++
.../src/main/resources/META-INF/LICENSE.txt | 203 +++++++++++++++++++
.../src/main/resources/META-INF/NOTICE.txt | 11 +
.../main/resources/META-INF/spring.factories | 21 ++
.../src/main/resources/META-INF/spring.provides | 17 ++
.../spring-boot/components-starter/pom.xml | 2 +-
66 files changed, 2184 insertions(+), 2029 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index ed275ef..beb8974 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -304,10 +304,6 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-everit-json-schema</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
<artifactId>camel-exec</artifactId>
</dependency>
<dependency>
@@ -588,6 +584,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
</dependency>
<dependency>
@@ -1434,11 +1434,6 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-everit-json-schema-starter</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
<artifactId>camel-exec-starter</artifactId>
<version>${project.version}</version>
</dependency>
@@ -1774,6 +1769,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath-starter</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/apache-camel/src/main/descriptors/common-bin.xml
----------------------------------------------------------------------
diff --git a/apache-camel/src/main/descriptors/common-bin.xml b/apache-camel/src/main/descriptors/common-bin.xml
index 64c2c2a..51c46bf 100644
--- a/apache-camel/src/main/descriptors/common-bin.xml
+++ b/apache-camel/src/main/descriptors/common-bin.xml
@@ -88,7 +88,6 @@
<include>org.apache.camel:camel-elsql</include>
<include>org.apache.camel:camel-etcd</include>
<include>org.apache.camel:camel-eventadmin</include>
- <include>org.apache.camel:camel-everit-json-schema</include>
<include>org.apache.camel:camel-exec</include>
<include>org.apache.camel:camel-facebook</include>
<include>org.apache.camel:camel-fastjson</include>
@@ -157,6 +156,7 @@
<include>org.apache.camel:camel-josql</include>
<include>org.apache.camel:camel-jpa</include>
<include>org.apache.camel:camel-jsch</include>
+ <include>org.apache.camel:camel-json-validator</include>
<include>org.apache.camel:camel-jsonpath</include>
<include>org.apache.camel:camel-jt400</include>
<include>org.apache.camel:camel-juel</include>
@@ -384,7 +384,6 @@
<include>org.apache.camel:camel-elasticsearch5-starter</include>
<include>org.apache.camel:camel-elsql-starter</include>
<include>org.apache.camel:camel-etcd-starter</include>
- <include>org.apache.camel:camel-everit-json-schema-starter</include>
<include>org.apache.camel:camel-exec-starter</include>
<include>org.apache.camel:camel-facebook-starter</include>
<include>org.apache.camel:camel-fastjson-starter</include>
@@ -452,6 +451,7 @@
<include>org.apache.camel:camel-josql-starter</include>
<include>org.apache.camel:camel-jpa-starter</include>
<include>org.apache.camel:camel-jsch-starter</include>
+ <include>org.apache.camel:camel-json-validator-starter</include>
<include>org.apache.camel:camel-jsonpath-starter</include>
<include>org.apache.camel:camel-jt400-starter</include>
<include>org.apache.camel:camel-juel-starter</include>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/pom.xml b/components/camel-everit-json-schema/pom.xml
deleted file mode 100644
index cab2c27..0000000
--- a/components/camel-everit-json-schema/pom.xml
+++ /dev/null
@@ -1,91 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.20.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>camel-everit-json-schema</artifactId>
- <name>Camel :: Everit JSON Schema validator</name>
- <description>Camel JSON Schema validation based on Everit JSON-schema library</description>
- <packaging>jar</packaging>
-
- <properties>
- <camel.osgi.export.pkg>org.apache.camel.component.everit.jsonschema.*</camel.osgi.export.pkg>
- <camel.osgi.export.service>
- org.apache.camel.spi.ComponentResolver;component=json-validator
- </camel.osgi.export.service>
- </properties>
-
- <!-- everit is distributed in jitpack and not Maven central -->
- <repositories>
- <repository>
- <id>jitpack.io</id>
- <url>https://jitpack.io</url>
- </repository>
- </repositories>
- <dependencies>
-
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>com.github.everit-org.json-schema</groupId>
- <artifactId>org.everit.json.schema</artifactId>
- <version>${everit-org-json-schema-version}</version>
- </dependency>
-
- <!-- for testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
deleted file mode 100644
index d0e6d56..0000000
--- a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
+++ /dev/null
@@ -1,127 +0,0 @@
-== JSON Schema Validator Component
-
-*Available as of Camel version *
-
-The JSON Schema Validator component performs bean validation of the message body
-agains JSON Schemas using the Everit.org JSON Schema library
-(https://github.com/everit-org/json-schema).
-
-Maven users will need to add the following dependency to their `pom.xml`
-for this component:
-
-[source,xml]
-----
-<dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-everit-json-schema</artifactId>
- <version>x.y.z</version>
- <!-- use the same version as your Camel core version -->
-</dependency>
-----
-
-
-=== URI format
-
-[source]
-----
-json-validator:resourceUri[?options]
-----
-
-
-Where *resourceUri* is some URL to a local resource on the classpath or a
-full URL to a remote resource or resource on the file system which contains
-the JSON Schema to validate against.
-
-=== URI Options
-
-// component options: START
-The JSON Schema Validator component has no options.
-// component options: END
-
-
-
-// endpoint options: START
-The JSON Schema Validator endpoint is configured using URI syntax:
-
-----
-json-validator:resourceUri
-----
-
-with the following path and query parameters:
-
-==== Path Parameters (1 parameters):
-
-[width="100%",cols="2,5,^1,2",options="header"]
-|===
-| Name | Description | Default | Type
-| *resourceUri* | *Required* Path to the resource. You can prefix with: classpath file http ref or bean. classpath file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot eg bean:myBean.myMethod. | | String
-|===
-
-==== Query Parameters (7 parameters):
-
-[width="100%",cols="2,5,^1,2",options="header"]
-|===
-| Name | Description | Default | Type
-| *contentCache* (producer) | Sets whether to use resource content cache or not | false | boolean
-| *failOnNullBody* (producer) | Whether to fail if no body exists. | true | boolean
-| *failOnNullHeader* (producer) | Whether to fail if no header exists when validating against a header. | true | boolean
-| *headerName* (producer) | To validate against a header instead of the message body. | | String
-| *errorHandler* (advanced) | To use a custom ValidatorErrorHandler. The default error handler captures the errors and throws an exception. | | JsonValidatorError Handler
-| *schemaLoader* (advanced) | To use a custom schema loader allowing for adding custom format validation. See Everit JSON Schema documentation. The default implementation will create a schema loader builder with draft v6 support. | | JsonSchemaLoader
-| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
-|===
-// endpoint options: END
-
-
-=== Example
-
-Assumed we have the following JSON Schema
-
-*myschema.json*
-
-[source,json]
-----
-{
- "$schema": "http://json-schema.org/draft-04/schema#",
- "definitions": {},
- "id": "http://example.com/example.json",
- "properties": {
- "id": {
- "default": 1,
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/id",
- "title": "The id schema",
- "type": "integer"
- },
- "name": {
- "default": "A green door",
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/name",
- "title": "The name schema",
- "type": "string"
- },
- "price": {
- "default": 12.5,
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/price",
- "title": "The price schema",
- "type": "number"
- }
- },
- "required": [
- "name",
- "id",
- "price"
- ],
- "type": "object"
-}
-----
-
-we can validate incoming JSON with the following Camel route, where `myschema.json` is loaded from the classpath.
-
-[source,java]
-----
-from("direct:start")
- .to("json-validator:myschema.json")
- .to("mock:end")
-----
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
deleted file mode 100644
index 97e25c7..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
+++ /dev/null
@@ -1,40 +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.everit.jsonschema;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.camel.CamelContext;
-import org.everit.json.schema.Schema;
-import org.everit.json.schema.loader.SchemaLoader;
-import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-
-public class DefaultJsonSchemaLoader implements JsonSchemaLoader {
-
- @Override
- public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
- SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
- try (InputStream inputStream = schemaInputStream) {
- JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
- return schemaLoaderBuilder.schemaJson(rawSchema).build().load().build();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
deleted file mode 100644
index 5978f3a..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
+++ /dev/null
@@ -1,38 +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.everit.jsonschema;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ValidationException;
-
-public class DefaultJsonValidationErrorHandler implements JsonValidatorErrorHandler {
-
- @Override
- public void reset() {
- // Do nothing since we do not keep state
- }
-
- @Override
- public void handleErrors(Exchange exchange, org.everit.json.schema.Schema schema, Exception e) throws ValidationException {
- if (e instanceof org.everit.json.schema.ValidationException) {
- throw new JsonSchemaValidationException(exchange, schema, (org.everit.json.schema.ValidationException)e);
- } else {
- throw new JsonSchemaValidationException(exchange, schema, e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
deleted file mode 100644
index ba98478..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
+++ /dev/null
@@ -1,44 +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.everit.jsonschema;
-
-import java.io.InputStream;
-
-import org.apache.camel.CamelContext;
-import org.everit.json.schema.FormatValidator;
-import org.everit.json.schema.Schema;
-
-/**
- * Can be used to create custom schema for the JSON validator endpoint.
- * This interface is useful to add custom {@link FormatValidator} to the {@link Schema}
- *
- * For more information see
- * <a href="https://github.com/everit-org/json-schema#format-validators">Format Validators</a>
- * in the Everit JSON Schema documentation.
- */
-public interface JsonSchemaLoader {
-
- /**
- * Create a new Schema based on the schema input stream.
- *
- * @param camelContext camel context
- * @param schemaInputStream the resource input stream
- * @return a Schema to be used when validating incoming requests
- */
- Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
deleted file mode 100644
index 3b096b0..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
+++ /dev/null
@@ -1,36 +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.everit.jsonschema;
-
-import java.util.stream.Collectors;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ValidationException;
-import org.everit.json.schema.Schema;
-
-public class JsonSchemaValidationException extends ValidationException {
-
- private static final long serialVersionUID = 1L;
-
- public JsonSchemaValidationException(Exchange exchange, Schema schema, org.everit.json.schema.ValidationException e) {
- super(e.getAllMessages().stream().collect(Collectors.joining(", ")), exchange, e);
- }
-
- public JsonSchemaValidationException(Exchange exchange, Schema schema, Exception e) {
- super(e.getMessage(), exchange, e);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
deleted file mode 100644
index 83d97c7..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
+++ /dev/null
@@ -1,35 +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.everit.jsonschema;
-
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.impl.DefaultComponent;
-
-/**
- * The JSON Schema Validator Component is for validating JSON against a schema.
- */
-public class JsonSchemaValidatorComponent extends DefaultComponent {
-
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- JsonSchemaValidatorEndpoint endpoint = new JsonSchemaValidatorEndpoint(uri, this, remaining);
- setProperties(endpoint, parameters);
- return endpoint;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
deleted file mode 100644
index afca7a3..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
+++ /dev/null
@@ -1,201 +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.everit.jsonschema;
-
-import java.io.InputStream;
-
-import org.apache.camel.Component;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.api.management.ManagedResource;
-import org.apache.camel.component.ResourceEndpoint;
-import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-import org.apache.camel.util.IOHelper;
-import org.everit.json.schema.ObjectSchema;
-import org.everit.json.schema.Schema;
-import org.everit.json.schema.ValidationException;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Validates the payload of a message using Everit JSON schema validator.
- */
-@ManagedResource(description = "Managed JsonSchemaValidatorEndpoint")
-@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "validation,json")
-public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
-
- private static final Logger LOG = LoggerFactory.getLogger(JsonSchemaValidatorEndpoint.class);
-
- private volatile Schema schema;
-
- @UriParam(defaultValue = "true")
- private boolean failOnNullBody = true;
- @UriParam(defaultValue = "true")
- private boolean failOnNullHeader = true;
- @UriParam(description = "To validate against a header instead of the message body.")
- private String headerName;
- @UriParam(label = "advanced")
- private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
- @UriParam(label = "advanced")
- private JsonSchemaLoader schemaLoader = new DefaultJsonSchemaLoader();
-
- public JsonSchemaValidatorEndpoint(String endpointUri, Component component, String resourceUri) {
- super(endpointUri, component, resourceUri);
- }
-
- @Override
- public void clearContentCache() {
- this.schema = null;
- super.clearContentCache();
- }
-
- @Override
- public ExchangePattern getExchangePattern() {
- return ExchangePattern.InOut;
- }
-
- @Override
- protected void onExchange(Exchange exchange) throws Exception {
- Object jsonPayload;
- InputStream is = null;
- // Get a local copy of the current schema to improve concurrency.
- Schema localSchema = this.schema;
- if (localSchema == null) {
- localSchema = getOrCreateSchema();
- }
- try {
- is = getContentToValidate(exchange, InputStream.class);
- if (shouldUseHeader()) {
- if (is == null && isFailOnNullHeader()) {
- throw new NoJsonHeaderValidationException(exchange, headerName);
- }
- } else {
- if (is == null && isFailOnNullBody()) {
- throw new NoJsonBodyValidationException(exchange);
- }
- }
- if (is != null) {
- if (schema instanceof ObjectSchema) {
- jsonPayload = new JSONObject(new JSONTokener(is));
- } else {
- jsonPayload = new JSONArray(new JSONTokener(is));
- }
- // throws a ValidationException if this object is invalid
- schema.validate(jsonPayload);
- LOG.debug("JSON is valid");
- }
- } catch (ValidationException | JSONException e) {
- this.errorHandler.handleErrors(exchange, schema, e);
- } finally {
- IOHelper.close(is);
- }
- }
-
- private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
- if (shouldUseHeader()) {
- return exchange.getIn().getHeader(headerName, clazz);
- } else {
- return exchange.getIn().getBody(clazz);
- }
- }
-
- private boolean shouldUseHeader() {
- return headerName != null;
- }
-
- /**
- * Synchronized method to create a schema if is does not already exist.
- *
- * @return The currently loaded schema
- */
- private Schema getOrCreateSchema() throws Exception {
- synchronized (this) {
- if (this.schema == null) {
- this.schema = this.schemaLoader.createSchema(getCamelContext(), this.getResourceAsInputStream());
- }
- }
- return this.schema;
- }
-
- @Override
- protected String createEndpointUri() {
- return "json-validator:" + getResourceUri();
- }
-
- public JsonValidatorErrorHandler getErrorHandler() {
- return errorHandler;
- }
-
- /**
- * To use a custom ValidatorErrorHandler.
- * <p/>
- * The default error handler captures the errors and throws an exception.
- */
- public void setErrorHandler(JsonValidatorErrorHandler errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- public JsonSchemaLoader getSchemaLoader() {
- return schemaLoader;
- }
-
- /**
- * To use a custom schema loader allowing for adding custom format validation. See Everit JSON Schema documentation.
- * The default implementation will create a schema loader builder with draft v6 support.
- */
- public void setSchemaLoader(JsonSchemaLoader schemaLoader) {
- this.schemaLoader = schemaLoader;
- }
-
- public boolean isFailOnNullBody() {
- return failOnNullBody;
- }
-
- /**
- * Whether to fail if no body exists.
- */
- public void setFailOnNullBody(boolean failOnNullBody) {
- this.failOnNullBody = failOnNullBody;
- }
-
- public boolean isFailOnNullHeader() {
- return failOnNullHeader;
- }
-
- /**
- * Whether to fail if no header exists when validating against a header.
- */
- public void setFailOnNullHeader(boolean failOnNullHeader) {
- this.failOnNullHeader = failOnNullHeader;
- }
-
- public String getHeaderName() {
- return headerName;
- }
-
- /**
- * To validate against a header instead of the message body.
- */
- public void setHeaderName(String headerName) {
- this.headerName = headerName;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
deleted file mode 100644
index 2657d6f..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
+++ /dev/null
@@ -1,39 +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.everit.jsonschema;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ValidationException;
-
-public interface JsonValidatorErrorHandler {
-
- /**
- * Resets any state within this error handler
- */
- void reset();
-
- /**
- * Process any errors which may have occurred during validation
- *
- * @param exchange the exchange
- * @param schema the schema
- * @param e the exception triggering the error
- * @throws ValidationException is thrown in case of validation errors
- */
- void handleErrors(Exchange exchange, org.everit.json.schema.Schema schema, Exception e) throws ValidationException;
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
deleted file mode 100644
index 0e7f4fc..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
+++ /dev/null
@@ -1,35 +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.everit.jsonschema;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ValidationException;
-
-/**
- * An exception found if no JSON body is available on the inbound message
- */
-public class NoJsonBodyValidationException extends ValidationException {
- private static final long serialVersionUID = 4502520681354358599L;
-
- public NoJsonBodyValidationException(Exchange exchange) {
- super(exchange, "No JSON body could be found on the input message");
- }
-
- public NoJsonBodyValidationException(Exchange exchange, Throwable cause) {
- super("No JSON body could be found on the input message", exchange, cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
deleted file mode 100644
index 79c05dc..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
+++ /dev/null
@@ -1,36 +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.everit.jsonschema;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ValidationException;
-
-/**
- * An exception found if no JSON body is available on the inbound message
- */
-public class NoJsonHeaderValidationException extends ValidationException {
- private static final long serialVersionUID = 4502520681354358599L;
-
- public NoJsonHeaderValidationException(Exchange exchange, String header) {
- this(exchange, header, null);
- }
-
- public NoJsonHeaderValidationException(Exchange exchange, String header, Throwable cause) {
- super("No JSON header \"" + header + "\" could be found on the input message", exchange, cause);
- }
-}
-
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
deleted file mode 100644
index 23a5ab3..0000000
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
+++ /dev/null
@@ -1,25 +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.
--->
-<html>
-<head>
-</head>
-<body>
-
-The JSON Schema Validator Component for validating JSON against a JSON schema.
-
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt b/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt
deleted file mode 100755
index 6b0b127..0000000
--- a/components/camel-everit-json-schema/src/main/resources/META-INF/LICENSE.txt
+++ /dev/null
@@ -1,203 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed 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.
-
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt b/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt
deleted file mode 100644
index 2e215bf..0000000
--- a/components/camel-everit-json-schema/src/main/resources/META-INF/NOTICE.txt
+++ /dev/null
@@ -1,11 +0,0 @@
- =========================================================================
- == NOTICE file corresponding to the section 4 d of ==
- == the Apache License, Version 2.0, ==
- == in this case for the Apache Camel distribution. ==
- =========================================================================
-
- This product includes software developed by
- The Apache Software Foundation (http://www.apache.org/).
-
- Please read the different LICENSE files present in the licenses directory of
- this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator b/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
deleted file mode 100644
index 447b785..0000000
--- a/components/camel-everit-json-schema/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
+++ /dev/null
@@ -1,18 +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.
-#
-
-class=org.apache.camel.component.everit.jsonschema.JsonSchemaValidatorComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java
deleted file mode 100644
index 198c1ef..0000000
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java
+++ /dev/null
@@ -1,84 +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.everit.jsonschema;
-
-import org.apache.camel.EndpointInject;
-import org.apache.camel.ValidationException;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.impl.JndiRegistry;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class CustomSchemaLoaderValidatorRouteTest extends CamelTestSupport {
-
- @EndpointInject(uri = "mock:valid")
- protected MockEndpoint validEndpoint;
-
- @EndpointInject(uri = "mock:finally")
- protected MockEndpoint finallyEndpoint;
-
- @EndpointInject(uri = "mock:invalid")
- protected MockEndpoint invalidEndpoint;
-
- @Test
- public void testValidMessage() throws Exception {
- validEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBody("direct:start",
- "{ \"name\": \"Even Joe\", \"id\": 1, \"price\": 12.5 }");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Test
- public void testInvalidMessage() throws Exception {
- invalidEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBody("direct:start",
- "{ \"name\": \"Odd Joe\", \"id\": 1, \"price\": 12.5 }");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry jndiRegistry = super.createRegistry();
- jndiRegistry.bind("customSchemaLoader", new TestCustomSchemaLoader());
- return jndiRegistry;
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .doTry()
- .to("json-validator:org/apache/camel/component/everit/jsonschema/schemawithformat.json?schemaLoader=#customSchemaLoader")
- .to("mock:valid")
- .doCatch(ValidationException.class)
- .to("mock:invalid")
- .doFinally()
- .to("mock:finally")
- .end();
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
deleted file mode 100644
index 578aa19..0000000
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
+++ /dev/null
@@ -1,38 +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.everit.jsonschema;
-
-import java.util.Optional;
-
-import org.everit.json.schema.FormatValidator;
-
-public class EvenCharNumValidator implements FormatValidator {
-
- @Override
- public Optional<String> validate(final String subject) {
- if (subject.length() % 2 == 0) {
- return Optional.empty();
- } else {
- return Optional.of(String.format("the length of string [%s] is odd", subject));
- }
- }
-
- @Override
- public String formatName() {
- return "evenlength";
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
deleted file mode 100644
index 4cdfb27..0000000
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
+++ /dev/null
@@ -1,94 +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.everit.jsonschema;
-
-import java.io.File;
-
-import org.apache.camel.Exchange;
-import org.apache.camel.ValidationException;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.camel.util.FileUtil;
-import org.junit.Before;
-import org.junit.Test;
-
-public class FileValidatorRouteTest extends CamelTestSupport {
-
- protected MockEndpoint validEndpoint;
- protected MockEndpoint finallyEndpoint;
- protected MockEndpoint invalidEndpoint;
-
- @Test
- public void testValidMessage() throws Exception {
- validEndpoint.expectedMessageCount(1);
- invalidEndpoint.expectedMessageCount(0);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBodyAndHeader("file:target/validator",
- "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }",
- Exchange.FILE_NAME, "valid.json");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
-
- assertTrue("Should be able to delete the file", FileUtil.deleteFile(new File("target/validator/valid.json")));
- }
-
- @Test
- public void testInvalidMessage() throws Exception {
- validEndpoint.expectedMessageCount(0);
- invalidEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBodyAndHeader("file:target/validator",
- "{ \"name\": \"Joe Doe\", \"id\": \"AA1\", \"price\": 12.5 }",
- Exchange.FILE_NAME, "invalid.json");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
-
- // should be able to delete the file
- assertTrue("Should be able to delete the file", FileUtil.deleteFile(new File("target/validator/invalid.json")));
- }
-
- @Before
- public void setUp() throws Exception {
- deleteDirectory("target/validator");
- super.setUp();
- validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class);
- invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
- finallyEndpoint = resolveMandatoryEndpoint("mock:finally", MockEndpoint.class);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("file:target/validator?noop=true")
- .doTry()
- .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json")
- .to("mock:valid")
- .doCatch(ValidationException.class)
- .to("mock:invalid")
- .doFinally()
- .to("mock:finally")
- .end();
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
deleted file mode 100644
index b90d9a3..0000000
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
+++ /dev/null
@@ -1,42 +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.everit.jsonschema;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import org.apache.camel.CamelContext;
-import org.everit.json.schema.Schema;
-import org.everit.json.schema.loader.SchemaLoader;
-import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-
-public class TestCustomSchemaLoader implements JsonSchemaLoader {
-
- @Override
- public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
-
- SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
-
- try (InputStream inputStream = schemaInputStream) {
- JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
- return schemaLoaderBuilder.schemaJson(rawSchema).addFormatValidator(new EvenCharNumValidator()).build().load().build();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java
deleted file mode 100644
index fb41490..0000000
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/ValidatorRouteTest.java
+++ /dev/null
@@ -1,174 +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.everit.jsonschema;
-
-import org.apache.camel.EndpointInject;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.ValidationException;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Test;
-
-public class ValidatorRouteTest extends CamelTestSupport {
-
- @EndpointInject(uri = "mock:valid")
- protected MockEndpoint validEndpoint;
-
- @EndpointInject(uri = "mock:finally")
- protected MockEndpoint finallyEndpoint;
-
- @EndpointInject(uri = "mock:invalid")
- protected MockEndpoint invalidEndpoint;
-
- @Test
- public void testValidMessage() throws Exception {
- validEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBody("direct:start",
- "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Test
- public void testValidMessageInHeader() throws Exception {
- validEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBodyAndHeader("direct:startHeaders",
- null,
- "headerToValidate",
- "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Test
- public void testInvalidMessage() throws Exception {
- invalidEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBody("direct:start",
- "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Test
- public void testInvalidMessageInHeader() throws Exception {
- invalidEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBodyAndHeader("direct:startHeaders",
- null,
- "headerToValidate",
- "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }");
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Test
- public void testNullHeaderNoFail() throws Exception {
- validEndpoint.expectedMessageCount(1);
-
- template.sendBodyAndHeader("direct:startNullHeaderNoFail", null, "headerToValidate", null);
-
- MockEndpoint.assertIsSatisfied(validEndpoint);
- }
-
- @Test
- public void testNullHeader() throws Exception {
- validEndpoint.setExpectedMessageCount(0);
-
- Exchange in = resolveMandatoryEndpoint("direct:startNoHeaderException").createExchange(ExchangePattern.InOut);
-
- in.getIn().setBody(null);
- in.getIn().setHeader("headerToValidate", null);
-
- Exchange out = template.send("direct:startNoHeaderException", in);
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
-
- Exception exception = out.getException();
- assertTrue("Should be failed", out.isFailed());
- assertTrue("Exception should be correct type", exception instanceof NoJsonHeaderValidationException);
- assertTrue("Exception should mention missing header", exception.getMessage().contains("headerToValidate"));
- }
-
- @Test
- public void testInvalideBytesMessage() throws Exception {
- invalidEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBody("direct:start",
- "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }".getBytes());
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Test
- public void testInvalidBytesMessageInHeader() throws Exception {
- invalidEndpoint.expectedMessageCount(1);
- finallyEndpoint.expectedMessageCount(1);
-
- template.sendBodyAndHeader("direct:startHeaders",
- null,
- "headerToValidate",
- "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }".getBytes());
-
- MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- from("direct:start")
- .doTry()
- .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json")
- .to("mock:valid")
- .doCatch(ValidationException.class)
- .to("mock:invalid")
- .doFinally()
- .to("mock:finally")
- .end();
-
- from("direct:startHeaders")
- .doTry()
- .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json?headerName=headerToValidate")
- .to("mock:valid")
- .doCatch(ValidationException.class)
- .to("mock:invalid")
- .doFinally()
- .to("mock:finally")
- .end();
-
- from("direct:startNoHeaderException")
- .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json?headerName=headerToValidate")
- .to("mock:valid");
-
- from("direct:startNullHeaderNoFail")
- .to("json-validator:org/apache/camel/component/everit/jsonschema/schema.json?headerName=headerToValidate&failOnNullHeader=false")
- .to("mock:valid");
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/log4j2.properties b/components/camel-everit-json-schema/src/test/resources/log4j2.properties
deleted file mode 100644
index 52a78c2..0000000
--- a/components/camel-everit-json-schema/src/test/resources/log4j2.properties
+++ /dev/null
@@ -1,29 +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.
-## ---------------------------------------------------------------------------
-
-appender.file.type = File
-appender.file.name = file
-appender.file.fileName = target/camel-everit-json-schema-test.log
-appender.file.layout.type = PatternLayout
-appender.file.layout.pattern = %d %-5p %c{1} - %m %n
-appender.out.type = Console
-appender.out.name = out
-appender.out.layout.type = PatternLayout
-appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
-rootLogger.level = INFO
-rootLogger.appenderRef.file.ref = file
-
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
deleted file mode 100644
index 021640d..0000000
--- a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schema.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "$schema": "http://json-schema.org/draft-06/schema#",
- "definitions": {},
- "id": "http://example.com/example.json",
- "properties": {
- "id": {
- "default": 1,
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/id",
- "title": "The id schema",
- "type": "integer"
- },
- "name": {
- "default": "A green door",
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/name",
- "title": "The name schema",
- "type": "string"
- },
- "price": {
- "default": 12.5,
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/price",
- "title": "The price schema",
- "type": "number"
- }
- },
- "required": [
- "name",
- "id",
- "price"
- ],
- "type": "object"
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
deleted file mode 100644
index a365115..0000000
--- a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
+++ /dev/null
@@ -1,35 +0,0 @@
-{
- "$schema": "http://json-schema.org/draft-06/schema#",
- "definitions": {},
- "id": "http://example.com/example.json",
- "properties": {
- "id": {
- "default": 1,
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/id",
- "title": "The id schema",
- "type": "integer"
- },
- "name": {
- "default": "A green door",
- "description": "An explanation about the purpose of this instance. Must have even number of characters",
- "id": "/properties/name",
- "title": "The name schema",
- "type": "string",
- "format": "evenlength"
- },
- "price": {
- "default": 12.5,
- "description": "An explanation about the purpose of this instance.",
- "id": "/properties/price",
- "title": "The price schema",
- "type": "number"
- }
- },
- "required": [
- "name",
- "id",
- "price"
- ],
- "type": "object"
-}
\ No newline at end of file
[06/14] camel git commit: CAMEL-9799: Polished.
Posted by da...@apache.org.
CAMEL-9799: Polished.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5ac52a93
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5ac52a93
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5ac52a93
Branch: refs/heads/master
Commit: 5ac52a93229bf4b70c37ad1f70a994ebe8f3d282
Parents: 2712739
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 09:44:28 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 09:44:28 2017 +0200
----------------------------------------------------------------------
components/camel-everit-json-schema/pom.xml | 133 ++++++++++---------
.../src/main/docs/json-validator-component.adoc | 38 +++---
.../jsonschema/DefaultJsonSchemaLoader.java | 6 +-
.../DefaultJsonValidationErrorHandler.java | 8 +-
.../everit/jsonschema/JsonSchemaLoader.java | 2 +-
.../JsonSchemaValidationException.java | 11 +-
.../JsonSchemaValidatorComponent.java | 2 -
.../jsonschema/JsonSchemaValidatorEndpoint.java | 38 +++---
.../jsonschema/JsonValidatorErrorHandler.java | 1 +
.../NoJsonBodyValidationException.java | 2 -
.../NoJsonHeaderValidationException.java | 2 -
.../everit/jsonschema/EvenCharNumValidator.java | 28 +++-
.../jsonschema/FileValidatorRouteTest.java | 3 -
.../jsonschema/TestCustomSchemaLoader.java | 30 +++--
.../src/test/resources/log4j2.properties | 8 +-
15 files changed, 151 insertions(+), 161 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/pom.xml b/components/camel-everit-json-schema/pom.xml
index 9d7938d..b913a3c 100644
--- a/components/camel-everit-json-schema/pom.xml
+++ b/components/camel-everit-json-schema/pom.xml
@@ -14,76 +14,77 @@
the specific language governing permissions and limitations under the
License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components</artifactId>
- <version>2.20.0-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.20.0-SNAPSHOT</version>
+ </parent>
- <artifactId>camel-everit-json-schema</artifactId>
- <name>Camel :: Everit Kft. JSON Schema validator</name>
- <description>Camel JSON Schema validation based on everit-org json-schema library</description>
- <packaging>jar</packaging>
+ <artifactId>camel-everit-json-schema</artifactId>
+ <name>Camel :: Everit JSON Schema validator</name>
+ <description>Camel JSON Schema validation based on Everit JSON-schema library</description>
+ <packaging>jar</packaging>
- <properties>
- <camel.osgi.export.pkg>org.apache.camel.component.everit.jsonschema.*</camel.osgi.export.pkg>
- <camel.osgi.export.service>org.apache.camel.spi.ComponentResolver;component=json-validator</camel.osgi.export.service>
- </properties>
- <repositories>
- <repository>
- <id>jitpack.io</id>
- <url>https://jitpack.io</url>
- </repository>
- </repositories>
- <dependencies>
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.everit.jsonschema.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>
+ org.apache.camel.spi.ComponentResolver;component=json-validator
+ </camel.osgi.export.service>
+ </properties>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core</artifactId>
- </dependency>
- <dependency>
- <groupId>com.github.everit-org.json-schema</groupId>
- <artifactId>org.everit.json.schema</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- </dependency>
+ <!-- everit is distributed in jitpack and not Maven central -->
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ </repositories>
+ <dependencies>
- <!-- for testing -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-api</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-slf4j-impl</artifactId>
- <scope>test</scope>
- </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.github.everit-org.json-schema</groupId>
+ <artifactId>org.everit.json.schema</artifactId>
+ </dependency>
- </dependencies>
+ <!-- for testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
index 9bcca3d..b7b124b 100644
--- a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
+++ b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
@@ -1,7 +1,6 @@
== JSON Schema Validator Component
-=== Everit Json Schema Validator Component
-*Available as of Camel version 2.21*
+*Available as of Camel version 2.20*
The JSON Schema Validator component performs bean validation of the message body
agains JSON Schemas using the Everit.org JSON Schema library
@@ -11,22 +10,22 @@ Maven users will need to add the following dependency to their `pom.xml`
for this component:
[source,xml]
-------------------------------------------------------------
+----
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-everit-json-schema</artifactId>
<version>x.y.z</version>
<!-- use the same version as your Camel core version -->
</dependency>
-------------------------------------------------------------
+----
=== URI format
-[source,java]
-------------------------------
+[source]
+----
json-validator:resourceUri[?options]
-------------------------------
+----
Where *resourceUri* is some URL to a local resource on the classpath or a
@@ -67,8 +66,8 @@ with the following path and query parameters:
| *failOnNullBody* (producer) | Whether to fail if no body exists. | true | boolean
| *failOnNullHeader* (producer) | Whether to fail if no header exists when validating against a header. | true | boolean
| *headerName* (producer) | To validate against a header instead of the message body. | | String
-| *errorHandler* (advanced) | To use a custom org.apache.camel.processor.validation.ValidatorErrorHandler. The default error handler captures the errors and throws an exception. | | JsonValidatorError Handler
-| *schemaLoader* (advanced) | To use a custom schema loader allowing for adding custom format validation. See the Everit JSON Schema documentation. The default implementation will create a schema loader builder with draft v6 support. | | JsonSchemaLoader
+| *errorHandler* (advanced) | To use a custom ValidatorErrorHandler. The default error handler captures the errors and throws an exception. | | JsonValidatorError Handler
+| *schemaLoader* (advanced) | To use a custom schema loader allowing for adding custom format validation. See Everit JSON Schema documentation. The default implementation will create a schema loader builder with draft v6 support. | | JsonSchemaLoader
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
|===
// endpoint options: END
@@ -78,10 +77,10 @@ with the following path and query parameters:
Assumed we have the following JSON Schema
-*schema.json*
+*myschema.json*
[source,json]
------------------------------------------------------------
+----
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
@@ -116,22 +115,15 @@ Assumed we have the following JSON Schema
],
"type": "object"
}
------------------------------------------------------------
+----
-we can validate incoming JSON with the following Camel route.
+we can validate incoming JSON with the following Camel route, where `myschema.json` is loaded from the classpath.
[source,java]
--------------------------
+----
from("direct:start")
- .to("json-validator:schema.json")
+ .to("json-validator:myschema.json")
.to("mock:end")
--------------------------
-
---------------------------------------------------------------------------------------------------
+----
-=== See Also
-* link:configuring-camel.html[Configuring Camel]
-* link:component.html[Component]
-* link:endpoint.html[Endpoint]
-* link:getting-started.html[Getting Started]
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
index 605fcd0..97e25c7 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
@@ -26,15 +26,11 @@ import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
import org.json.JSONObject;
import org.json.JSONTokener;
-
-public class DefaultJsonSchemaLoader implements
- JsonSchemaLoader {
+public class DefaultJsonSchemaLoader implements JsonSchemaLoader {
@Override
public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
-
SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
-
try (InputStream inputStream = schemaInputStream) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
return schemaLoaderBuilder.schemaJson(rawSchema).build().load().build();
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
index b6ef7c2..5978f3a 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonValidationErrorHandler.java
@@ -19,8 +19,7 @@ package org.apache.camel.component.everit.jsonschema;
import org.apache.camel.Exchange;
import org.apache.camel.ValidationException;
-public class DefaultJsonValidationErrorHandler implements
- JsonValidatorErrorHandler {
+public class DefaultJsonValidationErrorHandler implements JsonValidatorErrorHandler {
@Override
public void reset() {
@@ -28,10 +27,7 @@ public class DefaultJsonValidationErrorHandler implements
}
@Override
- public void handleErrors(Exchange exchange,
- org.everit.json.schema.Schema schema,
- Exception e)
- throws ValidationException {
+ public void handleErrors(Exchange exchange, org.everit.json.schema.Schema schema, Exception e) throws ValidationException {
if (e instanceof org.everit.json.schema.ValidationException) {
throw new JsonSchemaValidationException(exchange, schema, (org.everit.json.schema.ValidationException)e);
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
index 4bab6a8..ba98478 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
@@ -34,10 +34,10 @@ public interface JsonSchemaLoader {
/**
* Create a new Schema based on the schema input stream.
+ *
* @param camelContext camel context
* @param schemaInputStream the resource input stream
* @return a Schema to be used when validating incoming requests
- * @throws Exception if
*/
Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws Exception;
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
index ade36d5..3b096b0 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidationException.java
@@ -26,16 +26,11 @@ public class JsonSchemaValidationException extends ValidationException {
private static final long serialVersionUID = 1L;
- public JsonSchemaValidationException(Exchange exchange, Schema schema,
- org.everit.json.schema.ValidationException e) {
- super(e.getAllMessages().stream().collect(Collectors.joining(", ")),
- exchange,
- e
- );
+ public JsonSchemaValidationException(Exchange exchange, Schema schema, org.everit.json.schema.ValidationException e) {
+ super(e.getAllMessages().stream().collect(Collectors.joining(", ")), exchange, e);
}
- public JsonSchemaValidationException(Exchange exchange, Schema schema,
- Exception e) {
+ public JsonSchemaValidationException(Exchange exchange, Schema schema, Exception e) {
super(e.getMessage(), exchange, e);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
index ebf626b..83d97c7 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
@@ -23,8 +23,6 @@ import org.apache.camel.impl.DefaultComponent;
/**
* The JSON Schema Validator Component is for validating JSON against a schema.
- *
- * @version
*/
public class JsonSchemaValidatorComponent extends DefaultComponent {
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
index 80d1d32..4fa04d0 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.everit.jsonschema;
-import java.io.IOException;
import java.io.InputStream;
import org.apache.camel.Component;
@@ -37,30 +36,28 @@ import org.json.JSONTokener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Validates the payload of a message using XML Schema and JAXP Validation.
*/
-@ManagedResource(description = "Managed JSON ValidatorEndpoint")
-@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "core,validation")
+@ManagedResource(description = "Managed JsonSchemaValidatorEndpoint")
+@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "validation,json")
public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
private static final Logger LOG = LoggerFactory.getLogger(JsonSchemaValidatorEndpoint.class);
-
- @UriParam(label = "advanced", description = "To use a custom org.apache.camel.component.everit.jsonschema.JsonValidatorErrorHandler. "
- + "The default error handler captures the errors and throws an exception.")
- private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
- @UriParam(label = "advanced", description = "To use a custom schema loader allowing for adding custom format validation. See the Everit JSON Schema documentation.")
- private JsonSchemaLoader schemaLoader = new DefaultJsonSchemaLoader();
- @UriParam(defaultValue = "true", description = "Whether to fail if no body exists.")
+
+ private volatile Schema schema;
+
+ @UriParam(defaultValue = "true")
private boolean failOnNullBody = true;
- @UriParam(defaultValue = "true", description = "Whether to fail if no header exists when validating against a header.")
+ @UriParam(defaultValue = "true")
private boolean failOnNullHeader = true;
@UriParam(description = "To validate against a header instead of the message body.")
private String headerName;
-
- private Schema schema;
-
+ @UriParam(label = "advanced")
+ private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
+ @UriParam(label = "advanced")
+ private JsonSchemaLoader schemaLoader = new DefaultJsonSchemaLoader();
+
public JsonSchemaValidatorEndpoint(String endpointUri, Component component, String resourceUri) {
super(endpointUri, component, resourceUri);
}
@@ -78,7 +75,7 @@ public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
@Override
protected void onExchange(Exchange exchange) throws Exception {
- Object jsonPayload = null;
+ Object jsonPayload;
InputStream is = null;
// Get a local copy of the current schema to improve concurrency.
Schema localSchema = this.schema;
@@ -106,9 +103,7 @@ public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
schema.validate(jsonPayload);
LOG.debug("JSON is valid");
}
- } catch (ValidationException e) {
- this.errorHandler.handleErrors(exchange, schema, e);
- } catch (JSONException e) {
+ } catch (ValidationException | JSONException e) {
this.errorHandler.handleErrors(exchange, schema, e);
} finally {
IOHelper.close(is);
@@ -131,7 +126,6 @@ public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
* Synchronized method to create a schema if is does not already exist.
*
* @return The currently loaded schema
- * @throws IOException
*/
private Schema getOrCreateSchema() throws Exception {
synchronized (this) {
@@ -152,7 +146,7 @@ public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
}
/**
- * To use a custom org.apache.camel.processor.validation.ValidatorErrorHandler.
+ * To use a custom ValidatorErrorHandler.
* <p/>
* The default error handler captures the errors and throws an exception.
*/
@@ -165,7 +159,7 @@ public class JsonSchemaValidatorEndpoint extends ResourceEndpoint {
}
/**
- * To use a custom schema loader allowing for adding custom format validation. See the Everit JSON Schema documentation.
+ * To use a custom schema loader allowing for adding custom format validation. See Everit JSON Schema documentation.
* The default implementation will create a schema loader builder with draft v6 support.
*/
public void setSchemaLoader(JsonSchemaLoader schemaLoader) {
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
index 4594e97..2657d6f 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatorErrorHandler.java
@@ -20,6 +20,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.ValidationException;
public interface JsonValidatorErrorHandler {
+
/**
* Resets any state within this error handler
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
index 3000579..0e7f4fc 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonBodyValidationException.java
@@ -21,8 +21,6 @@ import org.apache.camel.ValidationException;
/**
* An exception found if no JSON body is available on the inbound message
- *
- * @version
*/
public class NoJsonBodyValidationException extends ValidationException {
private static final long serialVersionUID = 4502520681354358599L;
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
index 582a685..79c05dc 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/NoJsonHeaderValidationException.java
@@ -21,8 +21,6 @@ import org.apache.camel.ValidationException;
/**
* An exception found if no JSON body is available on the inbound message
- *
- * @version
*/
public class NoJsonHeaderValidationException extends ValidationException {
private static final long serialVersionUID = 4502520681354358599L;
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
index 876f55e..578aa19 100644
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
@@ -1,3 +1,19 @@
+/**
+ * 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.everit.jsonschema;
import java.util.Optional;
@@ -8,15 +24,15 @@ public class EvenCharNumValidator implements FormatValidator {
@Override
public Optional<String> validate(final String subject) {
- if (subject.length() % 2 == 0) {
- return Optional.empty();
- } else {
- return Optional.of(String.format("the length of string [%s] is odd", subject));
- }
+ if (subject.length() % 2 == 0) {
+ return Optional.empty();
+ } else {
+ return Optional.of(String.format("the length of string [%s] is odd", subject));
+ }
}
@Override
public String formatName() {
return "evenlength";
}
- }
\ No newline at end of file
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
index 2979326..4cdfb27 100644
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/FileValidatorRouteTest.java
@@ -27,9 +27,6 @@ import org.apache.camel.util.FileUtil;
import org.junit.Before;
import org.junit.Test;
-/**
- *
- */
public class FileValidatorRouteTest extends CamelTestSupport {
protected MockEndpoint validEndpoint;
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
index 1bd9260..b90d9a3 100644
--- a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
@@ -1,3 +1,19 @@
+/**
+ * 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.everit.jsonschema;
import java.io.IOException;
@@ -13,19 +29,13 @@ import org.json.JSONTokener;
public class TestCustomSchemaLoader implements JsonSchemaLoader {
@Override
- public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream)
- throws IOException {
-
+ public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
+
SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
-
+
try (InputStream inputStream = schemaInputStream) {
JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
- return schemaLoaderBuilder
- .schemaJson(rawSchema)
- .addFormatValidator(new EvenCharNumValidator())
- .build()
- .load()
- .build();
+ return schemaLoaderBuilder.schemaJson(rawSchema).addFormatValidator(new EvenCharNumValidator()).build().load().build();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/5ac52a93/components/camel-everit-json-schema/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/log4j2.properties b/components/camel-everit-json-schema/src/test/resources/log4j2.properties
index 9374f09..52a78c2 100644
--- a/components/camel-everit-json-schema/src/test/resources/log4j2.properties
+++ b/components/camel-everit-json-schema/src/test/resources/log4j2.properties
@@ -6,7 +6,7 @@
## (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
+## 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,
@@ -17,15 +17,13 @@
appender.file.type = File
appender.file.name = file
-appender.file.fileName = target/camel-json-validator-test.log
+appender.file.fileName = target/camel-everit-json-schema-test.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d %-5p %c{1} - %m %n
appender.out.type = Console
appender.out.name = out
appender.out.layout.type = PatternLayout
appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
-logger.springframework.name = org.springframework
-logger.springframework.level = WARN
rootLogger.level = INFO
rootLogger.appenderRef.file.ref = file
-rootLogger.appenderRef.out.ref = out
+
[03/14] camel git commit: Improved JSON schema loading making it
possible for injecting custom schema loader.
Posted by da...@apache.org.
Improved JSON schema loading making it possible for injecting custom schema loader.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/923f1267
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/923f1267
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/923f1267
Branch: refs/heads/master
Commit: 923f12675eab496083cd69efd424001672d631bd
Parents: 8ba38cf
Author: Pontus Ullgren <ul...@gmail.com>
Authored: Wed Oct 4 01:10:22 2017 +0200
Committer: Pontus Ullgren <po...@redpill-linpro.com>
Committed: Fri Oct 6 22:37:42 2017 +0200
----------------------------------------------------------------------
.../src/main/docs/json-validator-component.adoc | 18 +++--
.../jsonschema/DefaultJsonSchemaLoader.java | 45 +++++++++++
.../everit/jsonschema/JsonSchemaLoader.java | 28 +++++++
.../everit/jsonschema/JsonSchemaReader.java | 36 +++++++++
.../JsonSchemaValidatorComponent.java | 13 +--
.../jsonschema/JsonSchemaValidatorEndpoint.java | 49 ++++++------
.../jsonschema/JsonValidatingProcessor.java | 8 +-
.../component/everit/jsonschema/package.html | 2 +-
.../CustomSchemaLoaderValidatorRouteTest.java | 84 ++++++++++++++++++++
.../everit/jsonschema/EvenCharNumValidator.java | 22 +++++
.../jsonschema/TestCustomSchemaLoader.java | 33 ++++++++
.../everit/jsonschema/schemawithformat.json | 35 ++++++++
12 files changed, 325 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
index 2f10a7b..7097e04 100644
--- a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
+++ b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
@@ -1,9 +1,11 @@
== JSON Schema Validator Component
=== Everit Json Schema Validator Component
+*Available as of Camel version *
+
*Available as of Camel version 2.20*
-The Validator component performs bean validation of the message body
+The JSON Schema Validator component performs bean validation of the message body
agains JSON Schemas using the Everit.org JSON Schema library
(https://github.com/everit-org/json-schema).
@@ -29,13 +31,12 @@ json-validator:resourceUri[?options]
------------------------------
-Where *label* is an arbitrary text value describing the endpoint. +
- You can append query options to the URI in the following format,
-?option=value&option=value&...
-
+Where *resourceUri* is some URL to a local resource on the classpath or a
+full URL to a remote resource or resource on the file system which contains
+the JSON Schema to validate against.
+
=== URI Options
-
// component options: START
The JSON Schema Validator component has no options.
// component options: END
@@ -59,7 +60,7 @@ with the following path and query parameters:
| *resourceUri* | *Required* URL to a local resource on the classpath or a reference to lookup a bean in the Registry or a full URL to a remote resource or resource on the file system which contains the JSON Schema to validate against. | | String
|===
-==== Query Parameters (5 parameters):
+==== Query Parameters (6 parameters):
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -68,6 +69,7 @@ with the following path and query parameters:
| *failOnNullHeader* (producer) | Whether to fail if no header exists when validating against a header. | true | boolean
| *headerName* (producer) | To validate against a header instead of the message body. | | String
| *errorHandler* (advanced) | To use a custom org.apache.camel.processor.validation.ValidatorErrorHandler. The default error handler captures the errors and throws an exception. | | JsonValidatorError Handler
+| *schemaLoader* (advanced) | To use a custom schema loader allowing for adding custom format validation. See the Everit JSON Schema documentation. The default implementation will create a schema loader builder with draft v6 support. | | JsonSchemaLoader
| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
|===
// endpoint options: END
@@ -117,7 +119,7 @@ Assumed we have the following JSON Schema
}
-----------------------------------------------------------
-we can validate incomming JSON with the following Camel route.
+we can validate incoming JSON with the following Camel route.
[source,java]
-------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
new file mode 100644
index 0000000..8548f6e
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/DefaultJsonSchemaLoader.java
@@ -0,0 +1,45 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ResourceHelper;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.loader.SchemaLoader;
+import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+
+public class DefaultJsonSchemaLoader implements
+ JsonSchemaLoader {
+
+ @Override
+ public Schema createSchema(CamelContext camelContext, String resourceUri) throws IOException {
+
+ SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
+
+ try (InputStream inputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, resourceUri)) {
+ JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
+ return schemaLoaderBuilder.schemaJson(rawSchema).build().load().build();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
new file mode 100644
index 0000000..bd7998b
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaLoader.java
@@ -0,0 +1,28 @@
+/**
+ * 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.everit.jsonschema;
+
+import java.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.everit.json.schema.Schema;
+
+public interface JsonSchemaLoader {
+
+ Schema createSchema(CamelContext camelContext, String resourceUri) throws IOException;
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
new file mode 100644
index 0000000..1f76f67
--- /dev/null
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaReader.java
@@ -0,0 +1,36 @@
+package org.apache.camel.component.everit.jsonschema;
+
+import java.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ObjectHelper;
+import org.everit.json.schema.Schema;
+
+public class JsonSchemaReader {
+ private Schema schema;
+
+ private final CamelContext camelContext;
+ private final String resourceUri;
+ private final JsonSchemaLoader schemaLoader;
+
+ public JsonSchemaReader(CamelContext camelContext, String resourceUri, JsonSchemaLoader schemaLoader) {
+ ObjectHelper.notNull(camelContext, "camelContext");
+ ObjectHelper.notNull(resourceUri, "resourceUri");
+ ObjectHelper.notNull(schemaLoader, "schemaLoader");
+
+ this.camelContext = camelContext;
+ this.resourceUri = resourceUri;
+ this.schemaLoader = schemaLoader;
+ }
+
+ public Schema getSchema() throws IOException {
+ if ( this.schema == null ) {
+ this.schema = this.schemaLoader.createSchema(this.camelContext, this.resourceUri);
+ }
+ return schema;
+ }
+
+ public void setSchema(Schema schema) {
+ this.schema = schema;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
index 61cdd05..ebf626b 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorComponent.java
@@ -19,23 +19,14 @@ package org.apache.camel.component.everit.jsonschema;
import java.util.Map;
import org.apache.camel.Endpoint;
-import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.impl.DefaultComponent;
/**
* The JSON Schema Validator Component is for validating JSON against a schema.
*
* @version
*/
-public class JsonSchemaValidatorComponent extends UriEndpointComponent {
-
- public JsonSchemaValidatorComponent() {
- this(JsonSchemaValidatorEndpoint.class);
- }
-
- public JsonSchemaValidatorComponent(Class<? extends Endpoint> endpointClass) {
- super(endpointClass);
- }
-
+public class JsonSchemaValidatorComponent extends DefaultComponent {
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
JsonSchemaValidatorEndpoint endpoint = new JsonSchemaValidatorEndpoint(uri, this, remaining);
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
index ea0db62..dd05a33 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonSchemaValidatorEndpoint.java
@@ -16,9 +16,6 @@
*/
package org.apache.camel.component.everit.jsonschema;
-import java.io.IOException;
-import java.io.InputStream;
-
import org.apache.camel.Component;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
@@ -30,12 +27,6 @@ import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
-import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.ResourceHelper;
-import org.everit.json.schema.Schema;
-import org.everit.json.schema.loader.SchemaLoader;
-import org.json.JSONObject;
-import org.json.JSONTokener;
/**
@@ -52,46 +43,42 @@ public class JsonSchemaValidatorEndpoint extends DefaultEndpoint {
@UriParam(label = "advanced", description = "To use a custom org.apache.camel.component.everit.jsonschema.JsonValidatorErrorHandler. "
+ "The default error handler captures the errors and throws an exception.")
private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
+ @UriParam(label = "advanced", description = "To use a custom schema loader allowing for adding custom format validation. See the Everit JSON Schema documentation.")
+ private JsonSchemaLoader schemaLoader = new DefaultJsonSchemaLoader();
@UriParam(defaultValue = "true", description = "Whether to fail if no body exists.")
private boolean failOnNullBody = true;
@UriParam(defaultValue = "true", description = "Whether to fail if no header exists when validating against a header.")
private boolean failOnNullHeader = true;
@UriParam(description = "To validate against a header instead of the message body.")
private String headerName;
+
/**
- * We need a one-to-one relation between endpoint and a Schema
+ * We need a one-to-one relation between endpoint and a JsonSchemaReader
* to be able to clear the cached schema. See method
* {@link #clearCachedSchema}.
*/
- private Schema schema;
+ private JsonSchemaReader schemaReader;
public JsonSchemaValidatorEndpoint(String endpointUri, Component component, String resourceUri) {
super(endpointUri, component);
this.resourceUri = resourceUri;
}
- private Schema loadSchema() throws IOException {
- ObjectHelper.notNull(getCamelContext(), "camelContext");
- ObjectHelper.notNull(this.resourceUri, "resourceUri");
- try (InputStream inputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(getCamelContext(), this.resourceUri)) {
- JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
- // LOG.debug("JSON schema: {}", rawSchema);
- return SchemaLoader.load(rawSchema);
- }
- }
-
+
@ManagedOperation(description = "Clears the cached schema, forcing to re-load the schema on next request")
public void clearCachedSchema() {
- this.schema = null; // will cause to reload the schema
+ this.schemaReader.setSchema(null); // will cause to reload the schema
}
@Override
public Producer createProducer() throws Exception {
- if (this.schema == null) {
- this.schema = loadSchema();
+ if (this.schemaReader == null) {
+ this.schemaReader = new JsonSchemaReader(getCamelContext(), resourceUri, schemaLoader);
+ // Load the schema once when creating the producer to fail fast if the schema is invalid.
+ this.schemaReader.getSchema();
}
- JsonValidatingProcessor validator = new JsonValidatingProcessor(this.schema);
+ JsonValidatingProcessor validator = new JsonValidatingProcessor(this.schemaReader);
configureValidator(validator);
return new JsonSchemaValidatorProducer(this, validator);
@@ -140,6 +127,18 @@ public class JsonSchemaValidatorEndpoint extends DefaultEndpoint {
public void setErrorHandler(JsonValidatorErrorHandler errorHandler) {
this.errorHandler = errorHandler;
}
+
+ public JsonSchemaLoader getSchemaLoader() {
+ return schemaLoader;
+ }
+
+ /**
+ * To use a custom schema loader allowing for adding custom format validation. See the Everit JSON Schema documentation.
+ * The default implementation will create a schema loader builder with draft v6 support.
+ */
+ public void setSchemaLoader(JsonSchemaLoader schemaLoader) {
+ this.schemaLoader = schemaLoader;
+ }
public boolean isFailOnNullBody() {
return failOnNullBody;
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
index 7b5fb68..68cffaf 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/JsonValidatingProcessor.java
@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;
*/
public class JsonValidatingProcessor implements AsyncProcessor {
private static final Logger LOG = LoggerFactory.getLogger(JsonValidatingProcessor.class);
- private Schema schema;
+ private JsonSchemaReader schemaReader;
private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
private boolean failOnNullBody = true;
private boolean failOnNullHeader = true;
@@ -49,8 +49,8 @@ public class JsonValidatingProcessor implements AsyncProcessor {
}
- public JsonValidatingProcessor(Schema schema) {
- this.schema = schema;
+ public JsonValidatingProcessor(JsonSchemaReader schemaReader) {
+ this.schemaReader = schemaReader;
}
public void process(Exchange exchange) throws Exception {
@@ -70,6 +70,7 @@ public class JsonValidatingProcessor implements AsyncProcessor {
protected void doProcess(Exchange exchange) throws Exception {
Object jsonPayload = null;
InputStream is = null;
+ Schema schema = null;
try {
is = getContentToValidate(exchange, InputStream.class);
if (shouldUseHeader()) {
@@ -82,6 +83,7 @@ public class JsonValidatingProcessor implements AsyncProcessor {
}
}
if (is != null) {
+ schema = this.schemaReader.getSchema();
if (schema instanceof ObjectSchema) {
jsonPayload = new JSONObject(new JSONTokener(is));
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
index 64cf1d8..23a5ab3 100644
--- a/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
+++ b/components/camel-everit-json-schema/src/main/java/org/apache/camel/component/everit/jsonschema/package.html
@@ -19,7 +19,7 @@
</head>
<body>
-The <a href="http://activemq.apache.org/camel/validator.html">Validator Component</a> for validating XML against some schema
+The JSON Schema Validator Component for validating JSON against a JSON schema.
</body>
</html>
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java
new file mode 100644
index 0000000..198c1ef
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/CustomSchemaLoaderValidatorRouteTest.java
@@ -0,0 +1,84 @@
+/**
+ * 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.everit.jsonschema;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class CustomSchemaLoaderValidatorRouteTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:valid")
+ protected MockEndpoint validEndpoint;
+
+ @EndpointInject(uri = "mock:finally")
+ protected MockEndpoint finallyEndpoint;
+
+ @EndpointInject(uri = "mock:invalid")
+ protected MockEndpoint invalidEndpoint;
+
+ @Test
+ public void testValidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Even Joe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidMessage() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Odd Joe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndiRegistry = super.createRegistry();
+ jndiRegistry.bind("customSchemaLoader", new TestCustomSchemaLoader());
+ return jndiRegistry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/everit/jsonschema/schemawithformat.json?schemaLoader=#customSchemaLoader")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
new file mode 100644
index 0000000..876f55e
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/EvenCharNumValidator.java
@@ -0,0 +1,22 @@
+package org.apache.camel.component.everit.jsonschema;
+
+import java.util.Optional;
+
+import org.everit.json.schema.FormatValidator;
+
+public class EvenCharNumValidator implements FormatValidator {
+
+ @Override
+ public Optional<String> validate(final String subject) {
+ if (subject.length() % 2 == 0) {
+ return Optional.empty();
+ } else {
+ return Optional.of(String.format("the length of string [%s] is odd", subject));
+ }
+ }
+
+ @Override
+ public String formatName() {
+ return "evenlength";
+ }
+ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
new file mode 100644
index 0000000..7902fc3
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/java/org/apache/camel/component/everit/jsonschema/TestCustomSchemaLoader.java
@@ -0,0 +1,33 @@
+package org.apache.camel.component.everit.jsonschema;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.util.ResourceHelper;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.loader.SchemaLoader;
+import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+public class TestCustomSchemaLoader implements JsonSchemaLoader {
+
+ @Override
+ public Schema createSchema(CamelContext camelContext, String resourceUri)
+ throws IOException {
+
+ SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
+
+ try (InputStream inputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(camelContext, resourceUri)) {
+ JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
+ return schemaLoaderBuilder
+ .schemaJson(rawSchema)
+ .addFormatValidator(new EvenCharNumValidator())
+ .build()
+ .load()
+ .build();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/923f1267/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
new file mode 100644
index 0000000..17ba7ad
--- /dev/null
+++ b/components/camel-everit-json-schema/src/test/resources/org/apache/camel/component/everit/jsonschema/schemawithformat.json
@@ -0,0 +1,35 @@
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "definitions": {},
+ "id": "http://example.com/example.json",
+ "properties": {
+ "id": {
+ "default": 1,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/id",
+ "title": "The id schema",
+ "type": "integer"
+ },
+ "name": {
+ "default": "A green door",
+ "description": "An explanation about the purpose of this instance. Must have even number of characters",
+ "id": "/properties/name",
+ "title": "The name schema",
+ "type": "string",
+ "format": "evenlength"
+ },
+ "price": {
+ "default": 12.5,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/price",
+ "title": "The price schema",
+ "type": "number"
+ }
+ },
+ "required": [
+ "name",
+ "id",
+ "price"
+ ],
+ "type": "object"
+}
\ No newline at end of file
[14/14] camel git commit: CAMEL-9799: Added spring boot itest
Posted by da...@apache.org.
CAMEL-9799: Added spring boot itest
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/732ba9d3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/732ba9d3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/732ba9d3
Branch: refs/heads/master
Commit: 732ba9d36863be11c72861cd400b19d53a4905ef
Parents: d8a9ea3
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 10:58:52 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 10:58:52 2017 +0200
----------------------------------------------------------------------
.../springboot/CamelJsonValidatorTest.java | 48 ++++++++++++++++++++
1 file changed, 48 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/732ba9d3/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsonValidatorTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsonValidatorTest.java b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsonValidatorTest.java
new file mode 100644
index 0000000..e962e51
--- /dev/null
+++ b/tests/camel-itest-spring-boot/src/test/java/org/apache/camel/itest/springboot/CamelJsonValidatorTest.java
@@ -0,0 +1,48 @@
+/**
+ * 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.itest.springboot;
+
+import org.apache.camel.itest.springboot.util.ArquillianPackager;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+@RunWith(Arquillian.class)
+public class CamelJsonValidatorTest extends AbstractSpringBootTestSupport {
+
+ @Deployment
+ public static Archive<?> createSpringBootPackage() throws Exception {
+ return ArquillianPackager.springBootPackage(createTestConfig());
+ }
+
+ public static ITestConfig createTestConfig() {
+ return new ITestConfigBuilder()
+ .module(inferModuleName(CamelJsonValidatorTest.class))
+ .build();
+ }
+
+ @Test
+ public void componentTests() throws Exception {
+ this.runComponentTest(config);
+ this.runModuleUnitTestsIfEnabled(config);
+ }
+
+
+}
[07/14] camel git commit: CAMEL-9799: Add to kit.
Posted by da...@apache.org.
CAMEL-9799: Add to kit.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f7c2780b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f7c2780b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f7c2780b
Branch: refs/heads/master
Commit: f7c2780b0caca7f3741991a15d203e4edb262a1a
Parents: 5ac52a9
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Oct 7 09:47:55 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Oct 7 09:47:55 2017 +0200
----------------------------------------------------------------------
apache-camel/pom.xml | 9 +++++++++
.../src/main/docs/json-validator-component.adoc | 6 ++----
parent/pom.xml | 10 ++++++++++
3 files changed, 21 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f7c2780b/apache-camel/pom.xml
----------------------------------------------------------------------
diff --git a/apache-camel/pom.xml b/apache-camel/pom.xml
index 03111c6..ed275ef 100644
--- a/apache-camel/pom.xml
+++ b/apache-camel/pom.xml
@@ -304,6 +304,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-exec</artifactId>
</dependency>
<dependency>
@@ -1430,6 +1434,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-exec-starter</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/f7c2780b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
index b7b124b..d0e6d56 100644
--- a/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
+++ b/components/camel-everit-json-schema/src/main/docs/json-validator-component.adoc
@@ -1,6 +1,6 @@
== JSON Schema Validator Component
-*Available as of Camel version 2.20*
+*Available as of Camel version *
The JSON Schema Validator component performs bean validation of the message body
agains JSON Schemas using the Everit.org JSON Schema library
@@ -124,6 +124,4 @@ we can validate incoming JSON with the following Camel route, where `myschema.js
from("direct:start")
.to("json-validator:myschema.json")
.to("mock:end")
-----
-
-
+----
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/f7c2780b/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index ca1d8be..796b069 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1147,6 +1147,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-exec</artifactId>
<version>${project.version}</version>
</dependency>
@@ -2586,6 +2591,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-exec-starter</artifactId>
<version>${project.version}</version>
</dependency>
[10/14] camel git commit: CAMEL-9799: Rename component to
json-validator so it has a better name
Posted by da...@apache.org.
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/pom.xml b/components/camel-json-validator/pom.xml
new file mode 100644
index 0000000..cb03513
--- /dev/null
+++ b/components/camel-json-validator/pom.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>components</artifactId>
+ <version>2.20.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-json-validator</artifactId>
+ <name>Camel :: JSON validator</name>
+ <description>Camel JSON Schema validation based on Everit JSON-schema library</description>
+ <packaging>jar</packaging>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.component.jsonvalidator.*</camel.osgi.export.pkg>
+ <camel.osgi.export.service>
+ org.apache.camel.spi.ComponentResolver;component=json-validator
+ </camel.osgi.export.service>
+ </properties>
+
+ <!-- everit is distributed in jitpack and not Maven central -->
+ <repositories>
+ <repository>
+ <id>jitpack.io</id>
+ <url>https://jitpack.io</url>
+ </repository>
+ </repositories>
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.github.everit-org.json-schema</groupId>
+ <artifactId>org.everit.json.schema</artifactId>
+ <version>${everit-org-json-schema-version}</version>
+ </dependency>
+
+ <!-- for testing -->
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/docs/json-validator-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/docs/json-validator-component.adoc b/components/camel-json-validator/src/main/docs/json-validator-component.adoc
new file mode 100644
index 0000000..d0e6d56
--- /dev/null
+++ b/components/camel-json-validator/src/main/docs/json-validator-component.adoc
@@ -0,0 +1,127 @@
+== JSON Schema Validator Component
+
+*Available as of Camel version *
+
+The JSON Schema Validator component performs bean validation of the message body
+agains JSON Schemas using the Everit.org JSON Schema library
+(https://github.com/everit-org/json-schema).
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+----
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-everit-json-schema</artifactId>
+ <version>x.y.z</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+----
+
+
+=== URI format
+
+[source]
+----
+json-validator:resourceUri[?options]
+----
+
+
+Where *resourceUri* is some URL to a local resource on the classpath or a
+full URL to a remote resource or resource on the file system which contains
+the JSON Schema to validate against.
+
+=== URI Options
+
+// component options: START
+The JSON Schema Validator component has no options.
+// component options: END
+
+
+
+// endpoint options: START
+The JSON Schema Validator endpoint is configured using URI syntax:
+
+----
+json-validator:resourceUri
+----
+
+with the following path and query parameters:
+
+==== Path Parameters (1 parameters):
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *resourceUri* | *Required* Path to the resource. You can prefix with: classpath file http ref or bean. classpath file and http loads the resource using these protocols (classpath is default). ref will lookup the resource in the registry. bean will call a method on a bean to be used as the resource. For bean you can specify the method name after dot eg bean:myBean.myMethod. | | String
+|===
+
+==== Query Parameters (7 parameters):
+
+[width="100%",cols="2,5,^1,2",options="header"]
+|===
+| Name | Description | Default | Type
+| *contentCache* (producer) | Sets whether to use resource content cache or not | false | boolean
+| *failOnNullBody* (producer) | Whether to fail if no body exists. | true | boolean
+| *failOnNullHeader* (producer) | Whether to fail if no header exists when validating against a header. | true | boolean
+| *headerName* (producer) | To validate against a header instead of the message body. | | String
+| *errorHandler* (advanced) | To use a custom ValidatorErrorHandler. The default error handler captures the errors and throws an exception. | | JsonValidatorError Handler
+| *schemaLoader* (advanced) | To use a custom schema loader allowing for adding custom format validation. See Everit JSON Schema documentation. The default implementation will create a schema loader builder with draft v6 support. | | JsonSchemaLoader
+| *synchronous* (advanced) | Sets whether synchronous processing should be strictly used or Camel is allowed to use asynchronous processing (if supported). | false | boolean
+|===
+// endpoint options: END
+
+
+=== Example
+
+Assumed we have the following JSON Schema
+
+*myschema.json*
+
+[source,json]
+----
+{
+ "$schema": "http://json-schema.org/draft-04/schema#",
+ "definitions": {},
+ "id": "http://example.com/example.json",
+ "properties": {
+ "id": {
+ "default": 1,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/id",
+ "title": "The id schema",
+ "type": "integer"
+ },
+ "name": {
+ "default": "A green door",
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/name",
+ "title": "The name schema",
+ "type": "string"
+ },
+ "price": {
+ "default": 12.5,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/price",
+ "title": "The price schema",
+ "type": "number"
+ }
+ },
+ "required": [
+ "name",
+ "id",
+ "price"
+ ],
+ "type": "object"
+}
+----
+
+we can validate incoming JSON with the following Camel route, where `myschema.json` is loaded from the classpath.
+
+[source,java]
+----
+from("direct:start")
+ .to("json-validator:myschema.json")
+ .to("mock:end")
+----
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonSchemaLoader.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonSchemaLoader.java
new file mode 100644
index 0000000..6746c10
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonSchemaLoader.java
@@ -0,0 +1,40 @@
+/**
+ * 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.jsonvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.loader.SchemaLoader;
+import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+public class DefaultJsonSchemaLoader implements JsonSchemaLoader {
+
+ @Override
+ public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
+ SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
+ try (InputStream inputStream = schemaInputStream) {
+ JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
+ return schemaLoaderBuilder.schemaJson(rawSchema).build().load().build();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonValidationErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonValidationErrorHandler.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonValidationErrorHandler.java
new file mode 100644
index 0000000..da96a77
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/DefaultJsonValidationErrorHandler.java
@@ -0,0 +1,38 @@
+/**
+ * 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.jsonvalidator;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+public class DefaultJsonValidationErrorHandler implements JsonValidatorErrorHandler {
+
+ @Override
+ public void reset() {
+ // Do nothing since we do not keep state
+ }
+
+ @Override
+ public void handleErrors(Exchange exchange, org.everit.json.schema.Schema schema, Exception e) throws ValidationException {
+ if (e instanceof org.everit.json.schema.ValidationException) {
+ throw new JsonValidationException(exchange, schema, (org.everit.json.schema.ValidationException)e);
+ } else {
+ throw new JsonValidationException(exchange, schema, e);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonSchemaLoader.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonSchemaLoader.java
new file mode 100644
index 0000000..045052d
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonSchemaLoader.java
@@ -0,0 +1,44 @@
+/**
+ * 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.jsonvalidator;
+
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.everit.json.schema.FormatValidator;
+import org.everit.json.schema.Schema;
+
+/**
+ * Can be used to create custom schema for the JSON validator endpoint.
+ * This interface is useful to add custom {@link FormatValidator} to the {@link Schema}
+ *
+ * For more information see
+ * <a href="https://github.com/everit-org/json-schema#format-validators">Format Validators</a>
+ * in the Everit JSON Schema documentation.
+ */
+public interface JsonSchemaLoader {
+
+ /**
+ * Create a new Schema based on the schema input stream.
+ *
+ * @param camelContext camel context
+ * @param schemaInputStream the resource input stream
+ * @return a Schema to be used when validating incoming requests
+ */
+ Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws Exception;
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java
new file mode 100644
index 0000000..d027f2e
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidationException.java
@@ -0,0 +1,36 @@
+/**
+ * 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.jsonvalidator;
+
+import java.util.stream.Collectors;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+import org.everit.json.schema.Schema;
+
+public class JsonValidationException extends ValidationException {
+
+ private static final long serialVersionUID = 1L;
+
+ public JsonValidationException(Exchange exchange, Schema schema, org.everit.json.schema.ValidationException e) {
+ super(e.getAllMessages().stream().collect(Collectors.joining(", ")), exchange, e);
+ }
+
+ public JsonValidationException(Exchange exchange, Schema schema, Exception e) {
+ super(e.getMessage(), exchange, e);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorComponent.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorComponent.java
new file mode 100644
index 0000000..bdc2d34
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorComponent.java
@@ -0,0 +1,35 @@
+/**
+ * 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.jsonvalidator;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+
+/**
+ * The JSON Schema Validator Component is for validating JSON against a schema.
+ */
+public class JsonValidatorComponent extends DefaultComponent {
+
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ JsonValidatorEndpoint endpoint = new JsonValidatorEndpoint(uri, this, remaining);
+ setProperties(endpoint, parameters);
+ return endpoint;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorEndpoint.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorEndpoint.java
new file mode 100644
index 0000000..c301508
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorEndpoint.java
@@ -0,0 +1,201 @@
+/**
+ * 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.jsonvalidator;
+
+import java.io.InputStream;
+
+import org.apache.camel.Component;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.component.ResourceEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+import org.apache.camel.util.IOHelper;
+import org.everit.json.schema.ObjectSchema;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.ValidationException;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Validates the payload of a message using Everit JSON schema validator.
+ */
+@ManagedResource(description = "Managed JsonValidatorEndpoint")
+@UriEndpoint(scheme = "json-validator", title = "JSON Schema Validator", syntax = "json-validator:resourceUri", producerOnly = true, label = "validation,json")
+public class JsonValidatorEndpoint extends ResourceEndpoint {
+
+ private static final Logger LOG = LoggerFactory.getLogger(JsonValidatorEndpoint.class);
+
+ private volatile Schema schema;
+
+ @UriParam(defaultValue = "true")
+ private boolean failOnNullBody = true;
+ @UriParam(defaultValue = "true")
+ private boolean failOnNullHeader = true;
+ @UriParam(description = "To validate against a header instead of the message body.")
+ private String headerName;
+ @UriParam(label = "advanced")
+ private JsonValidatorErrorHandler errorHandler = new DefaultJsonValidationErrorHandler();
+ @UriParam(label = "advanced")
+ private JsonSchemaLoader schemaLoader = new DefaultJsonSchemaLoader();
+
+ public JsonValidatorEndpoint(String endpointUri, Component component, String resourceUri) {
+ super(endpointUri, component, resourceUri);
+ }
+
+ @Override
+ public void clearContentCache() {
+ this.schema = null;
+ super.clearContentCache();
+ }
+
+ @Override
+ public ExchangePattern getExchangePattern() {
+ return ExchangePattern.InOut;
+ }
+
+ @Override
+ protected void onExchange(Exchange exchange) throws Exception {
+ Object jsonPayload;
+ InputStream is = null;
+ // Get a local copy of the current schema to improve concurrency.
+ Schema localSchema = this.schema;
+ if (localSchema == null) {
+ localSchema = getOrCreateSchema();
+ }
+ try {
+ is = getContentToValidate(exchange, InputStream.class);
+ if (shouldUseHeader()) {
+ if (is == null && isFailOnNullHeader()) {
+ throw new NoJsonHeaderValidationException(exchange, headerName);
+ }
+ } else {
+ if (is == null && isFailOnNullBody()) {
+ throw new NoJsonBodyValidationException(exchange);
+ }
+ }
+ if (is != null) {
+ if (schema instanceof ObjectSchema) {
+ jsonPayload = new JSONObject(new JSONTokener(is));
+ } else {
+ jsonPayload = new JSONArray(new JSONTokener(is));
+ }
+ // throws a ValidationException if this object is invalid
+ schema.validate(jsonPayload);
+ LOG.debug("JSON is valid");
+ }
+ } catch (ValidationException | JSONException e) {
+ this.errorHandler.handleErrors(exchange, schema, e);
+ } finally {
+ IOHelper.close(is);
+ }
+ }
+
+ private <T> T getContentToValidate(Exchange exchange, Class<T> clazz) {
+ if (shouldUseHeader()) {
+ return exchange.getIn().getHeader(headerName, clazz);
+ } else {
+ return exchange.getIn().getBody(clazz);
+ }
+ }
+
+ private boolean shouldUseHeader() {
+ return headerName != null;
+ }
+
+ /**
+ * Synchronized method to create a schema if is does not already exist.
+ *
+ * @return The currently loaded schema
+ */
+ private Schema getOrCreateSchema() throws Exception {
+ synchronized (this) {
+ if (this.schema == null) {
+ this.schema = this.schemaLoader.createSchema(getCamelContext(), this.getResourceAsInputStream());
+ }
+ }
+ return this.schema;
+ }
+
+ @Override
+ protected String createEndpointUri() {
+ return "json-validator:" + getResourceUri();
+ }
+
+ public JsonValidatorErrorHandler getErrorHandler() {
+ return errorHandler;
+ }
+
+ /**
+ * To use a custom ValidatorErrorHandler.
+ * <p/>
+ * The default error handler captures the errors and throws an exception.
+ */
+ public void setErrorHandler(JsonValidatorErrorHandler errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ public JsonSchemaLoader getSchemaLoader() {
+ return schemaLoader;
+ }
+
+ /**
+ * To use a custom schema loader allowing for adding custom format validation. See Everit JSON Schema documentation.
+ * The default implementation will create a schema loader builder with draft v6 support.
+ */
+ public void setSchemaLoader(JsonSchemaLoader schemaLoader) {
+ this.schemaLoader = schemaLoader;
+ }
+
+ public boolean isFailOnNullBody() {
+ return failOnNullBody;
+ }
+
+ /**
+ * Whether to fail if no body exists.
+ */
+ public void setFailOnNullBody(boolean failOnNullBody) {
+ this.failOnNullBody = failOnNullBody;
+ }
+
+ public boolean isFailOnNullHeader() {
+ return failOnNullHeader;
+ }
+
+ /**
+ * Whether to fail if no header exists when validating against a header.
+ */
+ public void setFailOnNullHeader(boolean failOnNullHeader) {
+ this.failOnNullHeader = failOnNullHeader;
+ }
+
+ public String getHeaderName() {
+ return headerName;
+ }
+
+ /**
+ * To validate against a header instead of the message body.
+ */
+ public void setHeaderName(String headerName) {
+ this.headerName = headerName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorErrorHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorErrorHandler.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorErrorHandler.java
new file mode 100644
index 0000000..830ccd4
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/JsonValidatorErrorHandler.java
@@ -0,0 +1,39 @@
+/**
+ * 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.jsonvalidator;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+public interface JsonValidatorErrorHandler {
+
+ /**
+ * Resets any state within this error handler
+ */
+ void reset();
+
+ /**
+ * Process any errors which may have occurred during validation
+ *
+ * @param exchange the exchange
+ * @param schema the schema
+ * @param e the exception triggering the error
+ * @throws ValidationException is thrown in case of validation errors
+ */
+ void handleErrors(Exchange exchange, org.everit.json.schema.Schema schema, Exception e) throws ValidationException;
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonBodyValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonBodyValidationException.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonBodyValidationException.java
new file mode 100644
index 0000000..1257c04
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonBodyValidationException.java
@@ -0,0 +1,35 @@
+/**
+ * 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.jsonvalidator;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+/**
+ * An exception found if no JSON body is available on the inbound message
+ */
+public class NoJsonBodyValidationException extends ValidationException {
+ private static final long serialVersionUID = 4502520681354358599L;
+
+ public NoJsonBodyValidationException(Exchange exchange) {
+ super(exchange, "No JSON body could be found on the input message");
+ }
+
+ public NoJsonBodyValidationException(Exchange exchange, Throwable cause) {
+ super("No JSON body could be found on the input message", exchange, cause);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonHeaderValidationException.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonHeaderValidationException.java b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonHeaderValidationException.java
new file mode 100644
index 0000000..ae29d9f
--- /dev/null
+++ b/components/camel-json-validator/src/main/java/org/apache/camel/component/jsonvalidator/NoJsonHeaderValidationException.java
@@ -0,0 +1,36 @@
+/**
+ * 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.jsonvalidator;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+
+/**
+ * An exception found if no JSON body is available on the inbound message
+ */
+public class NoJsonHeaderValidationException extends ValidationException {
+ private static final long serialVersionUID = 4502520681354358599L;
+
+ public NoJsonHeaderValidationException(Exchange exchange, String header) {
+ this(exchange, header, null);
+ }
+
+ public NoJsonHeaderValidationException(Exchange exchange, String header, Throwable cause) {
+ super("No JSON header \"" + header + "\" could be found on the input message", exchange, cause);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/resources/META-INF/LICENSE.txt
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/resources/META-INF/LICENSE.txt b/components/camel-json-validator/src/main/resources/META-INF/LICENSE.txt
new file mode 100755
index 0000000..6b0b127
--- /dev/null
+++ b/components/camel-json-validator/src/main/resources/META-INF/LICENSE.txt
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
+
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/resources/META-INF/NOTICE.txt
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/resources/META-INF/NOTICE.txt b/components/camel-json-validator/src/main/resources/META-INF/NOTICE.txt
new file mode 100644
index 0000000..2e215bf
--- /dev/null
+++ b/components/camel-json-validator/src/main/resources/META-INF/NOTICE.txt
@@ -0,0 +1,11 @@
+ =========================================================================
+ == NOTICE file corresponding to the section 4 d of ==
+ == the Apache License, Version 2.0, ==
+ == in this case for the Apache Camel distribution. ==
+ =========================================================================
+
+ This product includes software developed by
+ The Apache Software Foundation (http://www.apache.org/).
+
+ Please read the different LICENSE files present in the licenses directory of
+ this distribution.
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/main/resources/META-INF/services/org/apache/camel/component/json-validator b/components/camel-json-validator/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
new file mode 100644
index 0000000..9830fb8
--- /dev/null
+++ b/components/camel-json-validator/src/main/resources/META-INF/services/org/apache/camel/component/json-validator
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.jsonvalidator.JsonValidatorComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/CustomSchemaLoaderValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/CustomSchemaLoaderValidatorRouteTest.java b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/CustomSchemaLoaderValidatorRouteTest.java
new file mode 100644
index 0000000..a509f81
--- /dev/null
+++ b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/CustomSchemaLoaderValidatorRouteTest.java
@@ -0,0 +1,84 @@
+/**
+ * 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.jsonvalidator;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class CustomSchemaLoaderValidatorRouteTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:valid")
+ protected MockEndpoint validEndpoint;
+
+ @EndpointInject(uri = "mock:finally")
+ protected MockEndpoint finallyEndpoint;
+
+ @EndpointInject(uri = "mock:invalid")
+ protected MockEndpoint invalidEndpoint;
+
+ @Test
+ public void testValidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Even Joe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidMessage() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Odd Joe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndiRegistry = super.createRegistry();
+ jndiRegistry.bind("customSchemaLoader", new TestCustomSchemaLoader());
+ return jndiRegistry;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/jsonvalidator/schemawithformat.json?schemaLoader=#customSchemaLoader")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/EvenCharNumValidator.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/EvenCharNumValidator.java b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/EvenCharNumValidator.java
new file mode 100644
index 0000000..6b995ac
--- /dev/null
+++ b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/EvenCharNumValidator.java
@@ -0,0 +1,38 @@
+/**
+ * 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.jsonvalidator;
+
+import java.util.Optional;
+
+import org.everit.json.schema.FormatValidator;
+
+public class EvenCharNumValidator implements FormatValidator {
+
+ @Override
+ public Optional<String> validate(final String subject) {
+ if (subject.length() % 2 == 0) {
+ return Optional.empty();
+ } else {
+ return Optional.of(String.format("the length of string [%s] is odd", subject));
+ }
+ }
+
+ @Override
+ public String formatName() {
+ return "evenlength";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/FileValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/FileValidatorRouteTest.java b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/FileValidatorRouteTest.java
new file mode 100644
index 0000000..9ee87fd
--- /dev/null
+++ b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/FileValidatorRouteTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.jsonvalidator;
+
+import java.io.File;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.camel.util.FileUtil;
+import org.junit.Before;
+import org.junit.Test;
+
+public class FileValidatorRouteTest extends CamelTestSupport {
+
+ protected MockEndpoint validEndpoint;
+ protected MockEndpoint finallyEndpoint;
+ protected MockEndpoint invalidEndpoint;
+
+ @Test
+ public void testValidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ invalidEndpoint.expectedMessageCount(0);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file:target/validator",
+ "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }",
+ Exchange.FILE_NAME, "valid.json");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+
+ assertTrue("Should be able to delete the file", FileUtil.deleteFile(new File("target/validator/valid.json")));
+ }
+
+ @Test
+ public void testInvalidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(0);
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("file:target/validator",
+ "{ \"name\": \"Joe Doe\", \"id\": \"AA1\", \"price\": 12.5 }",
+ Exchange.FILE_NAME, "invalid.json");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+
+ // should be able to delete the file
+ assertTrue("Should be able to delete the file", FileUtil.deleteFile(new File("target/validator/invalid.json")));
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ deleteDirectory("target/validator");
+ super.setUp();
+ validEndpoint = resolveMandatoryEndpoint("mock:valid", MockEndpoint.class);
+ invalidEndpoint = resolveMandatoryEndpoint("mock:invalid", MockEndpoint.class);
+ finallyEndpoint = resolveMandatoryEndpoint("mock:finally", MockEndpoint.class);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("file:target/validator?noop=true")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/jsonvalidator/schema.json")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/TestCustomSchemaLoader.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/TestCustomSchemaLoader.java b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/TestCustomSchemaLoader.java
new file mode 100644
index 0000000..b7367eb
--- /dev/null
+++ b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/TestCustomSchemaLoader.java
@@ -0,0 +1,42 @@
+/**
+ * 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.jsonvalidator;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.camel.CamelContext;
+import org.everit.json.schema.Schema;
+import org.everit.json.schema.loader.SchemaLoader;
+import org.everit.json.schema.loader.SchemaLoader.SchemaLoaderBuilder;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+public class TestCustomSchemaLoader implements JsonSchemaLoader {
+
+ @Override
+ public Schema createSchema(CamelContext camelContext, InputStream schemaInputStream) throws IOException {
+
+ SchemaLoaderBuilder schemaLoaderBuilder = SchemaLoader.builder().draftV6Support();
+
+ try (InputStream inputStream = schemaInputStream) {
+ JSONObject rawSchema = new JSONObject(new JSONTokener(inputStream));
+ return schemaLoaderBuilder.schemaJson(rawSchema).addFormatValidator(new EvenCharNumValidator()).build().load().build();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/ValidatorRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/ValidatorRouteTest.java b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/ValidatorRouteTest.java
new file mode 100644
index 0000000..f1542ab
--- /dev/null
+++ b/components/camel-json-validator/src/test/java/org/apache/camel/component/jsonvalidator/ValidatorRouteTest.java
@@ -0,0 +1,174 @@
+/**
+ * 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.jsonvalidator;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.ValidationException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ValidatorRouteTest extends CamelTestSupport {
+
+ @EndpointInject(uri = "mock:valid")
+ protected MockEndpoint validEndpoint;
+
+ @EndpointInject(uri = "mock:finally")
+ protected MockEndpoint finallyEndpoint;
+
+ @EndpointInject(uri = "mock:invalid")
+ protected MockEndpoint invalidEndpoint;
+
+ @Test
+ public void testValidMessage() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testValidMessageInHeader() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startHeaders",
+ null,
+ "headerToValidate",
+ "{ \"name\": \"Joe Doe\", \"id\": 1, \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidMessage() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidMessageInHeader() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startHeaders",
+ null,
+ "headerToValidate",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }");
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testNullHeaderNoFail() throws Exception {
+ validEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startNullHeaderNoFail", null, "headerToValidate", null);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint);
+ }
+
+ @Test
+ public void testNullHeader() throws Exception {
+ validEndpoint.setExpectedMessageCount(0);
+
+ Exchange in = resolveMandatoryEndpoint("direct:startNoHeaderException").createExchange(ExchangePattern.InOut);
+
+ in.getIn().setBody(null);
+ in.getIn().setHeader("headerToValidate", null);
+
+ Exchange out = template.send("direct:startNoHeaderException", in);
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+
+ Exception exception = out.getException();
+ assertTrue("Should be failed", out.isFailed());
+ assertTrue("Exception should be correct type", exception instanceof NoJsonHeaderValidationException);
+ assertTrue("Exception should mention missing header", exception.getMessage().contains("headerToValidate"));
+ }
+
+ @Test
+ public void testInvalideBytesMessage() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBody("direct:start",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }".getBytes());
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Test
+ public void testInvalidBytesMessageInHeader() throws Exception {
+ invalidEndpoint.expectedMessageCount(1);
+ finallyEndpoint.expectedMessageCount(1);
+
+ template.sendBodyAndHeader("direct:startHeaders",
+ null,
+ "headerToValidate",
+ "{ \"name\": \"Joe Doe\", \"id\": \"ABC123\", \"price\": 12.5 }".getBytes());
+
+ MockEndpoint.assertIsSatisfied(validEndpoint, invalidEndpoint, finallyEndpoint);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/jsonvalidator/schema.json")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+
+ from("direct:startHeaders")
+ .doTry()
+ .to("json-validator:org/apache/camel/component/jsonvalidator/schema.json?headerName=headerToValidate")
+ .to("mock:valid")
+ .doCatch(ValidationException.class)
+ .to("mock:invalid")
+ .doFinally()
+ .to("mock:finally")
+ .end();
+
+ from("direct:startNoHeaderException")
+ .to("json-validator:org/apache/camel/component/jsonvalidator/schema.json?headerName=headerToValidate")
+ .to("mock:valid");
+
+ from("direct:startNullHeaderNoFail")
+ .to("json-validator:org/apache/camel/component/jsonvalidator/schema.json?headerName=headerToValidate&failOnNullHeader=false")
+ .to("mock:valid");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/resources/log4j2.properties
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/resources/log4j2.properties b/components/camel-json-validator/src/test/resources/log4j2.properties
new file mode 100644
index 0000000..8af6faa
--- /dev/null
+++ b/components/camel-json-validator/src/test/resources/log4j2.properties
@@ -0,0 +1,29 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+appender.file.type = File
+appender.file.name = file
+appender.file.fileName = target/camel-json-validator-test.log
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d %-5p %c{1} - %m %n
+appender.out.type = Console
+appender.out.name = out
+appender.out.layout.type = PatternLayout
+appender.out.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n
+rootLogger.level = INFO
+rootLogger.appenderRef.file.ref = file
+
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schema.json
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schema.json b/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schema.json
new file mode 100644
index 0000000..021640d
--- /dev/null
+++ b/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schema.json
@@ -0,0 +1,34 @@
+{
+ "$schema": "http://json-schema.org/draft-06/schema#",
+ "definitions": {},
+ "id": "http://example.com/example.json",
+ "properties": {
+ "id": {
+ "default": 1,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/id",
+ "title": "The id schema",
+ "type": "integer"
+ },
+ "name": {
+ "default": "A green door",
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/name",
+ "title": "The name schema",
+ "type": "string"
+ },
+ "price": {
+ "default": 12.5,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/price",
+ "title": "The price schema",
+ "type": "number"
+ }
+ },
+ "required": [
+ "name",
+ "id",
+ "price"
+ ],
+ "type": "object"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schemawithformat.json
----------------------------------------------------------------------
diff --git a/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schemawithformat.json b/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schemawithformat.json
new file mode 100644
index 0000000..a365115
--- /dev/null
+++ b/components/camel-json-validator/src/test/resources/org/apache/camel/component/jsonvalidator/schemawithformat.json
@@ -0,0 +1,35 @@
+{
+ "$schema": "http://json-schema.org/draft-06/schema#",
+ "definitions": {},
+ "id": "http://example.com/example.json",
+ "properties": {
+ "id": {
+ "default": 1,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/id",
+ "title": "The id schema",
+ "type": "integer"
+ },
+ "name": {
+ "default": "A green door",
+ "description": "An explanation about the purpose of this instance. Must have even number of characters",
+ "id": "/properties/name",
+ "title": "The name schema",
+ "type": "string",
+ "format": "evenlength"
+ },
+ "price": {
+ "default": 12.5,
+ "description": "An explanation about the purpose of this instance.",
+ "id": "/properties/price",
+ "title": "The price schema",
+ "type": "number"
+ }
+ },
+ "required": [
+ "name",
+ "id",
+ "price"
+ ],
+ "type": "object"
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/components/pom.xml
----------------------------------------------------------------------
diff --git a/components/pom.xml b/components/pom.xml
index 60f3850..6b7f26d 100644
--- a/components/pom.xml
+++ b/components/pom.xml
@@ -121,7 +121,7 @@
<module>camel-elsql</module>
<module>camel-etcd</module>
<module>camel-eventadmin</module>
- <module>camel-everit-json-schema</module>
+ <module>camel-json-validator</module>
<module>camel-exec</module>
<module>camel-facebook</module>
<module>camel-fastjson</module>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 0a3cacc..b75a109 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -1147,11 +1147,6 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-everit-json-schema</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
<artifactId>camel-exec</artifactId>
<version>${project.version}</version>
</dependency>
@@ -1502,6 +1497,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath</artifactId>
<version>${project.version}</version>
</dependency>
@@ -2591,11 +2591,6 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-everit-json-schema-starter</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
<artifactId>camel-exec-starter</artifactId>
<version>${project.version}</version>
</dependency>
@@ -2931,6 +2926,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-json-validator-starter</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-jsonpath-starter</artifactId>
<version>${project.version}</version>
</dependency>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml
deleted file mode 100644
index 5ee84a3..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/pom.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.camel</groupId>
- <artifactId>components-starter</artifactId>
- <version>2.20.0-SNAPSHOT</version>
- </parent>
- <artifactId>camel-everit-json-schema-starter</artifactId>
- <packaging>jar</packaging>
- <name>Spring-Boot Starter :: Camel :: Everit Kft. JSON Schema validator</name>
- <description>Spring-Boot Starter for Camel JSON Schema validation based on everit-org json-schema library</description>
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- <version>${spring-boot-version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-everit-json-schema</artifactId>
- <version>${project.version}</version>
- <!--START OF GENERATED CODE-->
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- </exclusion>
- </exclusions>
- <!--END OF GENERATED CODE-->
- </dependency>
- <!--START OF GENERATED CODE-->
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-core-starter</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-spring-boot-starter</artifactId>
- </dependency>
- <!--END OF GENERATED CODE-->
- </dependencies>
- <!--START OF GENERATED CODE-->
- <repositories>
- <repository>
- <id>jitpack.io</id>
- <url>https://jitpack.io</url>
- </repository>
- </repositories>
- <!--END OF GENERATED CODE-->
-</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/1fa64e6d/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java b/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
deleted file mode 100644
index 7d2decc..0000000
--- a/platforms/spring-boot/components-starter/camel-everit-json-schema-starter/src/main/java/org/apache/camel/component/everit/jsonschema/springboot/JsonSchemaValidatorComponentAutoConfiguration.java
+++ /dev/null
@@ -1,129 +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.everit.jsonschema.springboot;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import javax.annotation.Generated;
-import org.apache.camel.CamelContext;
-import org.apache.camel.component.everit.jsonschema.JsonSchemaValidatorComponent;
-import org.apache.camel.spi.ComponentCustomizer;
-import org.apache.camel.spi.HasId;
-import org.apache.camel.spring.boot.CamelAutoConfiguration;
-import org.apache.camel.spring.boot.ComponentConfigurationProperties;
-import org.apache.camel.spring.boot.util.CamelPropertiesHelper;
-import org.apache.camel.spring.boot.util.ConditionalOnCamelContextAndAutoConfigurationBeans;
-import org.apache.camel.spring.boot.util.GroupCondition;
-import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
-import org.apache.camel.util.IntrospectionSupport;
-import org.apache.camel.util.ObjectHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-
-/**
- * Generated by camel-package-maven-plugin - do not edit this file!
- */
-@Generated("org.apache.camel.maven.packaging.SpringBootAutoConfigurationMojo")
-@Configuration
-@Conditional({ConditionalOnCamelContextAndAutoConfigurationBeans.class,
- JsonSchemaValidatorComponentAutoConfiguration.GroupConditions.class})
-@AutoConfigureAfter(CamelAutoConfiguration.class)
-@EnableConfigurationProperties({ComponentConfigurationProperties.class,
- JsonSchemaValidatorComponentConfiguration.class})
-public class JsonSchemaValidatorComponentAutoConfiguration {
-
- private static final Logger LOGGER = LoggerFactory
- .getLogger(JsonSchemaValidatorComponentAutoConfiguration.class);
- @Autowired
- private ApplicationContext applicationContext;
- @Autowired
- private CamelContext camelContext;
- @Autowired
- private JsonSchemaValidatorComponentConfiguration configuration;
- @Autowired(required = false)
- private List<ComponentCustomizer<JsonSchemaValidatorComponent>> customizers;
-
- static class GroupConditions extends GroupCondition {
- public GroupConditions() {
- super("camel.component", "camel.component.json-validator");
- }
- }
-
- @Lazy
- @Bean(name = "json-validator-component")
- @ConditionalOnMissingBean(JsonSchemaValidatorComponent.class)
- public JsonSchemaValidatorComponent configureJsonSchemaValidatorComponent()
- throws Exception {
- JsonSchemaValidatorComponent component = new JsonSchemaValidatorComponent();
- component.setCamelContext(camelContext);
- Map<String, Object> parameters = new HashMap<>();
- IntrospectionSupport.getProperties(configuration, parameters, null,
- false);
- for (Map.Entry<String, Object> entry : parameters.entrySet()) {
- Object value = entry.getValue();
- Class<?> paramClass = value.getClass();
- if (paramClass.getName().endsWith("NestedConfiguration")) {
- Class nestedClass = null;
- try {
- nestedClass = (Class) paramClass.getDeclaredField(
- "CAMEL_NESTED_CLASS").get(null);
- HashMap<String, Object> nestedParameters = new HashMap<>();
- IntrospectionSupport.getProperties(value, nestedParameters,
- null, false);
- Object nestedProperty = nestedClass.newInstance();
- CamelPropertiesHelper.setCamelProperties(camelContext,
- nestedProperty, nestedParameters, false);
- entry.setValue(nestedProperty);
- } catch (NoSuchFieldException e) {
- }
- }
- }
- CamelPropertiesHelper.setCamelProperties(camelContext, component,
- parameters, false);
- if (ObjectHelper.isNotEmpty(customizers)) {
- for (ComponentCustomizer<JsonSchemaValidatorComponent> customizer : customizers) {
- boolean useCustomizer = (customizer instanceof HasId)
- ? HierarchicalPropertiesEvaluator.evaluate(
- applicationContext.getEnvironment(),
- "camel.component.customizer",
- "camel.component.json-validator.customizer",
- ((HasId) customizer).getId())
- : HierarchicalPropertiesEvaluator.evaluate(
- applicationContext.getEnvironment(),
- "camel.component.customizer",
- "camel.component.json-validator.customizer");
- if (useCustomizer) {
- LOGGER.debug("Configure component {}, with customizer {}",
- component, customizer);
- customizer.customize(component);
- }
- }
- }
- return component;
- }
-}
\ No newline at end of file