Skip to content

Commit

Permalink
Add workarounds for quarkusio/quarkus#4407
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Oct 7, 2019
1 parent a0d9ab0 commit 9a79c0b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 46 deletions.
Expand Up @@ -93,15 +93,27 @@ protected void doStart() throws Exception {

Config cfg = ConfigProvider.getConfig();
final BodyHandler bodyHandler = BodyHandler.create();
/* Keep in sync with how the BodyHandler is configured in io.quarkus.vertx.web.runtime.VertxWebRecorder
* Eventually, VertxWebRecorder should have a method to do this for us. */
/*
* Keep in sync with how the BodyHandler is configured in io.quarkus.vertx.web.runtime.VertxWebRecorder
* Eventually, VertxWebRecorder should have a method to do this for us.
*
* TODO: remove this code when moving to quarkus 0.24.x, see https://github.com/quarkusio/quarkus/pull/4314
*/
cfg.getOptionalValue("quarkus.http.body.handle-file-uploads", boolean.class).ifPresent(bodyHandler::setHandleFileUploads);
cfg.getOptionalValue("quarkus.http.body.uploads-directory", String.class).ifPresent(bodyHandler::setUploadsDirectory);
cfg.getOptionalValue("quarkus.http.body.delete-uploaded-files-on-end", boolean.class).ifPresent(bodyHandler::setDeleteUploadedFilesOnEnd);
cfg.getOptionalValue("quarkus.http.body.merge-form-attributes", boolean.class).ifPresent(bodyHandler::setMergeFormAttributes);
cfg.getOptionalValue("quarkus.http.body.preallocate-body-buffer", boolean.class).ifPresent(bodyHandler::setPreallocateBodyBuffer);

newRoute
//
// This should not be needed but because the default route added by quarkus (i.e. in case
// the quarkus-resteasy extension is in the classpath) is a catch all, it is required to
// configure the route to be evaluated before the default one.
//
// TODO: remove this after https://github.com/quarkusio/quarkus/issues/4407 is fixed.
//
.order(-1)
.handler(bodyHandler)
.handler(ctx -> {
try {
Expand Down
13 changes: 13 additions & 0 deletions integration-tests/platform-http/pom.xml
Expand Up @@ -36,6 +36,14 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-platform-http</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand All @@ -48,6 +56,11 @@
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Expand Up @@ -16,11 +16,22 @@
*/
package org.apache.camel.quarkus.component.platform.http.it;

// TODO: investigate why adding resteasy break the platform http component
//@Path("/test")
//@ApplicationScoped
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.camel.component.platform.http.PlatformHttpConstants;
import org.apache.camel.spi.Registry;

@Path("/test")
@ApplicationScoped
public class PlatformHttpResource {
/*
@Inject
Registry registry;

Expand All @@ -36,12 +47,11 @@ public JsonObject inspectRegistry() {
if (engine != null) {
builder.add(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME, engine.getClass().getName());

}if (component != null) {
}
if (component != null) {
builder.add(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, component.getClass().getName());
}

return builder.build();
}
*/
}
Expand Up @@ -17,33 +17,12 @@
package org.apache.camel.quarkus.component.platform.http.it;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.platform.http.PlatformHttpConstants;
import org.apache.camel.spi.Registry;

public class PlatformHttpRouteBuilder extends RouteBuilder {

@Override
public void configure() {
from("platform-http:/platform-http/hello?httpMethodRestrict=GET").setBody(simple("Hello ${header.name}"));
from("platform-http:/platform-http/get-post?httpMethodRestrict=GET,POST").setBody(simple("Hello ${body}"));
from("platform-http:/platform-http/multipart?httpMethodRestrict=POST").setBody(simple("Hello ${body}"));

fromF("platform-http:/platform-http/registry/%s", PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME).process().message(m -> {
Registry registry = m.getExchange().getContext().getRegistry();
Object answer = registry.lookupByName(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME);

if (answer != null) {
m.setBody(answer.getClass().getName());
}
});

fromF("platform-http:/platform-http/registry/%s", PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME).process().message(m -> {
Registry registry = m.getExchange().getContext().getRegistry();
Object answer = registry.lookupByName(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME);

if (answer != null) {
m.setBody(answer.getClass().getName());
}
});
}
}
Expand Up @@ -25,24 +25,23 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;

@QuarkusTest
class PlatformHttpTest {
@Disabled("looks like adding resteasy break the component")
@Test
public void testRegistrySetUp() {

JsonPath p = RestAssured.given()
.get("/test/registry/inspect")
.then()
.statusCode(200)
.extract()
.body()
.jsonPath();
.body()
.jsonPath();

//assertThat(p.getString(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME)).isEqualTo(QuarkusPlatformHttpEngine.class.getName());
//assertThat(p.getString(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME)).isEqualTo(PlatformHttpComponent.class.getName());
assertThat(p.getString(PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME)).isEqualTo(QuarkusPlatformHttpEngine.class.getName());
assertThat(p.getString(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME)).isEqualTo(PlatformHttpComponent.class.getName());
}

@Test
Expand All @@ -54,27 +53,24 @@ public void basic() {
.statusCode(200)
.body(equalTo("Hello Kermit"));

RestAssured.post("/platform-http/hello").then().statusCode(405);

RestAssured.given()
.body("Camel")
.post("/platform-http/get-post")
.then()
.statusCode(200)
.body(equalTo("Hello Camel"));

RestAssured.given()
.get("/platform-http/get-post")
.then()
.statusCode(200)
.body(equalTo("Hello ")); // there is no body for get
}

RestAssured.given().get("/platform-http/registry/" + PlatformHttpConstants.PLATFORM_HTTP_ENGINE_NAME)
.then()
.statusCode(200)
.body(equalTo(QuarkusPlatformHttpEngine.class.getName()));
RestAssured.given().get("/platform-http/registry/" + PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME)
.then()
.statusCode(200)
.body(equalTo(PlatformHttpComponent.class.getName()));
@Disabled("See https://github.com/quarkusio/quarkus/issues/4408")
@Test
public void testInvalidMethod() {
RestAssured.post("/platform-http/hello")
.then().statusCode(405);
}
}

0 comments on commit 9a79c0b

Please sign in to comment.