Skip to content

Commit

Permalink
Get rid of ThreadLocalHandler
Browse files Browse the repository at this point in the history
- used to workaround vert-x3/vertx-web#1429
  • Loading branch information
mkouba committed Jul 23, 2020
1 parent 73d3959 commit 9d408d8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.smallrye.graphql.runtime;

import java.util.function.Supplier;

import javax.enterprise.inject.Instance;
import javax.enterprise.inject.spi.CDI;

Expand All @@ -10,7 +8,6 @@
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.security.identity.CurrentIdentityAssociation;
import io.quarkus.smallrye.graphql.runtime.spi.QuarkusClassloadingService;
import io.quarkus.vertx.http.runtime.ThreadLocalHandler;
import io.smallrye.graphql.cdi.producer.GraphQLProducer;
import io.smallrye.graphql.schema.model.Schema;
import io.vertx.core.Handler;
Expand Down Expand Up @@ -45,14 +42,9 @@ public Handler<RoutingContext> schemaHandler() {

public Handler<RoutingContext> uiHandler(String graphqlUiFinalDestination, String graphqlUiPath) {

Handler<RoutingContext> handler = new ThreadLocalHandler(new Supplier<Handler<RoutingContext>>() {
@Override
public Handler<RoutingContext> get() {
return StaticHandler.create().setAllowRootFileSystemAccess(true)
.setWebRoot(graphqlUiFinalDestination)
.setDefaultContentEncoding("UTF-8");
}
});
StaticHandler staticHandler = StaticHandler.create().setAllowRootFileSystemAccess(true)
.setWebRoot(graphqlUiFinalDestination)
.setDefaultContentEncoding("UTF-8");

return new Handler<RoutingContext>() {
@Override
Expand All @@ -68,7 +60,7 @@ public void handle(RoutingContext event) {
return;
}

handler.handle(event);
staticHandler.handle(event);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.quarkus.smallrye.health.runtime;

import java.util.function.Supplier;

import org.eclipse.microprofile.health.HealthCheckResponse;
import org.eclipse.microprofile.health.spi.HealthCheckResponseProvider;

import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.vertx.http.runtime.ThreadLocalHandler;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpHeaders;
import io.vertx.ext.web.RoutingContext;
Expand All @@ -26,14 +23,9 @@ public void registerHealthCheckResponseProvider(Class<? extends HealthCheckRespo

public Handler<RoutingContext> uiHandler(String healthUiFinalDestination, String healthUiPath) {

Handler<RoutingContext> handler = new ThreadLocalHandler(new Supplier<Handler<RoutingContext>>() {
@Override
public Handler<RoutingContext> get() {
return StaticHandler.create().setAllowRootFileSystemAccess(true)
.setWebRoot(healthUiFinalDestination)
.setDefaultContentEncoding("UTF-8");
}
});
StaticHandler staticHandler = StaticHandler.create().setAllowRootFileSystemAccess(true)
.setWebRoot(healthUiFinalDestination)
.setDefaultContentEncoding("UTF-8");

return new Handler<RoutingContext>() {
@Override
Expand All @@ -49,7 +41,7 @@ public void handle(RoutingContext event) {
return;
}

handler.handle(event);
staticHandler.handle(event);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package io.quarkus.swaggerui.runtime;

import java.util.function.Supplier;

import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.vertx.http.runtime.ThreadLocalHandler;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpHeaders;
import io.vertx.ext.web.RoutingContext;
Expand All @@ -13,14 +10,9 @@
public class SwaggerUiRecorder {
public Handler<RoutingContext> handler(String swaggerUiFinalDestination, String swaggerUiPath) {

Handler<RoutingContext> handler = new ThreadLocalHandler(new Supplier<Handler<RoutingContext>>() {
@Override
public Handler<RoutingContext> get() {
return StaticHandler.create().setAllowRootFileSystemAccess(true)
.setWebRoot(swaggerUiFinalDestination)
.setDefaultContentEncoding("UTF-8");
}
});
StaticHandler staticHandler = StaticHandler.create().setAllowRootFileSystemAccess(true)
.setWebRoot(swaggerUiFinalDestination)
.setDefaultContentEncoding("UTF-8");

return new Handler<RoutingContext>() {
@Override
Expand All @@ -36,7 +28,7 @@ public void handle(RoutingContext event) {
return;
}

handler.handle(event);
staticHandler.handle(event);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Handler;
Expand Down Expand Up @@ -36,17 +35,11 @@ public Consumer<Route> start() {
if (hotDeploymentResourcePaths != null && !hotDeploymentResourcePaths.isEmpty()) {
for (Path resourcePath : hotDeploymentResourcePaths) {
String root = resourcePath.toAbsolutePath().toString();
ThreadLocalHandler staticHandler = new ThreadLocalHandler(new Supplier<Handler<RoutingContext>>() {
@Override
public Handler<RoutingContext> get() {
StaticHandler staticHandler = StaticHandler.create();
staticHandler.setCachingEnabled(false);
staticHandler.setAllowRootFileSystemAccess(true);
staticHandler.setWebRoot(root);
staticHandler.setDefaultContentEncoding("UTF-8");
return staticHandler;
}
});
StaticHandler staticHandler = StaticHandler.create();
staticHandler.setCachingEnabled(false);
staticHandler.setAllowRootFileSystemAccess(true);
staticHandler.setWebRoot(root);
staticHandler.setDefaultContentEncoding("UTF-8");
handlers.add(event -> {
try {
staticHandler.handle(event);
Expand All @@ -59,13 +52,7 @@ public Handler<RoutingContext> get() {
}
}
if (!knownPaths.isEmpty()) {
ThreadLocalHandler staticHandler = new ThreadLocalHandler(new Supplier<Handler<RoutingContext>>() {
@Override
public Handler<RoutingContext> get() {
return StaticHandler.create(META_INF_RESOURCES)
.setDefaultContentEncoding("UTF-8");
}
});
StaticHandler staticHandler = StaticHandler.create(META_INF_RESOURCES).setDefaultContentEncoding("UTF-8");
handlers.add(ctx -> {
String rel = ctx.mountPoint() == null ? ctx.normalisedPath()
: ctx.normalisedPath().substring(ctx.mountPoint().length());
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class VertxHttpRecorder {

public static final String MAX_REQUEST_SIZE_KEY = "io.quarkus.max-request-size";

// We don not use Integer.MAX on purpose to allow advanced users to register a route AFTER the default route
// We do not use Integer.MAX on purpose to allow advanced users to register a route AFTER the default route
public static final int DEFAULT_ROUTE_ORDER = 10_000;

private static final Logger LOGGER = Logger.getLogger(VertxHttpRecorder.class.getName());
Expand Down

0 comments on commit 9d408d8

Please sign in to comment.