Elffuss BraidHub

kikocis/EDC public

cc2a9ff178c4 · 3.6 KiBRenderedRawPermalink
1# JSON-LD Processing Architecture
2
3The Dataspace Protocol requires all protocol message types to be serialized as JSON-LD. The IDS REST binding specifications further define how those serialized message types are bound to
4endpoints over HTTPS. Controller endpoints will be added to the EDC that support marshalling and unmarshalling JSON-LD messages. These controllers will operate on native JSON
5structures (since JSON-LD is valid JSON) as opposed to typed Java representations. This will allow the EDC to remove its dependency on the IDS InfoModel Java Library and to provide
6full support for JSON-LD message exchanges.
7
8A common JSON-LD processing architecture is required by these controller endpoints, which may be deployed to individual runtimes such as the control plane and catalog systems. In
9addition, the Management API will adopt support for JSON-LD. This document lays out the common processing architecture that will support those requirements.
10
11## JSON-LD Support
12
13JSON-LD support can be added to the existing `TypeManager` infrastructure by creating a __serializer context__ that is configured with JSONP support in a JSON-LD EDC extension:
14
15```
16var mapper = new ObjectMapper();
17
18mapper.registerModule(new JSONPModule());
19
20var module = new SimpleModule() {
21
22 @Override
23 public void setupModule(SetupContext context){
24 super.setupModule(context);
25 }
26
27};
28
29mapper.registerModule(module);
30
31typeManager.registerContext("json-ld",mapper)
32```
33
34This context can then be used in conjunction with the [Titanium JSON-LD Library](https://github.com/filip26/titanium-json-ld) when processing messages:
35
36```
37// message is de-serialized as Map<String, Object> by Jersey
38var document = JsonDocument.of(mapper.convertValue(message, JsonObject.class));
39
40try {
41
42 var compacted = JsonLd.compact(document,EMPTY_CONTEXT).get();
43 var convertedDocument = mapper.convertValue(compacted,Map.class);
44
45 // process converted document
46
47} catch(JsonLdError e) {
48 throw new RuntimeException(e);
49}
50```
51
52### JSON-LD Document Loaders
53
54JSON-LD allows references to external documents that contain context information. EDC should provide a default loader and extensibility point for resolving and caching external
55document contexts, `JsonLdDocumentResolverRegistry`. This extensibility point should be provided by a generic JSON-LD extension, as it may be reused outside of IDS.
56
57The Titanium interface for loading referenced documents is `DocumentLoader`:
58
59```
60public interface DocumentLoader {
61
62 /**
63 * Retrieve a remote document.
64 *
65 * @param url of the remote document to fetch
66 * @param options to set the behavior of the loader
67 * @return {@link Document} representing a remote document
68 * @throws JsonLdError
69 */
70 Document loadDocument(URI url, DocumentLoaderOptions options) throws JsonLdError;
71}
72
73```
74
75EDC will provide an implementation that:
76
771. Resolves documents from a local file system directory (which can be a read-only docker mount)
782. Delegates to `JsonLdDocumentResolver` implementations via the `JsonLdDocumentResolverRegistry`.
79
80`JsonLdDocumentResolver` should not expose Titanium classes. It should return a `JsonStructure` which can be wrapped in a Titanium `Document` by the EDC `DocumentLoader`
81implementation:
82
83```
84public interface JsonLdDocumentResolver {
85
86 boolean canResolve(URI url);
87
88 JsonStructure resolve(URI url);
89}
90```
91
92> __NOTE__: The EDC should refrain from resolving URLs that are not mapped to the local file system. For example, HTTP URLs, due to security considerations. If end-users want this
93> capability, they can implement and register a `JsonLdDocumentResolver`.
94
95