Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "maven" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: daily
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
*
* <p>Apply this annotation to JAX-RS resource classes or methods to enable filtering
* by the Proxy-Wasm plugins identified by the names specified in the {@link #value()} attribute.
* The {@link WasmPluginFeature} must be registered for this annotation to have effect.
* The {@link ProxyWasmFeature} must be registered for this annotation to have effect.
*
* @see WasmPluginFeature
* @see WasmPluginFilter
* @see ProxyWasmFeature
* @see ProxyWasmFilter
*/
@NameBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface WasmPlugin {
public @interface ProxyWasm {
/**
* Specifies the names of the Proxy-Wasm plugins that should filter the annotated
* resource class or method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import io.roastedroot.proxywasm.PluginFactory;
import io.roastedroot.proxywasm.StartException;
import io.roastedroot.proxywasm.internal.ServerAdaptor;
import io.roastedroot.proxywasm.jaxrs.internal.AbstractWasmPluginFeature;
import io.roastedroot.proxywasm.jaxrs.internal.AbstractProxyWasmFeature;
import java.util.Arrays;
import java.util.List;

/**
* A JAX-RS {@link jakarta.ws.rs.core.Feature} that enables Proxy-Wasm plugin filtering
* for JAX-RS applications. This feature registers the necessary {@link WasmPluginFilter}
* to intercept requests and responses for resources annotated with {@link WasmPlugin}.
* for JAX-RS applications. This feature registers the necessary {@link ProxyWasmFilter}
* to intercept requests and responses for resources annotated with {@link ProxyWasm}.
*
* <p>To use this feature, register an instance of it with your JAX-RS application, providing
* the required {@link ServerAdaptor} and a list of {@link PluginFactory} instances.
*
* <p>If you are using a CDI container like quarkus, you will be using the
* {@link io.roastedroot.proxywasm.jaxrs.cdi.WasmPluginFeature} instead.
* {@link io.roastedroot.proxywasm.jaxrs.cdi.ProxyWasmFeature} instead.
*
* <pre>
* public class MyApplication extends jakarta.ws.rs.core.Application {
Expand All @@ -34,24 +34,24 @@
* // Assuming a ServerAdaptor and PluginFactory are available
* ServerAdaptor serverAdaptor = ...;
* PluginFactory myPluginFactory = ...;
* singletons.add(new WasmPluginFeature(serverAdaptor, myPluginFactory));
* singletons.add(new ProxyWasmFeature(serverAdaptor, myPluginFactory));
* } catch (StartException e) {
* throw new RuntimeException("Failed to initialize WasmPluginFeature", e);
* throw new RuntimeException("Failed to initialize ProxyWasmFeature", e);
* }
* return singletons;
* }
* }
* </pre>
*
* @see WasmPlugin
* @see WasmPluginFilter
* @see ProxyWasm
* @see ProxyWasmFilter
* @see PluginFactory
* @see ServerAdaptor
*/
public class WasmPluginFeature extends AbstractWasmPluginFeature {
public class ProxyWasmFeature extends AbstractProxyWasmFeature {

/**
* Constructs a new WasmPluginFeature.
* Constructs a new ProxyWasmFeature.
*
* @param httpServer The {@link ServerAdaptor} used to adapt JAX-RS specific request/response
* objects for the Proxy-Wasm host.
Expand All @@ -60,13 +60,13 @@ public class WasmPluginFeature extends AbstractWasmPluginFeature {
* @throws StartException If an error occurs during the initialization or startup of the
* underlying Proxy-Wasm plugins.
*/
public WasmPluginFeature(ServerAdaptor httpServer, PluginFactory... factories)
public ProxyWasmFeature(ServerAdaptor httpServer, PluginFactory... factories)
throws StartException {
this(httpServer, Arrays.asList(factories));
}

/**
* Constructs a new WasmPluginFeature with a list of factories.
* Constructs a new ProxyWasmFeature with a list of factories.
*
* @param httpServer The {@link ServerAdaptor} used to adapt JAX-RS specific request/response
* objects for the Proxy-Wasm host.
Expand All @@ -75,7 +75,7 @@ public WasmPluginFeature(ServerAdaptor httpServer, PluginFactory... factories)
* @throws StartException If an error occurs during the initialization or startup of the
* underlying Proxy-Wasm plugins.
*/
public WasmPluginFeature(ServerAdaptor httpServer, List<PluginFactory> factories)
public ProxyWasmFeature(ServerAdaptor httpServer, List<PluginFactory> factories)
throws StartException {
init(factories, httpServer);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,31 @@
* and {@link WriterInterceptor} interfaces to intercept HTTP requests and responses,
* allowing Proxy-Wasm plugins to process them.
*
* <p>This filter is registered by the {@link WasmPluginFeature}. It interacts with
* <p>This filter is registered by the {@link ProxyWasmFeature}. It interacts with
* {@link Plugin} instances obtained from configured {@link Pool}s to execute the
* appropriate Proxy-Wasm ABI functions (e.g., {@code on_http_request_headers},
* {@code on_http_response_body}) at different stages of the JAX-RS request/response lifecycle.
*
* @see WasmPluginFeature
* @see WasmPlugin
* @see ProxyWasmFeature
* @see ProxyWasm
* @see Plugin
*/
public class WasmPluginFilter
public class ProxyWasmFilter
implements ContainerRequestFilter, WriterInterceptor, ContainerResponseFilter {

private static final String FILTER_CONTEXT = PluginHttpContext.class.getName() + ".context";

private static final Logger LOGGER = Logger.getLogger(WasmPluginFilter.class.getName());
private static final Logger LOGGER = Logger.getLogger(ProxyWasmFilter.class.getName());

private final List<Pool> pluginPools;

/**
* Constructs a WasmPluginFilter.
* Constructs a ProxyWasmFilter.
*
* @param pluginPools A list of {@link Pool} instances, each managing a pool of {@link Plugin}
* instances for a specific Wasm module.
*/
public WasmPluginFilter(List<Pool> pluginPools) {
public ProxyWasmFilter(List<Pool> pluginPools) {
this.pluginPools = List.copyOf(pluginPools);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import io.roastedroot.proxywasm.PluginFactory;
import io.roastedroot.proxywasm.StartException;
import io.roastedroot.proxywasm.internal.ServerAdaptor;
import io.roastedroot.proxywasm.jaxrs.internal.AbstractWasmPluginFeature;
import io.roastedroot.proxywasm.jaxrs.ProxyWasmFilter;
import io.roastedroot.proxywasm.jaxrs.internal.AbstractProxyWasmFeature;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
Expand All @@ -26,11 +27,11 @@
* will then automatically register the necessary filters.
*
* <p>Note: This class is intended for use in CDI environments. If you are not using CDI, you can
* use the {@link io.roastedroot.proxywasm.jaxrs.WasmPluginFeature} class directly to register the
* use the {@link io.roastedroot.proxywasm.jaxrs.ProxyWasmFeature} class directly to register the
* feature with your JAX-RS application.
*
* @see io.roastedroot.proxywasm.jaxrs.WasmPluginFeature
* @see io.roastedroot.proxywasm.jaxrs.WasmPluginFilter
* @see io.roastedroot.proxywasm.jaxrs.ProxyWasmFeature
* @see ProxyWasmFilter
* @see PluginFactory
* @see ServerAdaptor
* @see Provider
Expand All @@ -40,19 +41,19 @@
*/
@Provider
@ApplicationScoped
public class WasmPluginFeature extends AbstractWasmPluginFeature {
public class ProxyWasmFeature extends AbstractProxyWasmFeature {

@Inject Instance<PluginFactory> factories;

@Inject @Any ServerAdaptor serverAdaptor;

/**
* Creates a new instance of the WasmPluginFeature.
* Creates a new instance of the ProxyWasmFeature.
*/
public WasmPluginFeature() {}
public ProxyWasmFeature() {}

/**
* Initializes the WasmPluginFeature using injected CDI dependencies.
* Initializes the ProxyWasmFeature using injected CDI dependencies.
* This method is automatically called by the CDI container after dependency injection
* is complete.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import io.roastedroot.proxywasm.internal.Plugin;
import io.roastedroot.proxywasm.internal.Pool;
import io.roastedroot.proxywasm.internal.ServerAdaptor;
import io.roastedroot.proxywasm.jaxrs.WasmPlugin;
import io.roastedroot.proxywasm.jaxrs.WasmPluginFilter;
import io.roastedroot.proxywasm.jaxrs.ProxyWasm;
import io.roastedroot.proxywasm.jaxrs.ProxyWasmFilter;
import jakarta.ws.rs.container.DynamicFeature;
import jakarta.ws.rs.container.ResourceInfo;
import jakarta.ws.rs.core.FeatureContext;
Expand All @@ -15,7 +15,7 @@
import java.util.HashMap;
import java.util.stream.Collectors;

public abstract class AbstractWasmPluginFeature implements DynamicFeature {
public abstract class AbstractProxyWasmFeature implements DynamicFeature {

private final HashMap<String, Pool> pluginPools = new HashMap<>();

Expand Down Expand Up @@ -68,11 +68,11 @@ public void configure(ResourceInfo resourceInfo, FeatureContext context) {

var resourceMethod = resourceInfo.getResourceMethod();
if (resourceMethod != null) {
WasmPlugin pluignNameAnnotation = resourceMethod.getAnnotation(WasmPlugin.class);
ProxyWasm pluignNameAnnotation = resourceMethod.getAnnotation(ProxyWasm.class);
if (pluignNameAnnotation == null) {
// If no annotation on method, check the class level
pluignNameAnnotation =
resourceInfo.getResourceClass().getAnnotation(WasmPlugin.class);
resourceInfo.getResourceClass().getAnnotation(ProxyWasm.class);
}
if (pluignNameAnnotation != null) {
var pools =
Expand All @@ -95,7 +95,7 @@ public void configure(ResourceInfo resourceInfo, FeatureContext context) {
}
})
.collect(Collectors.toList());
context.register(new WasmPluginFilter(pools));
context.register(new ProxyWasmFilter(pools));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.roastedroot.proxywasm.jaxrs.example;

import io.roastedroot.proxywasm.jaxrs.WasmPlugin;
import io.roastedroot.proxywasm.jaxrs.ProxyWasm;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.POST;
Expand Down Expand Up @@ -37,42 +37,42 @@ public Response ok() {

@Path("/headerTests")
@GET
@WasmPlugin("headerTests")
@ProxyWasm("headerTests")
public String httpHeaders(@HeaderParam("x-request-counter") String counter) {
return String.format("counter: %s", counter);
}

@Path("/headerTestsNotShared")
@GET
@WasmPlugin("headerTestsNotShared")
@ProxyWasm("headerTestsNotShared")
public String notSharedHttpHeaders(@HeaderParam("x-request-counter") String counter) {
return String.format("counter: %s", counter);
}

@Path("/tickTests/{sub: .+ }")
@GET
@WasmPlugin("tickTests")
@ProxyWasm("tickTests")
public String tickTests(@PathParam("sub") String sub) {
return "hello world";
}

@Path("/ffiTests/reverse")
@POST
@WasmPlugin("ffiTests")
@ProxyWasm("ffiTests")
public String ffiTests(String body) {
return body;
}

@Path("/httpCallTests")
@GET
@WasmPlugin("httpCallTests")
@ProxyWasm("httpCallTests")
public String httpCallTests() {
return "hello world";
}

@Path("/httpCallTestsAndFFI")
@GET
@WasmPlugin({"ffiTests", "httpCallTests"})
@ProxyWasm({"ffiTests", "httpCallTests"})
public String httpCallTestsAndFFI() {
return "hello world";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.roastedroot.proxywasm.jaxrs.example.tests;

import io.restassured.specification.RequestSpecification;
import io.roastedroot.proxywasm.jaxrs.WasmPluginFeature;
import io.roastedroot.proxywasm.jaxrs.ProxyWasmFeature;
import io.roastedroot.proxywasm.jaxrs.example.App;
import io.roastedroot.proxywasm.jaxrs.example.Resources;
import io.roastedroot.proxywasm.jaxrs.internal.BlockingServerAdaptor;
Expand Down Expand Up @@ -30,9 +30,9 @@ public void setUp() throws Exception {
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(Resources.class);

// Create mock Instance<PluginFactory> for WasmPluginFeature
// Create mock Instance<PluginFactory> for ProxyWasmFeature
resourceConfig.register(
new WasmPluginFeature(
new ProxyWasmFeature(
new BlockingServerAdaptor(),
App.headerTests(),
App.headerTestsNotShared(),
Expand Down