Skip to content

Commit

Permalink
Merge pull request #531 from swisspost/develop
Browse files Browse the repository at this point in the history
PR for release
  • Loading branch information
mcweba authored Nov 22, 2023
2 parents 67822b7 + b4d447b commit b10c5bb
Show file tree
Hide file tree
Showing 50 changed files with 401 additions and 161 deletions.
1 change: 1 addition & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
jobs:
build_maven:
runs-on: ubuntu-latest
timeout-minutes: 30

steps:
- uses: actions/checkout@v3
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>2.0.2-SNAPSHOT</version>
<version>2.0.3-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>2.0.2-SNAPSHOT</version>
<version>2.0.3-SNAPSHOT</version>
</parent>

<artifactId>gateleen-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.MultiMap;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.core.http.*;

import java.util.List;
import java.util.function.Function;

import static io.vertx.core.Future.succeededFuture;

/**
* Base class with empty method implementations.
*
* @author https://github.com/lbovet [Laurent Bovet]
*/
public abstract class AbstractHttpClient implements HttpClient {

private final Vertx vertx;

public AbstractHttpClient(Vertx vertx) {
this.vertx = vertx;
}

protected abstract HttpClientRequest doRequest(HttpMethod method, String uri);

public HttpClientRequest options(String uri) {
Expand Down Expand Up @@ -51,12 +61,14 @@ public Function<HttpClientResponse, Future<RequestOptions>> redirectHandler() {

@Override
public void close(Handler<AsyncResult<Void>> handler) {
throw new UnsupportedOperationException();
close().onComplete(handler);
}

@Override
public Future<Void> close() {
throw new UnsupportedOperationException();
Promise<Void> promise = Promise.promise();
vertx.runOnContext(v -> promise.complete());
return promise.future();
}

@Override
Expand All @@ -71,7 +83,7 @@ public Future<HttpClientRequest> request(RequestOptions requestOptions) {

@Override
public void request(HttpMethod httpMethod, int i, String s, String s1, Handler<AsyncResult<HttpClientRequest>> handler) {
Future.succeededFuture(doRequest(httpMethod, s1)).onComplete(handler);
vertx.runOnContext(v -> succeededFuture(doRequest(httpMethod, s1)).onComplete(handler));
}

@Override
Expand All @@ -81,6 +93,7 @@ public Future<HttpClientRequest> request(HttpMethod httpMethod, int i, String s,

@Override
public void request(HttpMethod httpMethod, String s, String s1, Handler<AsyncResult<HttpClientRequest>> handler) {
throw new UnsupportedOperationException();
}

@Override
Expand All @@ -90,7 +103,7 @@ public Future<HttpClientRequest> request(HttpMethod httpMethod, String s, String

@Override
public void request(HttpMethod method, String requestURI, Handler<AsyncResult<HttpClientRequest>> handler) {
throw new UnsupportedOperationException();
vertx.runOnContext(v -> succeededFuture(doRequest(method, requestURI)).onComplete(handler));
}

@Override
Expand Down Expand Up @@ -152,4 +165,4 @@ public Future<WebSocket> webSocketAbs(String s, MultiMap multiMap, WebsocketVers
public boolean isMetricsEnabled() {
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class LocalHttpClient extends AbstractHttpClient {
private Vertx vertx;

public LocalHttpClient(Vertx vertx) {
super(vertx);
this.vertx = vertx;
}

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>2.0.2-SNAPSHOT</version>
<version>2.0.3-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>2.0.2-SNAPSHOT</version>
<version>2.0.3-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>2.0.2-SNAPSHOT</version>
<version>2.0.3-SNAPSHOT</version>
</parent>

<artifactId>gateleen-expansion</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,24 @@
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.*;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.gateleen.core.http.RequestLoggerFactory;
import org.swisspush.gateleen.core.storage.ResourceStorage;
import org.swisspush.gateleen.core.util.*;
import org.swisspush.gateleen.core.util.ExpansionDeltaUtil;
import org.swisspush.gateleen.core.util.ExpansionDeltaUtil.CollectionResourceContainer;
import org.swisspush.gateleen.core.util.ExpansionDeltaUtil.SlashHandling;
import org.swisspush.gateleen.core.util.HttpServerRequestUtil;
import org.swisspush.gateleen.core.util.ResourceCollectionException;
import org.swisspush.gateleen.core.util.ResponseStatusCodeLogUtil;
import org.swisspush.gateleen.core.util.StatusCode;
import org.swisspush.gateleen.routing.Rule;
import org.swisspush.gateleen.routing.RuleFeaturesProvider;
import org.swisspush.gateleen.routing.RuleProvider;
Expand All @@ -25,6 +33,7 @@
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import static org.swisspush.gateleen.core.util.StatusCode.INTERNAL_SERVER_ERROR;
import static org.swisspush.gateleen.routing.RuleFeatures.Feature.EXPAND_ON_BACKEND;
import static org.swisspush.gateleen.routing.RuleFeatures.Feature.STORAGE_EXPAND;
import static org.swisspush.gateleen.routing.RuleProvider.RuleChangesObserver;
Expand Down Expand Up @@ -491,7 +500,9 @@ private void removeZipParameter(final HttpServerRequest request) {

private void makeStorageExpandRequest(final String targetUri, final List subResourceNames, final HttpServerRequest req, final DeltaHandler<ResourceNode> handler) {
Logger log = RequestLoggerFactory.getLogger(ExpansionHandler.class, req);
httpClient.request(HttpMethod.POST, targetUri + "?storageExpand=true").onComplete(asyncResult -> {
HttpMethod reqMethod = HttpMethod.POST;
String reqUri = targetUri + "?storageExpand=true";
httpClient.request(reqMethod, reqUri).onComplete(asyncResult -> {
if (asyncResult.failed()) {
log.warn("Failed request to {}: {}", targetUri + "?storageExpand=true", asyncResult.cause());
return;
Expand All @@ -512,16 +523,23 @@ private void makeStorageExpandRequest(final String targetUri, final List subReso
cReq.write(payload);

cReq.send(event -> {
if (event.failed()) {
Throwable ex = event.cause();
log.debug("{} {}", reqMethod, reqUri, ex);
var exWrappr = new ResourceCollectionException(ex.getMessage(), INTERNAL_SERVER_ERROR);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, exWrappr));
}
HttpClientResponse cRes = event.result();
cRes.bodyHandler(data -> {
if (StatusCode.NOT_FOUND.getStatusCode() == cRes.statusCode()) {
log.debug("requested resource could not be found: {}", targetUri);
log.debug("NotFound: {}", targetUri);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(cRes.statusMessage(), StatusCode.NOT_FOUND)));
} else if (StatusCode.INTERNAL_SERVER_ERROR.getStatusCode() == cRes.statusCode()) {
log.error("error in request resource : {} message : {}", targetUri, data.toString());
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(data.toString(), StatusCode.INTERNAL_SERVER_ERROR)));
String fullResponseBody = data.toString();
log.error("{}: {}: {}", INTERNAL_SERVER_ERROR, targetUri, fullResponseBody);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(fullResponseBody, StatusCode.INTERNAL_SERVER_ERROR)));
} else if (StatusCode.METHOD_NOT_ALLOWED.getStatusCode() == cRes.statusCode()) {
log.error("POST requests (storageExpand) not allowed for uri: {}", targetUri);
log.error("storageExpand not allowed for: {}", targetUri);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(cRes.statusMessage(), StatusCode.METHOD_NOT_ALLOWED)));
} else {
String eTag = geteTag(cRes.headers());
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>2.0.2-SNAPSHOT</version>
<version>2.0.3-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>2.0.2-SNAPSHOT</version>
<version>2.0.3-SNAPSHOT</version>
</parent>

<artifactId>gateleen-hook</artifactId>
Expand Down
Loading

0 comments on commit b10c5bb

Please sign in to comment.