Elffuss BraidHub

kikocis/EDC public

main · 5.3 KiBRenderedRawPermalink
1# Data Plane HTTP extension
2
3## Background
4
5### Scope
6
7This extension provides support for sending data sourced from an HTTP endpoint and posting data to an HTTP endpoint. By
8nature of the DPF design, which supports _n_-way transfers, HTTP-sourced data can be sent to any `DataSink` type and an
9HTTP endpoint can receive data from any `DataSource` type. The extension is designed to stream content to limit memory
10consumption under load.
11
12### Use Cases
13
14Typically, this extension is used to fetch or post data from/to a REST endpoint.
15
16## Technical Details
17
18### Dependencies
19
20| Name | Description |
21|:-------------------------------------|:----------------------|
22| extensions:data-plane:data-plane-spi | SPI of the data plane |
23
24### Provided Services
25
26#### `HttpRequestParamsProvider`
27This service could be used to register HTTP params decorators (implementors of `HttpParamsDecorator`), that will be
28invoked before the HTTP request creation, both on `source` and on `sink` sides. This can be useful, to enhance the request
29adding some headers with for example some data flow related info like "transferId" or "contractId".
30
31To register a decorator, you can inject the `HttpRequestParamsProvider` and use one of the register methods:
32- `registerSourceDecorator`: register the decorator that will be used for every source request
33- `registerSinkDecorator`: register the decorator that will be used for every sink request
34
35Example:
36```java
37public class CustomDecoratorExtension implements ServiceExtension {
38
39 @Inject
40 private HttpRequestParamsProvider paramsProvider;
41
42 public void initialize(ServiceExtensionContext context) {
43 paramsProvider.registerSourceDecorator((request, address, builder) -> builder.header("customSourceHeader", "customValue"));
44 paramsProvider.registerSinkDecorator((request, address, builder) -> builder.header("customSinkHeader", "customValue"));
45 }
46}
47```
48
49
50## Design Principles
51
52This extension provides implementations for `HttpDataSourceFactory`, `HttpDataSinkFactory`, `HttpDataSource` and `HttpDataSink`, which are triggered when
53the `DataFlowRequest` type is `HttpData`.
54
55Basically the role of these classes is to extract the parameters (query params, path, body, auth header...) required to hit the HTTP endpoint and then to perform the call.
56
57The table below summarizes how each parameter is retrieved for the source/sink implementations.
58
59| Parameter | `HttpDataSource` | `HttpDataSink` | Example |
60|:--------------------------|:-------------------------------------------------------------------------------------------------------------|:------------------------------------------------------------------|:-------------------------------------|
61| Base url | Source/destination `DataAddress` | Same | http://example.com |
62| Authorization header key | Source/destination `DataAddress` | Same | Api-Key |
63| Authorization header code | Source/destination `DataAddress`, which can either contains the secret value, or the `Vault` secret name | Same | 8e631012-f6de-11ec-b939-0242ac120002 |
64| Headers | Source/destination `DataAddress` | Same | foo:bar;hello:world |
65| Path | `DataFlowRequest` properties if path proxy enabled by the source `DataAddress` | Destination `DataAddress` | foo/bar |
66| Query params | `DataFlowRequest` properties if query param proxy enabled by the source `DataAddress` | Destination `DataAddress` | hello=world&foo=bar |
67| Method | `DataFlowRequest` properties if method proxy enabled by the source `DataAddress`, otherwise default to `GET` | Destination `DataAddress` if present, otherwise `POST` by default | GET, POST... |
68| Content type | `DataFlowRequest` properties if body proxy enabled by the source `DataAddress` | Destination `DataAddress` | application/json |
69| Body | `DataFlowRequest` properties if body proxy enabled by the source `DataAddress` | `Part` stream fetched by the `DataSource` | "hello world!" |
70| NonChunkedTransfer | Not used | Destination `DataAddress` if present, otherwise `true` by default | "false" |