Skip to content

Commit

Permalink
Update interceptors.adoc
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang authored Jun 25, 2024
1 parent 1a2aa6d commit d6993a9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docs/plugins/interceptors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public class MyPlugin implements JsonService {
|`interceptPoint`
|the intercept point: `REQUEST_BEFORE_EXCHANGE_INIT`, `REQUEST_BEFORE_AUTH`, `REQUEST_AFTER_AUTH`, `RESPONSE`, `RESPONSE_ASYNC`
|no
|`REQUEST_AFTER_AUTH`
|`requiresContent`
|proxy interceptor
|Only used by Interceptors of proxied resources (the content is always available to Interceptor of Services) Set it to `true` to make available the content of the request (if interceptPoint is `REQUEST_BEFORE_AUTH` or `REQUEST_AFTER_AUTH`) or of the response (if interceptPoint is `RESPONSE` or `RESPONSE_ASYNC`)
|no
|`false`
Expand All @@ -107,6 +107,19 @@ public class MyPlugin implements JsonService {
|`10`
|===

**Intercept Point Note: `REQUEST_BEFORE_EXCHANGE_INIT`**

An interceptor using this intercept point will handle requests before the exchange initialization occurs. Such interceptors must implement the `WildcardInterceptor` interface, ensuring that the `Interceptor.handle(request, response)` method receives both `UninitializedRequest` and `UninitializedResponse` objects.

Additionally, interceptors at this stage may:

- Provide a custom initializer for requests by using `PluginUtils.attachCustomRequestInitializer()`.
- Modify the raw content of the request using `Request.setRawContent()`.

This setup allows for preliminary modifications and configurations to be applied to requests at an early stage in the processing pipeline.

---

== Transforming Request Content Format

Interceptors at `REQUEST_BEFORE_EXCHANGE_INIT` can inspect and modify the request before it is initialized. `The handle(req, res)` and `resolve(req, res)` methods receive the request as `UninitializedRequest` and the response as `UninitializedResponse`. This is particularly useful for transforming request content formats.
Expand All @@ -133,4 +146,4 @@ public class XmlToBsonTransformer implements WildcardInterceptor {

IMPORTANT: Only `WildcardInterceptor` can use the `REQUEST_BEFORE_EXCHANGE_INIT` intercept point.

For a practical example of transforming request and response content to and from a different format than expected by a service, refer to the link:https://github.com/SoftInstigate/restheart/tree/master/examples/protobuffer-contacts[protobuffer-contacts] example.
For a practical example of transforming request and response content to and from a different format than expected by a service, refer to the link:https://github.com/SoftInstigate/restheart/tree/master/examples/protobuffer-contacts[protobuffer-contacts] example.

0 comments on commit d6993a9

Please sign in to comment.