Skip to content

Commit

Permalink
Merge pull request #414 from swisspush/develop
Browse files Browse the repository at this point in the history
PR for new release
  • Loading branch information
mcweba authored Dec 22, 2021
2 parents e01e106 + 08bc1be commit 23ad7bc
Show file tree
Hide file tree
Showing 31 changed files with 87 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ before_install:
- source "$HOME/.sdkman/bin/sdkman-init.sh"
- sdk install groovy 3.0.8
install:
- mvn install -DskipTests -Dmaven.javadoc.skip=true -PpublicRepos -B -V
- mvn install -Dmaven.javadoc.skip=true -PpublicRepos -B -V
before_script:
- git config --global user.email "swisspush@post.ch"
- git config --global user.name "Travis-CI"
Expand All @@ -30,9 +30,9 @@ script:
# TODO: Instead of sleeping, should we rather make sure that the server Playground actually is running?
- sleep 5s
- mvn deploy -PuploadStaticFiles
#- mvn install -PuiIntegrationTests
- mvn install -PuiIntegrationTests
- kill $(ps -ef | grep playground | awk '{ print $2 }')
#- mvn install -PnonUiIntegrationTests
- mvn install -PnonUiIntegrationTests
# the exported credentials are needed in the maybe-release.sh
- git config credential.helper "store --file=.git/credentials"
- echo "https://${GH_TOKEN}:@github.com" > .git/credentials
Expand Down
2 changes: 1 addition & 1 deletion gateleen-cache/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-cache</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-delegate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-delegate</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-delta/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-delta</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-expansion/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-expansion</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-hook-js/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>
<artifactId>gateleen-hook-js</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-hook/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-hook</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-kafka/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-kafka</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-logging</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-merge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-merge</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-monitoring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-monitoring</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-packing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-packing</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-player/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-player</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-playground/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-playground</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-qos/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-qos</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-queue/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-queue</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-routing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-routing</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-runconfig/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-runconfig</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-scheduler</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-security/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-security</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>
<artifactId>gateleen-test</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-testhelper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-testhelper</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-user/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-user</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion gateleen-validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.swisspush.gateleen</groupId>
<artifactId>gateleen</artifactId>
<version>1.2.7-SNAPSHOT</version>
<version>1.2.8-SNAPSHOT</version>
</parent>

<artifactId>gateleen-validation</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import io.vertx.core.Future;
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpClientRequest;
Expand All @@ -26,6 +26,7 @@ public class DefaultValidationSchemaProvider implements ValidationSchemaProvider
private final Logger log = LoggerFactory.getLogger(DefaultValidationSchemaProvider.class);

private final Map<String, SchemaEntry> cachedSchemas;
private final MultiMap defaultRequestHeaders;

private static final int TIMEOUT_MS = 30000;
private static final String CONTENT_TYPE_HEADER = "Content-Type";
Expand All @@ -40,8 +41,22 @@ public class DefaultValidationSchemaProvider implements ValidationSchemaProvider
* @param cacheCleanupInterval interval to define the cached schema cleanup
*/
public DefaultValidationSchemaProvider(Vertx vertx, ClientRequestCreator clientRequestCreator, Duration cacheCleanupInterval) {
this(vertx, clientRequestCreator, cacheCleanupInterval, new HashMap<>());
}

/**
* Constructor for {@link DefaultValidationSchemaProvider}
*
* @param vertx the Vert.x instance
* @param clientRequestCreator the {@link ClientRequestCreator} to fetch the schema
* @param cacheCleanupInterval interval to define the cached schema cleanup
* @param defaultRequestHeaders default request headers to add to every schema fetch request
*/
public DefaultValidationSchemaProvider(Vertx vertx, ClientRequestCreator clientRequestCreator, Duration cacheCleanupInterval,
Map<String, String> defaultRequestHeaders) {
this.clientRequestCreator = clientRequestCreator;
this.cachedSchemas = new HashMap<>();
this.defaultRequestHeaders = new VertxHttpHeaders().addAll(defaultRequestHeaders);

vertx.setPeriodic(cacheCleanupInterval.toMillis(), event -> cleanupCachedSchemas());
}
Expand All @@ -51,6 +66,10 @@ private void cleanupCachedSchemas() {
cachedSchemas.entrySet().removeIf(entry -> entry.getValue().expiration().isBefore(Instant.now()));
}

private MultiMap defaultRequestHeaders() {
return defaultRequestHeaders;
}

@Override
public Future<Optional<JsonSchema>> schemaFromLocation(SchemaLocation schemaLocation) {
Future<Optional<JsonSchema>> future = Future.future();
Expand All @@ -65,7 +84,7 @@ public Future<Optional<JsonSchema>> schemaFromLocation(SchemaLocation schemaLoca
}
}

VertxHttpHeaders headers = new VertxHttpHeaders();
MultiMap headers = defaultRequestHeaders();
headers.add("Accept", "application/json");
headers.add(SELF_REQUEST_HEADER, "true");

Expand Down Expand Up @@ -107,7 +126,7 @@ public Future<Optional<JsonSchema>> schemaFromLocation(SchemaLocation schemaLoca
private Optional<JsonSchema> parseSchema(SchemaLocation schemaLocation, Buffer data) {
JsonSchema schema = null;
try {
schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4).getSchema(data.toString());
schema = JsonSchemaFactory.getInstance().getSchema(data.toString());
if (schemaLocation.keepInMemory() != null) {
cachedSchemas.put(schemaLocation.schemaLocation(), new SchemaEntry(schema, Instant.now().plusSeconds(schemaLocation.keepInMemory())));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.SpecVersion;
import com.networknt.schema.ValidationMessage;
import io.vertx.core.json.Json;
import org.swisspush.gateleen.core.http.RequestLoggerFactory;
Expand Down Expand Up @@ -136,7 +135,7 @@ public static ValidationResult validateStatic(Buffer dataToBeValidated, String s
if (SCHEMA_DECLARATION.equals(schemaObject.getString("$schema"))) {
JsonSchema schema;
try {
schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4).getSchema(schemaAsString);
schema = JsonSchemaFactory.getInstance().getSchema(schemaAsString);
} catch (RuntimeException e) {
String message = "Cannot load schema";
log.warn(message, e);
Expand Down Expand Up @@ -206,7 +205,7 @@ private static void performValidation(String dataString, JsonObject data, Logger
if (SCHEMA_DECLARATION.equals(data.getString("$schema"))) {
JsonSchema schema;
try {
schema = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V4).getSchema(dataString);
schema = JsonSchemaFactory.getInstance().getSchema(dataString);
} catch (RuntimeException e) {
String message = "Cannot load schema " + base;
log.warn(message, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package org.swisspush.gateleen.validation;

import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.http.CaseInsensitiveHeaders;
import io.vertx.core.http.HttpMethod;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import org.swisspush.gateleen.core.http.ClientRequestCreator;
import org.swisspush.gateleen.core.http.LocalHttpClient;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

import static org.mockito.Matchers.*;
import static org.mockito.Mockito.times;
Expand All @@ -38,13 +43,39 @@ public void setUp(){
public void testSchemaFromLocation(TestContext context){
schemaProvider.schemaFromLocation(new SchemaLocation("/path/to/schema", null));

ArgumentCaptor<MultiMap> headersCaptor = ArgumentCaptor.forClass(MultiMap.class);
verify(clientRequestCreator, times(1)).createClientRequest(
eq(HttpMethod.GET),
eq("/path/to/schema"),
any(),
headersCaptor.capture(),
anyLong(),
any(Handler.class),
any(Handler.class)
);

MultiMap headers = headersCaptor.getValue();
context.assertTrue(headers.contains("Accept", "application/json", true));
context.assertTrue(headers.contains("x-self-request", "true", true));
}

@Test
public void testSchemaFromLocationWithDefaultRequestHeaders(TestContext context){
schemaProvider = new DefaultValidationSchemaProvider(vertx, clientRequestCreator, Duration.ofSeconds(5), Map.of("foo", "bar"));
schemaProvider.schemaFromLocation(new SchemaLocation("/path/to/schema", null));

ArgumentCaptor<MultiMap> headersCaptor = ArgumentCaptor.forClass(MultiMap.class);
verify(clientRequestCreator, times(1)).createClientRequest(
eq(HttpMethod.GET),
eq("/path/to/schema"),
headersCaptor.capture(),
anyLong(),
any(Handler.class),
any(Handler.class)
);

MultiMap headers = headersCaptor.getValue();
context.assertTrue(headers.contains("foo", "bar", true));
context.assertTrue(headers.contains("Accept", "application/json", true));
context.assertTrue(headers.contains("x-self-request", "true", true));
}
}
Loading

0 comments on commit 23ad7bc

Please sign in to comment.