Skip to content

Commit

Permalink
exceptionFactory can be pass in
Browse files Browse the repository at this point in the history
  • Loading branch information
Xin Zheng committed Jun 20, 2024
1 parent 178488e commit 5547874
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class Router implements Refreshable, LoggableResource, ConfigurationResou
private final String rulesUri;
private final String userProfileUri;
private final String serverUri;
private final GateleenExceptionFactory exceptionFactory;
private io.vertx.ext.web.Router router;
private final LoggingResourceManager loggingResourceManager;
private final LogAppenderRepository logAppenderRepository;
Expand Down Expand Up @@ -86,8 +87,6 @@ public class Router implements Refreshable, LoggableResource, ConfigurationResou
private OAuthStrategy oAuthStrategy = null;
private BasicAuthStrategy basicAuthStrategy;

private static GateleenExceptionFactory gateleenExceptionFactory = GateleenExceptionFactory.newGateleenThriftyExceptionFactory();

/**
* The multiplier applied to routes, typically the number of {@link Router} instances in a cluster.
*/
Expand Down Expand Up @@ -120,6 +119,7 @@ public static RouterBuilder builder() {
HttpClientFactory httpClientFactory,
int routeMultiplier,
@Nullable OAuthProvider oAuthProvider,
GateleenExceptionFactory exceptionFactory,
Handler<Void>... doneHandlers) {
this.storage = storage;
this.properties = properties;
Expand All @@ -138,6 +138,7 @@ public static RouterBuilder builder() {
this.doneHandlers = doneHandlers;
this.routeMultiplier = routeMultiplier;
this.oAuthProvider = oAuthProvider;
this.exceptionFactory = exceptionFactory;

if (oAuthProvider != null) {
this.oAuthStrategy = new OAuthStrategy(oAuthProvider);
Expand Down Expand Up @@ -327,7 +328,7 @@ private void createForwarders(List<Rule> rules, io.vertx.ext.web.Router newRoute
vertx.eventBus());
} else if (rule.getStorage() != null) {
forwarder = new StorageForwarder(vertx.eventBus(), rule, loggingResourceManager, logAppenderRepository,
monitoringHandler, gateleenExceptionFactory);
monitoringHandler, exceptionFactory);
} else if (rule.getScheme().equals("local")) {
forwarder = new Forwarder(vertx, selfClient, rule, this.storage, loggingResourceManager, logAppenderRepository,
monitoringHandler, userProfileUri, authStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.swisspush.gateleen.core.configuration.ConfigurationResourceManager;
import org.swisspush.gateleen.core.exception.GateleenExceptionFactory;
import org.swisspush.gateleen.core.http.HttpClientFactory;
import org.swisspush.gateleen.core.storage.ResourceStorage;
import org.swisspush.gateleen.logging.LogAppenderRepository;
Expand Down Expand Up @@ -52,6 +53,7 @@ public class RouterBuilder {
private int routeMultiplier = Router.DEFAULT_ROUTER_MULTIPLIER;

private OAuthProvider oAuthProvider;
private GateleenExceptionFactory exceptionFactory;

RouterBuilder() {
// PackagePrivate, as clients should use "Router.builder()" and not this class here directly.
Expand All @@ -67,6 +69,10 @@ public Router build() {
defaultRouteTypes = all();
}

if (this.exceptionFactory == null) {
this.exceptionFactory = GateleenExceptionFactory.newGateleenThriftyExceptionFactory();
}

Handler<Void>[] doneHandlersArray;
if (doneHandlers == null || doneHandlers.isEmpty()) {
logger.debug("No doneHandlers specified.");
Expand Down Expand Up @@ -102,6 +108,7 @@ public Router build() {
httpClientFactory,
routeMultiplier,
oAuthProvider,
exceptionFactory,
doneHandlersArray
);
if (resourceLoggingEnabled) {
Expand Down Expand Up @@ -273,4 +280,9 @@ public RouterBuilder withRouteMultiplier(int routeMultiplier) {
this.routeMultiplier = routeMultiplier;
return this;
}

public RouterBuilder withExceptionFactory(GateleenExceptionFactory exceptionFactory) {
this.exceptionFactory = exceptionFactory;
return this;
}
}

0 comments on commit 5547874

Please sign in to comment.