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 <davscl...@apache.org> Authored: Sat Oct 7 09:44:28 2017 +0200 Committer: Claus Ibsen <davscl...@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 +