You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Java host implementation for Proxy-Wasm, enabling developers to run Proxy-Wasm plugins in JAX-RS.
5
+
The Java host implementation for proxy-wasm, enabling developer to run Proxy-Wasm plugins in Java.
6
6
7
7
## Docs
8
8
9
-
TODO: still need to document how to use in non-cdi containers.
10
-
11
9
If your using Quarkus, see the [Quarkus Proxy-Wasm Extension](https://docs.quarkiverse.io/quarkus-proxy-wasm/dev/index.html) docs.
12
10
13
11
## Building
@@ -17,3 +15,185 @@ To build the project, you need to have Maven installed. You can build the projec
17
15
```bash
18
16
mvn clean install
19
17
```
18
+
19
+
## Overview
20
+
21
+
Proxy-Wasm is a plugin system for network proxies. It lets you write plugins that can act as request filters in a
22
+
portable, sandboxed, and language-agnostic way, thanks to WebAssembly.
23
+
24
+
This Quarkus extension allows you to use Proxy-Wasm plugins to filter requests to Jakarta REST (formerly known as JAX-RS)
25
+
endpoints.
26
+
27
+
Adding a Proxy-Wasm plugin to a JAX-RS for a "waf" proxy-wasm module is as simple as adding a `@ProxyWasm` annotation
28
+
to a method or class:
29
+
30
+
```java
31
+
packageorg.example;
32
+
33
+
importjakarta.ws.rs.GET;
34
+
importjakarta.ws.rs.Path;
35
+
importjakarta.ws.rs.Produces;
36
+
importjakarta.ws.rs.core.MediaType;
37
+
importio.roastedroot.proxywasm.jaxrs.ProxyWasm;
38
+
39
+
@Path("/example")
40
+
publicclassExample {
41
+
42
+
@GET
43
+
@Produces(MediaType.TEXT_PLAIN)
44
+
@ProxyWasm("waf")
45
+
publicStringhello() {
46
+
return"hello";
47
+
}
48
+
}
49
+
```
50
+
51
+
### Configuring the Plugin with CDI
52
+
53
+
Configuring the Proxy-Wasm plugin is easy in a CDI container like Quarkus or TomEE. You produce it with
54
+
a `@ApplicationScoped``@Produces` method, which returns a `PluginFactory` instance.
55
+
56
+
Below is an example that uses the [`PluginFactory.builder()`](https://javadoc.io/doc/io.roastedroot/proxy-wasm-java-host/latest/io/roastedroot/proxywasm/PluginFactory.Builder.html) API to create a `PluginFactory`:
.withPluginConfig(" ... the config passed to the plugin ... ")
79
+
.withMetricsHandler(newSimpleMetricsHandler())
80
+
.build();
81
+
}
82
+
}
83
+
```
84
+
85
+
### Non-CDI Configuration
86
+
87
+
Setting up non-CDI is also possible, but more complicated. If anyone is interested helping document this, please
88
+
send in a PR. Here is link to where we [configure the ProxyWasmFeature](https://github.com/roastedroot/proxy-wasm-java-host/blob/main/proxy-wasm-jaxrs/src/test/java/io/roastedroot/proxywasm/jaxrs/example/tests/BaseTest.java#L34)
89
+
for a Jersey based test case.
90
+
91
+
### Compiling WASM to Bytecode
92
+
93
+
By default, WASM modules are executed using the [Chicory](https://chicory.dev/) interpreter. But if you want the WASM code to
94
+
run a near native speed, you should compile the WASM to Java bytecode using the chicory WASM to bytecode compiler.
95
+
Chicory supports compiling the WASM module at either build time or runtime.
96
+
97
+
#### Runtime Compilation
98
+
99
+
To enable runtime compilation, you need just need to add the following dependency to your `pom.xml`:
100
+
101
+
```xml
102
+
<dependency>
103
+
<groupId>com.dylibso.chicory</groupId>
104
+
<artifactId>compiler</artifactId>
105
+
</dependency>
106
+
```
107
+
108
+
You then enable it on the PluginFactory builder by using it as the machine factory:
0 commit comments