Skip to content

Commit

Permalink
Merge pull request #13132 from ia3andy/fix-funky
Browse files Browse the repository at this point in the history
Revert Funqy root handling commit and add a new commit only for Funqy Knative
  • Loading branch information
patriot1burke authored Nov 9, 2020
2 parents 15d2c6d + 3a92792 commit b4c1995
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
import io.quarkus.funqy.deployment.FunctionBuildItem;
import io.quarkus.funqy.deployment.FunctionInitializedBuildItem;
import io.quarkus.funqy.runtime.FunqyConfig;
import io.quarkus.funqy.runtime.bindings.http.FunqyHttpBindingRecorder;
import io.quarkus.jackson.ObjectMapperProducer;
import io.quarkus.vertx.core.deployment.CoreVertxBuildItem;
Expand Down Expand Up @@ -58,7 +57,6 @@ public void staticInit(FunqyHttpBindingRecorder binding,
@BuildStep
@Record(RUNTIME_INIT)
public void boot(ShutdownContextBuildItem shutdown,
FunqyConfig funqyConfig,
FunqyHttpBindingRecorder binding,
BuildProducer<FeatureBuildItem> feature,
BuildProducer<RouteBuildItem> routes,
Expand All @@ -74,22 +72,19 @@ public void boot(ShutdownContextBuildItem shutdown,
feature.produce(new FeatureBuildItem(FUNQY_HTTP_FEATURE));

String rootPath = httpConfig.rootPath;
if (rootPath == null) {
rootPath = "/";
} else if (!rootPath.endsWith("/")) {
rootPath += "/";
}

Handler<RoutingContext> handler = binding.start(rootPath,
funqyConfig,
vertx.getVertx(),
shutdown,
beanContainer.getValue(),
executorBuildItem.getExecutorProxy());

routes.produce(new RouteBuildItem("/", handler, false));
for (FunctionBuildItem function : functions) {
if (rootPath == null)
rootPath = "/";
else if (!rootPath.endsWith("/"))
rootPath += "/";
String name = function.getFunctionName() == null ? function.getMethodName() : function.getFunctionName();
//String path = rootPath + name;
String path = "/" + name;
routes.produce(new RouteBuildItem(path, handler, false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

public class RootPathTest {
private static final String APP_PROPS = "" +
"quarkus.http.root-path=/api\n" +
"quarkus.funqy.export=get\n";
"quarkus.http.root-path=/api\n";

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
Expand All @@ -30,10 +29,6 @@ public void testGetOrPost() throws Exception {
.then().statusCode(200).body(equalTo("\"get\""));
RestAssured.given().post("/get")
.then().statusCode(200).body(equalTo("\"get\""));
RestAssured.given().get("/")
.then().statusCode(200).body(equalTo("\"get\""));
RestAssured.given().post("/")
.then().statusCode(200).body(equalTo("\"get\""));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static org.hamcrest.Matchers.equalTo;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand All @@ -18,13 +17,9 @@
import io.restassured.RestAssured;

public class SimpleTest {
private static final String APP_PROPS = "" +
"quarkus.funqy.export=toLowerCase\n";

@RegisterExtension
static QuarkusUnitTest test = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource(new StringAsset(APP_PROPS), "application.properties")
.addClasses(PrimitiveFunctions.class, GreetingFunctions.class, Greeting.class, GreetingService.class,
GreetingTemplate.class));

Expand All @@ -35,12 +30,6 @@ public void testString(String path) {
.then().statusCode(200).body(equalTo("\"hello\""));
}

@Test
public void testRoot() {
RestAssured.given().contentType("application/json").body("\"Hello\"").post("/")
.then().statusCode(200).body(equalTo("\"hello\""));
}

@ParameterizedTest
@ValueSource(strings = { "/doubleIt", "/doubleItAsync" })
public void testInt(String path) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import io.quarkus.funqy.runtime.FunctionConstructor;
import io.quarkus.funqy.runtime.FunctionInvoker;
import io.quarkus.funqy.runtime.FunctionRecorder;
import io.quarkus.funqy.runtime.FunqyConfig;
import io.quarkus.funqy.runtime.query.QueryObjectMapper;
import io.quarkus.funqy.runtime.query.QueryReader;
import io.quarkus.runtime.ShutdownContext;
Expand Down Expand Up @@ -60,7 +59,6 @@ private ObjectMapper getObjectMapper() {
}

public Handler<RoutingContext> start(String contextPath,
FunqyConfig funqyConfig,
Supplier<Vertx> vertx,
ShutdownContext shutdown,
BeanContainer beanContainer,
Expand All @@ -75,18 +73,6 @@ public void run() {
});
FunctionConstructor.CONTAINER = beanContainer;

final FunctionInvoker defaultInvoker;
if (funqyConfig.export.isPresent()) {
defaultInvoker = FunctionRecorder.registry.matchInvoker(funqyConfig.export.get());
if (defaultInvoker == null) {
throw new RuntimeException("quarkus.funqy.export value does not map a function: " + funqyConfig.export.get());
}
} else if (FunctionRecorder.registry.invokers().size() == 1) {
defaultInvoker = FunctionRecorder.registry.invokers().iterator().next();
} else {
defaultInvoker = null;
}

return new VertxRequestHandler(vertx.get(), defaultInvoker, beanContainer, contextPath, executor);
return new VertxRequestHandler(vertx.get(), beanContainer, contextPath, executor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ public class VertxRequestHandler implements Handler<RoutingContext> {
protected final CurrentIdentityAssociation association;
protected final CurrentVertxRequest currentVertxRequest;
protected final Executor executor;
protected final FunctionInvoker defaultInvoker;

public VertxRequestHandler(Vertx vertx,
FunctionInvoker defaultInvoker,
BeanContainer beanContainer,
String rootPath,
Executor executor) {
this.vertx = vertx;
this.defaultInvoker = defaultInvoker;
this.beanContainer = beanContainer;
// make sure rootPath ends with "/" for easy parsing
if (rootPath == null) {
Expand Down Expand Up @@ -79,12 +76,7 @@ public void handle(RoutingContext routingContext) {

path = path.substring(rootPath.length());

final FunctionInvoker invoker;
if (!path.isEmpty()) {
invoker = FunctionRecorder.registry.matchInvoker(path);
} else {
invoker = defaultInvoker;
}
FunctionInvoker invoker = FunctionRecorder.registry.matchInvoker(path);

if (invoker == null) {
routingContext.fail(404);
Expand Down

0 comments on commit b4c1995

Please sign in to comment.