diff --git a/.gitignore b/.gitignore index 4ad458a..63f293a 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ build/ ### Rust ### target/ + +### TomEE ### +.distribution diff --git a/integration-tests/tomee/README.md b/integration-tests/tomee/README.md new file mode 100644 index 0000000..703abfd --- /dev/null +++ b/integration-tests/tomee/README.md @@ -0,0 +1,8 @@ +# Running + +If you would like to run this web app in tomee, run: + +``` +mvn clean install tomee:exec +java -jar target/*-exec.jar +``` diff --git a/integration-tests/tomee/pom.xml b/integration-tests/tomee/pom.xml new file mode 100644 index 0000000..b4f0ae0 --- /dev/null +++ b/integration-tests/tomee/pom.xml @@ -0,0 +1,128 @@ + + + + 4.0.0 + + + io.roastedroot + proxy-wasm-java-host-parent + 999-SNAPSHOT + ../../pom.xml + + + proxy-wasm-integration-tests-tomee + war + ${project.artifactId} + + + 10.0.0 + false + 17 + 17 + + + + + com.google.code.gson + gson + 2.13.1 + + + io.roastedroot + proxy-wasm-jaxrs + + + org.apache.tomee.bom + tomee-webprofile + ${tomee.version} + provided + + + org.apache.tomee + tomee-webapp + + + + + + org.apache.tomee.bom + tomee-webprofile-api + ${tomee.version} + provided + + + junit + junit + 4.13.2 + test + + + org.apache.tomee + arquillian-tomee-embedded + ${tomee.version} + test + + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + 3.3.1 + test + + + + + + + com.dylibso.chicory + chicory-compiler-maven-plugin + ${chicory.version} + + + wasm-shim + + compile + + + io.roastedroot.proxywasm.jaxrs.it.internal.MainWasm + ../../proxy-wasm-java-host/src/test/go-examples/unit_tester/main.wasm + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.2.5 + + + ${project.version} + + + + + org.apache.tomee.maven + tomee-maven-plugin + ${tomee.version} + + ${tomee.version} + webprofile + + + + + diff --git a/integration-tests/tomee/src/main/java/io/roastedroot/proxywasm/jaxrs/it/App.java b/integration-tests/tomee/src/main/java/io/roastedroot/proxywasm/jaxrs/it/App.java new file mode 100644 index 0000000..6099331 --- /dev/null +++ b/integration-tests/tomee/src/main/java/io/roastedroot/proxywasm/jaxrs/it/App.java @@ -0,0 +1,31 @@ +package io.roastedroot.proxywasm.jaxrs.it; + +import com.google.gson.Gson; +import io.roastedroot.proxywasm.PluginFactory; +import io.roastedroot.proxywasm.jaxrs.it.internal.MainWasm; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Produces; +import java.util.Map; + +/** + * CDI producers for PluginFactory instances used in integration tests. + */ +@ApplicationScoped +public class App { + + private static final Gson gson = new Gson(); + + /** + * Configures the headerTests PluginFactory. + */ + @Produces + public PluginFactory headerTests() { + + return PluginFactory.builder(MainWasm.load()) + .withMachineFactory(MainWasm::create) + .withName("headerTests") + .withShared(true) + .withPluginConfig(gson.toJson(Map.of("type", "headerTests"))) + .build(); + } +} diff --git a/integration-tests/tomee/src/main/java/io/roastedroot/proxywasm/jaxrs/it/Resources.java b/integration-tests/tomee/src/main/java/io/roastedroot/proxywasm/jaxrs/it/Resources.java new file mode 100644 index 0000000..2fe2f51 --- /dev/null +++ b/integration-tests/tomee/src/main/java/io/roastedroot/proxywasm/jaxrs/it/Resources.java @@ -0,0 +1,26 @@ +package io.roastedroot.proxywasm.jaxrs.it; + +import io.roastedroot.proxywasm.jaxrs.ProxyWasm; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.HeaderParam; +import jakarta.ws.rs.Path; + +/** + * JAX-RS resource class providing endpoints for integration tests. + */ +@Path("/") +public class Resources { + + /** + * Endpoint for testing header manipulation with a shared Wasm plugin instance. + * + * @param counter The value of the "x-request-counter" header. + * @return A string indicating the counter value. + */ + @Path("/headerTests") + @GET + @ProxyWasm("headerTests") + public String headerTests(@HeaderParam("x-request-counter") String counter) { + return String.format("counter: %s", counter); + } +} diff --git a/integration-tests/tomee/src/main/webapp/WEB-INF/beans.xml b/integration-tests/tomee/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000..bf9ad39 --- /dev/null +++ b/integration-tests/tomee/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,6 @@ + + \ No newline at end of file diff --git a/integration-tests/tomee/src/test/java/io/roastedroot/proxywasm/jaxrs/it/ResourceTest.java b/integration-tests/tomee/src/test/java/io/roastedroot/proxywasm/jaxrs/it/ResourceTest.java new file mode 100644 index 0000000..3fa882e --- /dev/null +++ b/integration-tests/tomee/src/test/java/io/roastedroot/proxywasm/jaxrs/it/ResourceTest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.roastedroot.proxywasm.jaxrs.it; + +import jakarta.ws.rs.client.ClientBuilder; +import java.io.File; +import java.net.URL; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.asset.FileAsset; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.jboss.shrinkwrap.resolver.api.maven.Maven; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(Arquillian.class) +public class ResourceTest extends Assert { + + @ArquillianResource private URL webappUrl; + + @Deployment(testable = false) + public static WebArchive createDeployment() { + + // Get GAV coordinates from system properties set by Maven + String version = System.getProperty("proxy.wasm.version", "999-SNAPSHOT"); + String gav = "io.roastedroot:proxy-wasm-jaxrs:" + version; + + return ShrinkWrap.create(WebArchive.class) + .addClasses(Resources.class, App.class) + .addAsLibraries(Maven.resolver().resolve(gav).withTransitivity().asFile()) + .addAsWebInfResource( + new FileAsset(new File("src/main/webapp/WEB-INF/beans.xml")), "beans.xml"); + } + + @Test + public void test() throws Exception { + final var webTarget = ClientBuilder.newClient().target(webappUrl.toURI()); + + var response = webTarget.path("/headerTests").request().get(); + assertEquals(200, response.getStatus()); + assertEquals("1", response.getHeaderString("x-response-counter")); + assertEquals("counter: 1", response.readEntity(String.class)); + + response = webTarget.path("/headerTests").request().get(); + assertEquals(200, response.getStatus()); + assertEquals("2", response.getHeaderString("x-response-counter")); + assertEquals("counter: 2", response.readEntity(String.class)); + } +} diff --git a/integration-tests/tomee/src/test/resources/arquillian.xml b/integration-tests/tomee/src/test/resources/arquillian.xml new file mode 100644 index 0000000..30dbfd6 --- /dev/null +++ b/integration-tests/tomee/src/test/resources/arquillian.xml @@ -0,0 +1,26 @@ + + + + + + -1 + -1 + -1 + + + diff --git a/pom.xml b/pom.xml index 6fc3849..d0cacec 100644 --- a/pom.xml +++ b/pom.xml @@ -78,6 +78,21 @@ + + + + io.roastedroot + proxy-wasm-java-host + ${project.version} + + + io.roastedroot + proxy-wasm-jaxrs + ${project.version} + + + + @@ -369,6 +384,17 @@ + + + jdk17-modules + + [17,) + + + integration-tests/tomee + + + diff --git a/proxy-wasm-jaxrs/src/main/resources/META-INF/beans.xml b/proxy-wasm-jaxrs/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000..e1dbba5 --- /dev/null +++ b/proxy-wasm-jaxrs/src/main/resources/META-INF/beans.xml @@ -0,0 +1,9 @@ + + + + io.roastedroot.proxywasm.jaxrs.cdi.ServerAdaptor + + \ No newline at end of file