Skip to content

Commit

Permalink
REVERT random stuff to try-fix build.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenalpha committed Jun 30, 2023
1 parent 871b512 commit 93e51e0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@
import io.vertx.core.MultiMap;
import io.vertx.core.Vertx;
import io.vertx.core.buffer.Buffer;
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.http.*;
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.ExpansionDeltaUtil;
import org.swisspush.gateleen.core.util.*;
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 Down Expand Up @@ -502,7 +494,7 @@ private void makeStorageExpandRequest(final String targetUri, final List subReso
Logger log = RequestLoggerFactory.getLogger(ExpansionHandler.class, req);
HttpMethod reqMethod = HttpMethod.POST;
String reqUri = targetUri + "?storageExpand=true";
httpClient.request(reqMethod, reqUri, asyncResult -> {
httpClient.request(reqMethod, reqUri).onComplete(asyncResult -> {

Check warning on line 497 in gateleen-expansion/src/main/java/org/swisspush/gateleen/expansion/ExpansionHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-expansion/src/main/java/org/swisspush/gateleen/expansion/ExpansionHandler.java#L495-L497

Added lines #L495 - L497 were not covered by tests
if (asyncResult.failed()) {
log.warn("Failed request to {}: {}", targetUri + "?storageExpand=true", asyncResult.cause());
return;
Expand Down Expand Up @@ -535,9 +527,8 @@ private void makeStorageExpandRequest(final String targetUri, final List subReso
log.debug("NotFound: {}", targetUri);

Check warning on line 527 in gateleen-expansion/src/main/java/org/swisspush/gateleen/expansion/ExpansionHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-expansion/src/main/java/org/swisspush/gateleen/expansion/ExpansionHandler.java#L527

Added line #L527 was not covered by tests
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(cRes.statusMessage(), StatusCode.NOT_FOUND)));
} else if (StatusCode.INTERNAL_SERVER_ERROR.getStatusCode() == cRes.statusCode()) {
String fullResponseBody = data.toString();
log.error("{}: {}: {}", INTERNAL_SERVER_ERROR, targetUri, fullResponseBody);
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(fullResponseBody, StatusCode.INTERNAL_SERVER_ERROR)));
log.error("error in request resource : {} message : {}", targetUri, data.toString());
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(data.toString(), StatusCode.INTERNAL_SERVER_ERROR)));
} else if (StatusCode.METHOD_NOT_ALLOWED.getStatusCode() == cRes.statusCode()) {
log.error("storageExpand not allowed for: {}", targetUri);

Check warning on line 533 in gateleen-expansion/src/main/java/org/swisspush/gateleen/expansion/ExpansionHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-expansion/src/main/java/org/swisspush/gateleen/expansion/ExpansionHandler.java#L533

Added line #L533 was not covered by tests
handler.handle(new ResourceNode(SERIOUS_EXCEPTION, new ResourceCollectionException(cRes.statusMessage(), StatusCode.METHOD_NOT_ALLOWED)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static io.vertx.core.http.HttpMethod.DELETE;
import static io.vertx.core.http.HttpMethod.PUT;
import static org.swisspush.gateleen.core.util.HttpRequestHeader.CONTENT_LENGTH;

/**
Expand Down Expand Up @@ -504,28 +502,24 @@ public boolean handle(final RoutingContext ctx) {
/*
* 1) Un- / Register Listener / Routes
*/
var requestMethod = request.method();
if (requestMethod == PUT) {
var requestUri = request.uri();
if (requestUri.contains(HOOKS_LISTENERS_URI_PART)) {
handleListenerRegistration(request);
return true;
}
if (requestUri.contains(HOOKS_ROUTE_URI_PART)) {
handleRouteRegistration(request);
return true;
}
if (isHookListenerRegistration(request)) {
handleListenerRegistration(request);
return true;
}
if (requestMethod == DELETE) {
var requestUri = request.uri();
if (requestUri.contains(HOOKS_LISTENERS_URI_PART)) {
handleListenerUnregistration(request);
return true;
}
if (requestUri.contains(HOOKS_ROUTE_URI_PART)) {
handleRouteUnregistration(request);
return true;
}

if (isHookListenerUnregistration(request)) {
handleListenerUnregistration(request);
return true;
}

if (isHookRouteRegistration(request)) {
handleRouteRegistration(request);
return true;
}

if (isHookRouteUnregistration(request)) {
handleRouteUnregistration(request);
return true;
}

/*
Expand Down Expand Up @@ -1660,6 +1654,46 @@ private String getListenerUrlSegment(String requestUrl) {
return requestUrl.substring(pos + HOOKS_LISTENERS_URI_PART.length());
}

/**
* Checks if the given request is a listener unregistration instruction.
*
* @param request request
* @return boolean
*/
private boolean isHookListenerUnregistration(HttpServerRequest request) {
return request.uri().contains(HOOKS_LISTENERS_URI_PART) && HttpMethod.DELETE == request.method();
}

/**
* Checks if the given request is a listener registration instruction.
*
* @param request request
* @return boolean
*/
private boolean isHookListenerRegistration(HttpServerRequest request) {
return request.uri().contains(HOOKS_LISTENERS_URI_PART) && HttpMethod.PUT == request.method();
}

/**
* Checks if the given request is a route registration instruction.
*
* @param request request
* @return boolean
*/
private boolean isHookRouteRegistration(HttpServerRequest request) {
return request.uri().contains(HOOKS_ROUTE_URI_PART) && HttpMethod.PUT == request.method();
}

/**
* Checks if the given request is a route registration instruction.
*
* @param request request
* @return boolean
*/
private boolean isHookRouteUnregistration(HttpServerRequest request) {
return request.uri().contains(HOOKS_ROUTE_URI_PART) && HttpMethod.DELETE == request.method();
}

/**
* @param request Request to extract the value from. This instance gets manipulated
* internally during call.
Expand Down

0 comments on commit 93e51e0

Please sign in to comment.