Compare commits
749 Commits
cloudevent
...
main
Author | SHA1 | Date |
---|---|---|
|
0d96691f6d | |
|
c8a22b5175 | |
|
57f9867a5c | |
|
43f0d5b138 | |
|
efe7e01b75 | |
|
188c3c7085 | |
|
659bb8cc01 | |
|
9981635e7d | |
|
b54df5ca0c | |
|
a3decf768c | |
|
215e67f2c3 | |
|
514e00d75b | |
|
f7ac215bf1 | |
|
5f4abd144a | |
|
8d59d29bb1 | |
|
6ab42de007 | |
|
2e87988d0c | |
|
6d958b69d4 | |
|
1de03ad38a | |
|
4c5d0efb89 | |
|
01a9111d8b | |
|
e056d1b2d8 | |
|
efdf0ba866 | |
|
bd90d903ce | |
|
52a98d778c | |
|
010627e784 | |
|
a7904823c3 | |
|
e5a35ac472 | |
|
4d204cef89 | |
|
43afb6ceaa | |
|
9c6e7fd11e | |
|
98deac1599 | |
|
05baf9be8a | |
|
3add823e00 | |
|
5a03173dde | |
|
9ee16fb48c | |
|
0db4446163 | |
|
111fb55cfd | |
|
55fddb35fc | |
|
7b9d020acc | |
|
fb11b94f2b | |
|
eaef3becdd | |
|
b30324e916 | |
|
1f9fa13231 | |
|
a135755ec6 | |
|
677a2c2628 | |
|
826e099fc0 | |
|
76366338fc | |
|
4ef304115a | |
|
582feed520 | |
|
5ef1088a19 | |
|
698cdf7ad4 | |
|
4ebeab0e0f | |
|
4c81f3eacc | |
|
569e025cf0 | |
|
3614a4f5f4 | |
|
d64aff7327 | |
|
d1cff75230 | |
|
1591cb337a | |
|
f71303b7b7 | |
|
d59b33307a | |
|
e0d1961f35 | |
|
7c6b52ab30 | |
|
433ec5b274 | |
|
40fe91a5e0 | |
|
a43f90f4e2 | |
|
e488269510 | |
|
7d50c7fc7a | |
|
f1a86af656 | |
|
354f7a16ef | |
|
9132a13d81 | |
|
a491c85eb2 | |
|
6362bfbcd6 | |
|
f08a099ed9 | |
|
4139fb7e57 | |
|
adde53c817 | |
|
0dc10251ff | |
|
b9eaa2fcaa | |
|
f8d27b08bf | |
|
9125136530 | |
|
f35e6e610a | |
|
45ec85f8c1 | |
|
1d87fb7191 | |
|
8f9b741306 | |
|
2dd8ba95dd | |
|
1c29726e8c | |
|
6681205733 | |
|
a4bc7a8368 | |
|
4784f03e8c | |
|
ace6859ae0 | |
|
cc786251d5 | |
|
ceb06757a3 | |
|
8d91cdaee6 | |
|
d00ad967c0 | |
|
9231e6d230 | |
|
a94bc5c81c | |
|
32adfe9123 | |
|
0277ee4ae4 | |
|
202849307c | |
|
624ac693d8 | |
|
5a323942d3 | |
|
1587708805 | |
|
06c4ec5385 | |
|
73a3c370d5 | |
|
722f5205b3 | |
|
8ad857d8c7 | |
|
baa9b5927a | |
|
c41a2c3ba7 | |
|
3651cdae18 | |
|
ee4c85b1a1 | |
|
a0b0835180 | |
|
687e03bac5 | |
|
208b18c299 | |
|
9d45943844 | |
|
0a1a03db64 | |
|
7f355d10c1 | |
|
3234e30e55 | |
|
c8f10e9215 | |
|
ba9ccad5d2 | |
|
78355bb225 | |
|
2730ae4a13 | |
|
30fd6769eb | |
|
ff07dd8315 | |
|
928ebcfd6f | |
|
a4613c00d2 | |
|
69f0e20549 | |
|
e2b13109e4 | |
|
5e3bfc890f | |
|
13f8b56618 | |
|
a419d8bba3 | |
|
47bed5616d | |
|
baba37ccfd | |
|
32bcdcd3b9 | |
|
8b382734d9 | |
|
f05418cba9 | |
|
23cd08fcfd | |
|
70782da2c2 | |
|
48fc69e058 | |
|
e7e6e46bd5 | |
|
e523bfbfbf | |
|
12eee4da6e | |
|
d49ff9f69d | |
|
611f2292a7 | |
|
296230719b | |
|
d9592d5201 | |
|
00cdf9cb42 | |
|
bd11010138 | |
|
3a22557b83 | |
|
87c6915d9a | |
|
a7f87cf6cb | |
|
711277eacb | |
|
58570cf4d9 | |
|
24d108fe5d | |
|
f5d9b47c1c | |
|
59643c3368 | |
|
34483025df | |
|
e9d15daf28 | |
|
b89f45265b | |
|
a14f5eabec | |
|
5099b31f6c | |
|
bcc1434a39 | |
|
c1c55ac1d6 | |
|
5ca2c2de91 | |
|
2524cdf324 | |
|
eeb83c3567 | |
|
5a926820b4 | |
|
7c0b1e3c49 | |
|
377850cb61 | |
|
d2a89a4e08 | |
|
de786322aa | |
|
5037a69a80 | |
|
ceb5a2eeb2 | |
|
78a023d08c | |
|
bbce65aa64 | |
|
cc0892a440 | |
|
2d68c4843f | |
|
7f65c92dec | |
|
c9b3fa4b65 | |
|
394347db07 | |
|
6c78428513 | |
|
bf60a25098 | |
|
baf3b56d6d | |
|
8ac23dc479 | |
|
84fbb0c801 | |
|
20ebdbf87f | |
|
2411fe3508 | |
|
554198d9e0 | |
|
c1ff628511 | |
|
62fe155604 | |
|
34408236db | |
|
7696ffe4ec | |
|
b1aa399b63 | |
|
42a732623b | |
|
db745fd309 | |
|
c7baada605 | |
|
3bd9a6922f | |
|
118fc82f2b | |
|
d09b621409 | |
|
b3cdfc1ded | |
|
f52356e93a | |
|
de2052c4d6 | |
|
5e747e7278 | |
|
f9e31efaa3 | |
|
a09b03bd2f | |
|
f219b6937c | |
|
3cea0245b3 | |
|
7abf0c82ed | |
|
bb33df53d3 | |
|
b30c1dc2ec | |
|
e481d6feaf | |
|
36c6a78455 | |
|
8d3e86e672 | |
|
3d86cdd8f4 | |
|
2982f07f55 | |
|
1f58088f3c | |
|
3841e74e1e | |
|
dda867a6ea | |
|
e9c8da021a | |
|
53c0a84f43 | |
|
0a4caad417 | |
|
8a14cf4182 | |
|
6eecf29cf7 | |
|
29c9eaa23f | |
|
c3904fbff4 | |
|
69e605e2ef | |
|
b54a46fd07 | |
|
08aed3bc40 | |
|
f20208aec7 | |
|
c61f87f4d5 | |
|
0ca907be49 | |
|
8b4e586b64 | |
|
75171b9705 | |
|
700661b664 | |
|
6a982d83fa | |
|
b572bd88cf | |
|
39b9fc159c | |
|
4c98031c3b | |
|
0ce5f9535d | |
|
58a6426fe8 | |
|
d4ee5a6930 | |
|
e71cc5358c | |
|
862e4a657a | |
|
f42020333a | |
|
63ffe3be14 | |
|
900decaed0 | |
|
bd50e6f284 | |
|
a012e1e434 | |
|
fd1e6b2728 | |
|
12cca34d21 | |
|
83d9045897 | |
|
98a6b87d5b | |
|
c632f56f8b | |
|
7d85d19f1a | |
|
fd1c3268d9 | |
|
1bebbbbb68 | |
|
14dc3e5b8a | |
|
5c32b566e7 | |
|
28dcc2a009 | |
|
c386423787 | |
|
815c9cff26 | |
|
57bb81cc5c | |
|
1d07d9c392 | |
|
1ebf662b9b | |
|
6d057aa64d | |
|
34cd81455b | |
|
73d90d11bb | |
|
c4f2902dd6 | |
|
0fdfcc378d | |
|
c616a71947 | |
|
fb10bd3da5 | |
|
2ff79c06b6 | |
|
199f8c02e0 | |
|
cd5777791c | |
|
a485edffdb | |
|
9c167a67bb | |
|
30ca27afd8 | |
|
5586404278 | |
|
ba2db45f38 | |
|
5c28b36967 | |
|
d5f87a6df1 | |
|
bf3514459b | |
|
1b03ee1a93 | |
|
7d80d7263b | |
|
2b5e72c50a | |
|
4e38fc805d | |
|
f50f28ef3d | |
|
924dbed6e7 | |
|
cd913f368f | |
|
8d7c785afd | |
|
d207ecc311 | |
|
92c205a941 | |
|
d420efcda7 | |
|
ae4028d59d | |
|
4df01cd279 | |
|
7dcfdba30d | |
|
30c5fcf1e4 | |
|
0f94976f7b | |
|
41f48a5c84 | |
|
814bf80745 | |
|
3eecb4d7a9 | |
|
c7b9f3dab5 | |
|
8f1b8d2da9 | |
|
223d786a3f | |
|
d54dcf7f83 | |
|
ad5ab5d491 | |
|
59d4a79ed6 | |
|
ce98e7cbda | |
|
0113207a45 | |
|
670d1c13f4 | |
|
242b58a530 | |
|
5362a80afe | |
|
5096753658 | |
|
361a34cc63 | |
|
c35b313d15 | |
|
200aa6cd02 | |
|
dd07320779 | |
|
d25aaf8f49 | |
|
a79f8f9431 | |
|
833db5bd92 | |
|
e39291f655 | |
|
ae6dff25aa | |
|
dfa4d2c30e | |
|
2f0e22c560 | |
|
a5f88c3408 | |
|
6861823eb8 | |
|
a6e3bc8d2a | |
|
0b1d2d27d5 | |
|
8e53e66ed0 | |
|
7055740465 | |
|
d183489f04 | |
|
d0178c0bea | |
|
e895a6e596 | |
|
b753661af2 | |
|
3049f587d8 | |
|
e0e562b787 | |
|
0d7c86025c | |
|
c3460ee150 | |
|
01ae643f67 | |
|
0376e12e11 | |
|
6994c2244b | |
|
dfd71734d0 | |
|
cbab54ed88 | |
|
7a1326f182 | |
|
962d10cb48 | |
|
457962402a | |
|
b451c1d7d6 | |
|
d732c0d153 | |
|
2dfed7e782 | |
|
c205299065 | |
|
c047c754f0 | |
|
6328b86c96 | |
|
88c078af57 | |
|
25e90caf43 | |
|
39427f3162 | |
|
ffdcca6dd1 | |
|
b5bb261e22 | |
|
50f8015d18 | |
|
1291497f1d | |
|
de45795d29 | |
|
f641cb1957 | |
|
d8fc237466 | |
|
179cc1972c | |
|
6bf0af1555 | |
|
c5abaef45b | |
|
37b4854775 | |
|
79dd762367 | |
|
59962ba689 | |
|
9e97e10ac6 | |
|
c02fcecb5b | |
|
a635f429f8 | |
|
84441cd0f9 | |
|
9eea7587a1 | |
|
f35dc6bbf8 | |
|
313040f7f6 | |
|
43f779e010 | |
|
893ee567f0 | |
|
73f6c9572c | |
|
835058f32b | |
|
d9434f5408 | |
|
ba0ccb1e1e | |
|
73bbda9c17 | |
|
b1a473894d | |
|
372af07c64 | |
|
92c4f78829 | |
|
9f14242ed8 | |
|
769254bb75 | |
|
984b05b75e | |
|
821273139a | |
|
698a3d1131 | |
|
3df3b29e09 | |
|
50508ba4b3 | |
|
1cff239ab4 | |
|
cf65ce0309 | |
|
b0a6101b23 | |
|
bf72800220 | |
|
fe94d00437 | |
|
1ad66b0da4 | |
|
680f8cdf13 | |
|
2cacd5fc80 | |
|
56331feb2e | |
|
3c600a3538 | |
|
685d2a0dbf | |
|
ac45ce9045 | |
|
ccc55e9e4c | |
|
291df4b1e0 | |
|
76946e63f3 | |
|
4db13f58e6 | |
|
d66adea035 | |
|
53cde4cae6 | |
|
436dae661e | |
|
9b2e420e4a | |
|
082bb529b7 | |
|
b0814a97be | |
|
67b1303d2a | |
|
a95cb50483 | |
|
aa79390ee9 | |
|
b9d55cfdfc | |
|
f5b6eab1ee | |
|
fabebe5ef3 | |
|
78896687b3 | |
|
47ab16a7eb | |
|
0a6a65b53a | |
|
2d7944cf23 | |
|
fb267a050d | |
|
855949ce5f | |
|
6962a97997 | |
|
bab23ab8be | |
|
ec0bbb6aad | |
|
cb2b930fef | |
|
f7175593e7 | |
|
50bbd8f62a | |
|
4d54386c7c | |
|
b4553fcae6 | |
|
fb3c59c6a9 | |
|
82581ddf18 | |
|
25bdc70645 | |
|
dde76aabec | |
|
2da5a54263 | |
|
49a6dda3cb | |
|
c086de98cb | |
|
c2bbfa7a27 | |
|
b469da4388 | |
|
33ac91972a | |
|
d7af439944 | |
|
639e5b4480 | |
|
e625f3a33a | |
|
cc4325d52e | |
|
fda0e73429 | |
|
064785f549 | |
|
154a93e3c4 | |
|
b14b6b0652 | |
|
0857dfa4ca | |
|
b7aa38eacb | |
|
efc32d5c09 | |
|
b0483f3a8c | |
|
cac367cf8e | |
|
5e86c215bc | |
|
272c6ad568 | |
|
f57cc6ad65 | |
|
838a730258 | |
|
528563b563 | |
|
af39059327 | |
|
c11ca15fc4 | |
|
9b41ae001d | |
|
8327a97b04 | |
|
cb3364e714 | |
|
61e63ed367 | |
|
879c6e81b1 | |
|
e626dc45ce | |
|
f6a85d0b40 | |
|
6a248907f9 | |
|
4b47abe4e4 | |
|
cac81e32ad | |
|
1f6a6009d9 | |
|
29466509f4 | |
|
7aedf64ea8 | |
|
33393ce26c | |
|
d4c1cb2825 | |
|
4e4ded70dc | |
|
089f976540 | |
|
f3cd10ac93 | |
|
b2436c94ee | |
|
de58785f62 | |
|
0ac54691d7 | |
|
b4b7b2a37b | |
|
90d08f0678 | |
|
3ec841c33c | |
|
f23bb3e8a3 | |
|
58449faa87 | |
|
a62510671f | |
|
0b58bc9bc7 | |
|
8fb128e992 | |
|
f0ed9b9786 | |
|
cdb638157d | |
|
533e95b755 | |
|
e6f4b691d5 | |
|
ad2074d48d | |
|
5df373310e | |
|
efd60454ee | |
|
0b11866d83 | |
|
816c03ab67 | |
|
d8b24f8953 | |
|
14e873d3f2 | |
|
d46300b57b | |
|
6e63ce20e2 | |
|
62a9c133c4 | |
|
7b97f3714c | |
|
ff1ee9d694 | |
|
33d75f43d4 | |
|
4eb6cfaa95 | |
|
3f87394cbb | |
|
322e9cee4a | |
|
cf39dd5a39 | |
|
c2a982dc0c | |
|
1a7ecafeeb | |
|
87bea3cca2 | |
|
ac8561003c | |
|
a971933128 | |
|
5ce4c08563 | |
|
8cfc47b41d | |
|
ca377dbb61 | |
|
5b53529dcd | |
|
43945a9356 | |
|
1f58ddfc88 | |
|
16f81f522a | |
|
e2b05808ca | |
|
aabd8c7847 | |
|
667f22a060 | |
|
9ad2486176 | |
|
9568fc339f | |
|
da2c2e7f51 | |
|
e21fd99ff1 | |
|
2d0538f4f9 | |
|
dc97d6f565 | |
|
d3492c5edd | |
|
18e2b19b71 | |
|
f9ebd5a7e0 | |
|
16b7c48754 | |
|
1bdab88d95 | |
|
e03db54f33 | |
|
f6d0d1fba1 | |
|
d84211dea4 | |
|
80b8a1ddc5 | |
|
9b515cbff2 | |
|
2d878fc146 | |
|
50f5e5d81e | |
|
47c445f710 | |
|
061619b39a | |
|
58d54b4ecc | |
|
97bac365bb | |
|
f038be561e | |
|
a4bedf04af | |
|
2a1075af0e | |
|
9939e69d76 | |
|
d2497338f3 | |
|
4482e2200b | |
|
4bea5a311f | |
|
e4237f3a26 | |
|
08a3c4ea66 | |
|
3f3c547310 | |
|
156f8561b8 | |
|
eede6b2625 | |
|
a525b08ddf | |
|
a06f5c5109 | |
|
480c7b5443 | |
|
2a5108ebce | |
|
8c03752e86 | |
|
fbaac5a73b | |
|
9063b5d923 | |
|
18a4578b0c | |
|
98b3d8980b | |
|
6237e569d0 | |
|
de1e54272c | |
|
d6611de540 | |
|
7467513636 | |
|
9a561d3e52 | |
|
60bbac06de | |
|
b5e72d7beb | |
|
469ba5a81e | |
|
aa3d5b75af | |
|
049fc8c7d7 | |
|
4e6695525b | |
|
9fd1a26e94 | |
|
bcc9fd4784 | |
|
842ce70fa4 | |
|
fe6bbc89df | |
|
4afc34399b | |
|
0f89086d0d | |
|
24e071a62c | |
|
ae719c9984 | |
|
ec11c44a47 | |
|
1e4f84f41f | |
|
880b85b786 | |
|
6c54ff32e7 | |
|
e815d7c75b | |
|
7df1d1536d | |
|
5d29d4f00d | |
|
01b715d4fc | |
|
785c4cb9b9 | |
|
7ad4d4e308 | |
|
a9635b5d93 | |
|
b65f91120a | |
|
8608be402a | |
|
799fd57881 | |
|
30953e7657 | |
|
52dad12ed6 | |
|
a1539f4c08 | |
|
d782c0b4ec | |
|
a11b443a76 | |
|
bb4fcaa52a | |
|
be956f60a9 | |
|
b416aa9c35 | |
|
15909cd087 | |
|
ecd250a698 | |
|
3026d9a35b | |
|
57076ab49d | |
|
46b9dd2653 | |
|
a7d2249ab5 | |
|
41729e800c | |
|
ec2564dd0c | |
|
6d18806ff4 | |
|
e89b3c1f13 | |
|
51450a363d | |
|
aa70190226 | |
|
5bee36db53 | |
|
f939c21fd7 | |
|
9c549706f8 | |
|
5359a1ece0 | |
|
0257406506 | |
|
2462b4637f | |
|
f2ace570aa | |
|
b06e6106a6 | |
|
efca35b6f0 | |
|
201b5ab21b | |
|
e9fd715325 | |
|
a0047bef6e | |
|
9c11207c84 | |
|
a892517682 | |
|
a9ecd31562 | |
|
982a359731 | |
|
38c8f3d1b2 | |
|
dbd5c366a1 | |
|
3a48e913d0 | |
|
dccb1cd57c | |
|
0606036c31 | |
|
d040bcef32 | |
|
3cecb769f1 | |
|
92f2a3f8b8 | |
|
8968802bf8 | |
|
a32976e44b | |
|
92f463c661 | |
|
4f1bf875f3 | |
|
740d67d42a | |
|
c9f3998c15 | |
|
607c2cf43d | |
|
1f45b0f230 | |
|
d93866f856 | |
|
7078603fc8 | |
|
c941799977 | |
|
0d2e1d7579 | |
|
a3bab6f860 | |
|
809a6e4bbc | |
|
b3753002af | |
|
69481e3075 | |
|
7f70261981 | |
|
c8ac595435 | |
|
d41b528221 | |
|
236f1597a2 | |
|
1721fd387e | |
|
5c171dbf39 | |
|
20cef92ee1 | |
|
01ae400193 | |
|
fda22ed938 | |
|
5e230ddeff | |
|
3bf55af44d | |
|
77bbca5943 | |
|
7de013719e | |
|
5fc30f5f06 | |
|
c3a94c90d1 | |
|
66adbdada5 | |
|
63d693d694 | |
|
91b89d51fe | |
|
30e7fb681c | |
|
abbdf66686 | |
|
806a2dacc9 | |
|
98df3e997e | |
|
a12d29eaf6 | |
|
5ac588c8d9 | |
|
3a2ee97847 | |
|
87d63b2ccd | |
|
b2934fad99 | |
|
861b3410ce | |
|
171b9652b3 | |
|
87fdd9f9de | |
|
279d0d6806 | |
|
7c85f338ac | |
|
385153a552 | |
|
afc6f3deef | |
|
024e7b18fe | |
|
a636b9b518 | |
|
2323b4cf2d | |
|
9a75b23566 | |
|
7aac31892c | |
|
ef3753f8d9 | |
|
12860fafaf | |
|
2d4828f02b | |
|
fe7e40973d | |
|
10a7931393 | |
|
5dde66e8d8 | |
|
137dcaa016 | |
|
059a3e7206 | |
|
06fb04e42f | |
|
4d5ed04fd9 | |
|
8c635e3c53 | |
|
ff074c2758 | |
|
b26ecda111 | |
|
49f318c251 | |
|
937a3abe5a | |
|
2acad53ba8 | |
|
676a32a60d | |
|
c9f4292604 | |
|
7f11e22a76 | |
|
2e464adeb7 | |
|
2a6e56e5f4 | |
|
4655bc89d9 | |
|
a00ddcad35 | |
|
5326476d55 | |
|
935c17bb16 | |
|
8350a78ce5 | |
|
9f2d568598 | |
|
af57ffb57d | |
|
cee02dead8 | |
|
47ca69c435 | |
|
f11c773f8a | |
|
6b32537972 | |
|
0b2585048c | |
|
19ac10b176 | |
|
9035156ec2 | |
|
c85c691ea6 | |
|
27fe1a686e | |
|
c8a27e50dc | |
|
ea0f128a77 | |
|
e8f6419e8c | |
|
5a422422e1 | |
|
419769e7a0 | |
|
05d8658b08 | |
|
958d539c83 | |
|
ee8632a537 | |
|
192bfcaaa0 |
|
@ -0,0 +1,14 @@
|
|||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
trim_trailing_whitespace = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[{*.yaml, *.yml}]
|
||||
indent_size = 2
|
||||
|
||||
[*.java]
|
||||
max_line_length = 160
|
|
@ -0,0 +1,11 @@
|
|||
# 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"
|
||||
directory: "/" # Location of package manifests
|
||||
schedule:
|
||||
interval: "daily"
|
|
@ -0,0 +1,48 @@
|
|||
name: Test and Deploy
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- '[0-9]+.[0-9]+'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Java ${{ matrix.java }} Test
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java: [ 8, 11, 17 ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
- run: |
|
||||
./mvnw clean install -DskipTests -B
|
||||
./mvnw verify -B
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
name: Deploy
|
||||
needs: test
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 8
|
||||
server-id: central # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
server-username: MAVEN_USERNAME # env variable for username in deploy
|
||||
server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy
|
||||
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
|
||||
gpg-passphrase: MAVEN_GPG_PASSPHRASE # env variable for GPG private key passphrase
|
||||
- name: Publish to Apache Maven Central
|
||||
run: ./mvnw clean deploy -Drelease -DskipTests -B
|
||||
env:
|
||||
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
|
||||
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
|
||||
MAVEN_GPG_PASSPHRASE: ${{ secrets.MAVEN_GPG_PASSPHRASE }}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
name: Bump version
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
description: 'Version to bump (without prepending "v")'
|
||||
required: true
|
||||
maven-modules:
|
||||
description: "Whether to bump versions in pom.xml files"
|
||||
type: choice
|
||||
required: true
|
||||
default: 'true'
|
||||
options:
|
||||
- 'true'
|
||||
- 'false'
|
||||
|
||||
jobs:
|
||||
bump:
|
||||
name: Bump Java version
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
NEW_VERSION: ${{ github.event.inputs.version }}
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 8
|
||||
- name: Bump version using Maven
|
||||
if: ${{ inputs.maven-modules == 'true' }}
|
||||
run: './mvnw versions:set -DnewVersion=$NEW_VERSION -DgenerateBackupPoms=false -B'
|
||||
- name: Bump version in docs
|
||||
if: ${{ !endsWith(github.event.inputs.version, 'SNAPSHOT') }}
|
||||
run: 'find . -type f -name "*.md" -exec sed -i -e "s+<version>[a-zA-Z0-9.-]*<\/version>+<version>$NEW_VERSION</version>+g" {} +'
|
||||
- name: Create version bump PR
|
||||
uses: peter-evans/create-pull-request@v3
|
||||
with:
|
||||
title: "[Release] Bump to ${{ github.event.inputs.version }}"
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
commit-message: "Bump to ${{ github.event.inputs.version }}"
|
||||
signoff: true
|
||||
branch: "bump/${{ github.event.inputs.version }}"
|
||||
body: >
|
||||
This PR performs the bump of the SDK to ${{ github.event.inputs.version }}.
|
||||
This PR is auto-generated by
|
||||
[create-pull-request](https://github.com/peter-evans/create-pull-request).
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
name: Test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- main
|
||||
- '[0-9]+.[0-9]+'
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
java: [ 8, 11, 17 ]
|
||||
name: Java ${{ matrix.java }} Test
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Setup java
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: 'temurin'
|
||||
- run: |
|
||||
./mvnw clean install -DskipTests -B
|
||||
./mvnw verify -B
|
||||
./mvnw javadoc:javadoc
|
|
@ -13,6 +13,8 @@ release.properties
|
|||
.classpath
|
||||
.project
|
||||
.settings/
|
||||
.vscode/
|
||||
.attach_pid*
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
@ -34,3 +36,14 @@ release.properties
|
|||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
# Jekyll stuff
|
||||
_site/
|
||||
.sass-cache/
|
||||
.jekyll-cache/
|
||||
.jekyll-metadata
|
||||
|
||||
# MacOS
|
||||
*.DS_Store
|
||||
/http/restful-ws-jakarta/src/main/*
|
||||
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright 2007-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.Properties;
|
||||
|
||||
public class MavenWrapperDownloader {
|
||||
|
||||
private static final String WRAPPER_VERSION = "0.5.6";
|
||||
/**
|
||||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
|
||||
*/
|
||||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
|
||||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
|
||||
|
||||
/**
|
||||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
|
||||
* use instead of the default one.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
|
||||
".mvn/wrapper/maven-wrapper.properties";
|
||||
|
||||
/**
|
||||
* Path where the maven-wrapper.jar will be saved to.
|
||||
*/
|
||||
private static final String MAVEN_WRAPPER_JAR_PATH =
|
||||
".mvn/wrapper/maven-wrapper.jar";
|
||||
|
||||
/**
|
||||
* Name of the property which should be used to override the default download url for the wrapper.
|
||||
*/
|
||||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("- Downloader started");
|
||||
File baseDirectory = new File(args[0]);
|
||||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
|
||||
|
||||
// If the maven-wrapper.properties exists, read it and check if it contains a custom
|
||||
// wrapperUrl parameter.
|
||||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
|
||||
String url = DEFAULT_DOWNLOAD_URL;
|
||||
if(mavenWrapperPropertyFile.exists()) {
|
||||
FileInputStream mavenWrapperPropertyFileInputStream = null;
|
||||
try {
|
||||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
|
||||
Properties mavenWrapperProperties = new Properties();
|
||||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
|
||||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
|
||||
} catch (IOException e) {
|
||||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
|
||||
} finally {
|
||||
try {
|
||||
if(mavenWrapperPropertyFileInputStream != null) {
|
||||
mavenWrapperPropertyFileInputStream.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Ignore ...
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading from: " + url);
|
||||
|
||||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
|
||||
if(!outputFile.getParentFile().exists()) {
|
||||
if(!outputFile.getParentFile().mkdirs()) {
|
||||
System.out.println(
|
||||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
|
||||
}
|
||||
}
|
||||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
|
||||
try {
|
||||
downloadFileFromURL(url, outputFile);
|
||||
System.out.println("Done");
|
||||
System.exit(0);
|
||||
} catch (Throwable e) {
|
||||
System.out.println("- Error downloading");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
|
||||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
|
||||
String username = System.getenv("MVNW_USERNAME");
|
||||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
|
||||
Authenticator.setDefault(new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
});
|
||||
}
|
||||
URL website = new URL(urlString);
|
||||
ReadableByteChannel rbc;
|
||||
rbc = Channels.newChannel(website.openStream());
|
||||
FileOutputStream fos = new FileOutputStream(destination);
|
||||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||
fos.close();
|
||||
rbc.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
|
15
.travis.yml
15
.travis.yml
|
@ -1,15 +0,0 @@
|
|||
language: java
|
||||
|
||||
sudo: false
|
||||
|
||||
jdk:
|
||||
- oraclejdk8
|
||||
- openjdk8
|
||||
- openjdk9
|
||||
- openjdk10
|
||||
- openjdk11
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
|
@ -0,0 +1,167 @@
|
|||
# Contributing to CloudEvents' Java SDK
|
||||
|
||||
:+1::tada: First off, thanks for taking the time to contribute! :tada::+1:
|
||||
|
||||
We welcome contributions from the community! Please take some time to become
|
||||
acquainted with the process before submitting a pull request. There are just
|
||||
a few things to keep in mind.
|
||||
|
||||
# Pull Requests
|
||||
|
||||
Typically, a pull request should relate to an existing issue. If you have
|
||||
found a bug, want to add an improvement, or suggest an API change, please
|
||||
create an issue before proceeding with a pull request. For very minor changes
|
||||
such as typos in the documentation this isn't really necessary.
|
||||
|
||||
## Pull Request Guidelines
|
||||
|
||||
Here you will find step by step guidance for creating, submitting and updating
|
||||
a pull request in this repository. We hope it will help you have an easy time
|
||||
managing your work and a positive, satisfying experience when contributing
|
||||
your code. Thanks for getting involved! :rocket:
|
||||
|
||||
* [Getting Started](#getting-started)
|
||||
* [Branches](#branches)
|
||||
* [Commit Messages](#commit-messages)
|
||||
* [Staying current with main](#staying-current-with-main)
|
||||
* [Submitting and Updating a Pull Request](#submitting-and-updating-a-pull-request)
|
||||
* [Congratulations!](#congratulations)
|
||||
|
||||
## Getting Started
|
||||
|
||||
When creating a pull request, first fork this repository and clone it to your
|
||||
local development environment. Then add this repository as the upstream.
|
||||
|
||||
```console
|
||||
git clone https://github.com/mygithuborg/sdk-java.git
|
||||
cd sdk-java
|
||||
git remote add upstream https://github.com/cloudevents/sdk-java.git
|
||||
```
|
||||
|
||||
## Branches
|
||||
|
||||
The first thing you'll need to do is create a branch for your work.
|
||||
If you are submitting a pull request that fixes or relates to an existing
|
||||
GitHub issue, you can use the issue number in your branch name to keep things
|
||||
organized.
|
||||
|
||||
```console
|
||||
git fetch upstream
|
||||
git reset --hard upstream/main
|
||||
git checkout FETCH_HEAD
|
||||
git checkout -b 48-fix-http-agent-error
|
||||
```
|
||||
|
||||
## Commit Messages
|
||||
|
||||
Please follow the
|
||||
[Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/#summary).
|
||||
The first line of your commit should be prefixed with a type, be a single
|
||||
sentence with no period, and succinctly indicate what this commit changes.
|
||||
|
||||
All commit message lines should be kept to fewer than 80 characters if possible.
|
||||
|
||||
An example of a good commit message.
|
||||
|
||||
```log
|
||||
docs: remove 0.1, 0.2 spec support from README
|
||||
```
|
||||
|
||||
### Signing your commits
|
||||
|
||||
Each commit must be signed. Use the `--signoff` flag for your commits.
|
||||
|
||||
```console
|
||||
git commit --signoff
|
||||
```
|
||||
|
||||
This will add a line to every git commit message:
|
||||
|
||||
Signed-off-by: Joe Smith <joe.smith@email.com>
|
||||
|
||||
Use your real name (sorry, no pseudonyms or anonymous contributions.)
|
||||
|
||||
The sign-off is a signature line at the end of your commit message. Your
|
||||
signature certifies that you wrote the patch or otherwise have the right to pass
|
||||
it on as open-source code. See [developercertificate.org](http://developercertificate.org/)
|
||||
for the full text of the certification.
|
||||
|
||||
Be sure to have your `user.name` and `user.email` set in your git config.
|
||||
If your git config information is set properly then viewing the `git log`
|
||||
information for your commit will look something like this:
|
||||
|
||||
```
|
||||
Author: Joe Smith <joe.smith@email.com>
|
||||
Date: Thu Feb 2 11:41:15 2018 -0800
|
||||
|
||||
Update README
|
||||
|
||||
Signed-off-by: Joe Smith <joe.smith@email.com>
|
||||
```
|
||||
|
||||
Notice the `Author` and `Signed-off-by` lines match. If they don't your PR will
|
||||
be rejected by the automated DCO check.
|
||||
|
||||
## Staying Current with `main`
|
||||
|
||||
As you are working on your branch, changes may happen on `main`. Before
|
||||
submitting your pull request, be sure that your branch has been updated
|
||||
with the latest commits.
|
||||
|
||||
```console
|
||||
git fetch upstream
|
||||
git rebase upstream/main
|
||||
```
|
||||
|
||||
This may cause conflicts if the files you are changing on your branch are
|
||||
also changed on main. Error messages from `git` will indicate if conflicts
|
||||
exist and what files need attention. Resolve the conflicts in each file, then
|
||||
continue with the rebase with `git rebase --continue`.
|
||||
|
||||
|
||||
If you've already pushed some changes to your `origin` fork, you'll
|
||||
need to force push these changes.
|
||||
|
||||
```console
|
||||
git push -f origin 48-fix-http-agent-error
|
||||
```
|
||||
|
||||
## Submitting and Updating Your Pull Request
|
||||
|
||||
Before submitting a pull request, you should make sure that all of the tests
|
||||
successfully pass.
|
||||
|
||||
Once you have sent your pull request, `main` may continue to evolve
|
||||
before your pull request has landed. If there are any commits on `main`
|
||||
that conflict with your changes, you may need to update your branch with
|
||||
these changes before the pull request can land. Resolve conflicts the same
|
||||
way as before.
|
||||
|
||||
```console
|
||||
git fetch upstream
|
||||
git rebase upstream/main
|
||||
# fix any potential conflicts
|
||||
git push -f origin 48-fix-http-agent-error
|
||||
```
|
||||
|
||||
This will cause the pull request to be updated with your changes, and
|
||||
CI will rerun.
|
||||
|
||||
A maintainer may ask you to make changes to your pull request. Sometimes these
|
||||
changes are minor and shouldn't appear in the commit log. For example, you may
|
||||
have a typo in one of your code comments that should be fixed before merge.
|
||||
You can prevent this from adding noise to the commit log with an interactive
|
||||
rebase. See the [git documentation](https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History)
|
||||
for details.
|
||||
|
||||
```console
|
||||
git commit -m "fixup: fix typo"
|
||||
git rebase -i upstream/main # follow git instructions
|
||||
```
|
||||
|
||||
Once you have rebased your commits, you can force push to your fork as before.
|
||||
|
||||
## Congratulations!
|
||||
|
||||
Congratulations! You've done it! We really appreciate the time and energy
|
||||
you've given to the project. Thank you.
|
2
LICENSE
2
LICENSE
|
@ -186,7 +186,7 @@
|
|||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright 2018-Present The CloudEvents Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
# Maintainers
|
||||
|
||||
Current active maintainers of this SDK:
|
||||
|
||||
- [Pierangelo Di Pilato](https://github.com/pierDipi)
|
|
@ -0,0 +1,39 @@
|
|||
# Maintainer's Guide
|
||||
|
||||
## Tips
|
||||
|
||||
Here are a few tips for repository maintainers.
|
||||
|
||||
* Stay on top of your pull requests. PRs that languish for too long can become difficult to merge.
|
||||
* Work from your own fork. As you are making contributions to the project, you should be working from your own fork just as outside contributors do. This keeps the branches in github to a minimum and reduces unnecessary CI runs.
|
||||
* Try to proactively label issues and pull requests with labels
|
||||
* Actively review pull requests as they are submitted
|
||||
* Triage issues once in a while in order to keep the repository alive.
|
||||
* If some issues are stale for too long because they are no longer valid/relevant or because the discussion reached no significant action items to perform, close them and invite the users to reopen if they need it.
|
||||
* If some PRs are no longer valid due to conflicts, but the PR is still needed, ask the contributor to rebase their PR.
|
||||
* If some issues and PRs are still relevant, use labels to help organize tasks.
|
||||
* If you find an issue that you want to create a pull request for, be sure to assign it to yourself so that other maintainers don't start working on it at the same time.
|
||||
|
||||
## Landing Pull Requests
|
||||
|
||||
When landing pull requests, be sure to check the first line uses an appropriate commit message prefix (e.g. docs, feat, lib, etc). If there is more than one commit, try to squash into a single commit. Usually this can just be done with the GitHub UI when merging the PR. Use "Squash and merge". To help ensure that everyone in the community has an opportunity to review and comment on pull requests, it's often good to have some time after a pull request has been submitted, and before it has landed. Some guidelines here about approvals and timing.
|
||||
|
||||
* No pull request may land without passing all automated checks
|
||||
* All pull requests require at least one approval from a maintainer before landing
|
||||
* A pull request author may approve their own PR, but will need an additional approval to land it
|
||||
* If a maintainer has submitted a pull request and it has not received approval from at least one other maintainer, it can be landed after 72 hours
|
||||
* If a pull request has both approvals and requested changes, it can't be landed until those requested changes are resolved
|
||||
|
||||
## Branch Management
|
||||
|
||||
The `main` branch is the bleeding edge. New major versions of the module
|
||||
are cut from this branch and tagged. If you intend to submit a pull request
|
||||
you should use `main HEAD` as your starting point.
|
||||
|
||||
Each major release will result in a new branch and tag. For example, the
|
||||
release of version 1.0.0 of the module will result in a `v1.0.0` tag on the
|
||||
release commit, and a new branch `v1.x.y` for subsequent minor and patch
|
||||
level releases of that major version. However, development will continue
|
||||
apace on `main` for the next major version - e.g. 2.0.0. Version branches
|
||||
are only created for each major version. Minor and patch level releases
|
||||
are simply tagged.
|
134
README.md
134
README.md
|
@ -1,39 +1,123 @@
|
|||
# Java SDK for CloudEvents API
|
||||
|
||||
[](https://travis-ci.org/cloudevents/sdk-java)
|
||||
[](http://www.apache.org/licenses/LICENSE-2.0)
|
||||
[](https://maven-badges.herokuapp.com/maven-central/io.cloudevents/cloudevents-parent)
|
||||
[](http://www.javadoc.io/doc/io.cloudevents/cloudevents-api)
|
||||
[](http://www.javadoc.io/doc/io.cloudevents/cloudevents-core)
|
||||
|
||||
A Java API for the [CloudEvents specification](https://github.com/cloudevents/spec)
|
||||
The Java SDK for CloudEvents is a collection of Java packages to adopt
|
||||
[CloudEvents](https://github.com/cloudevents/spec) in your Java application.
|
||||
|
||||
## Motivation
|
||||
Using the Java SDK you can:
|
||||
|
||||
The [CloudEvents specification](https://github.com/cloudevents/spec) is vendor-neutral specification for defining the format of event data that is being exchanged between different cloud systems. The specification basically defines an abstract envelope for any event data payload, without knowing specific implementation details of the actual underlying event. The current version of the spec is at `0.2` and it describes a simple event format, which was demonstrated at last [KubeCon 2018](https://youtu.be/TZPPjAv12KU) using different _Serverless platforms_, such as [Apache Openwhisk](https://github.com/apache/incubator-openwhisk).
|
||||
- Access, create and manipulate `CloudEvent` inside your application.
|
||||
- Serialize and deserialize `CloudEvent` back and forth using the _CloudEvents
|
||||
Event Format_, like Json.
|
||||
- Read and write `CloudEvent` back and forth to HTTP, Kafka, AMQP using the
|
||||
_CloudEvents Protocol Binding_ implementations we provide for a wide range
|
||||
of well known Java frameworks/libraries.
|
||||
|
||||
## Java API
|
||||
To check out the complete documentation and how to get started, look at the dedicated website
|
||||
https://cloudevents.github.io/sdk-java/.
|
||||
|
||||
Based on the specification we started to look at an early implementation of the API for Java. Using the API your backend application can create strongly-typed CloudEvents, such as:
|
||||
## Status
|
||||
|
||||
```java
|
||||
// given
|
||||
final String eventId = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("/trigger");
|
||||
final String eventType = "My.Cloud.Event.Type";
|
||||
final MyCustomEvent payload = ...
|
||||
This SDK is considered **work in progress**. The community is working hard to
|
||||
bring you a new major version of the SDK with major enhancements both to APIs
|
||||
and to implementation.
|
||||
|
||||
// passing in the given attributes
|
||||
final CloudEvent<MyCustomEvent> cloudEvent = new CloudEventBuilder<MyCustomEvent>()
|
||||
.type(eventType)
|
||||
.id(eventId)
|
||||
.source(src)
|
||||
.data(payload)
|
||||
.build();
|
||||
```
|
||||
If you want to know more about v1 of this SDK, check out the
|
||||
[v1 readme](https://github.com/cloudevents/sdk-java/tree/1.x)
|
||||
|
||||
## Possible Integrations
|
||||
Stay tuned!
|
||||
|
||||
The idea on the API is to keep the pure API simple, for allowing a wide range of possible integrations
|
||||
Supported features of the specification:
|
||||
|
||||
* [CDI](cdi/)
|
||||
* [Eclipse Vert.x](http/vertx/)
|
||||
| | [v0.3](https://github.com/cloudevents/spec/tree/v0.3) | [v1.0](https://github.com/cloudevents/spec/tree/v1.0) |
|
||||
| :-------------------------------------: | :---------------------------------------------------: | :---------------------------------------------------: |
|
||||
| CloudEvents Core | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| AMQP Protocol Binding | :x: | :x: |
|
||||
| - [Proton](amqp) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| AVRO Event Format | :x: | :x: |
|
||||
| HTTP Protocol Binding | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [Vert.x](http/vertx) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [Jakarta Restful WS](http/restful-ws) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [Basic](http/basic) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [Spring](spring) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [http4k][http4k]<sup>†</sup>| :heavy_check_mark: | :heavy_check_mark: |
|
||||
| JSON Event Format | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [Jackson](formats/json-jackson) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| Protobuf Event Format | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| - [Proto](formats/protobuf) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| [Kafka Protocol Binding](kafka) | :heavy_check_mark: | :heavy_check_mark: |
|
||||
| MQTT Protocol Binding | :x: | :x: |
|
||||
| NATS Protocol Binding | :x: | :x: |
|
||||
| Web hook | :x: | :x: |
|
||||
|
||||
<sub>† Source/artifacts hosted externally</sub>
|
||||
|
||||
## Documentation
|
||||
|
||||
Documentation is available at https://cloudevents.github.io/sdk-java/.
|
||||
|
||||
Javadocs are available on [javadoc.io](https://www.javadoc.io):
|
||||
|
||||
- [cloudevents-api](https://www.javadoc.io/doc/io.cloudevents/cloudevents-api)
|
||||
- [cloudevents-core](https://www.javadoc.io/doc/io.cloudevents/cloudevents-core)
|
||||
- [cloudevents-avro-compact](https://www.javadoc.io/doc/io.cloudevents/cloudevents-avro-compact)
|
||||
- [cloudevents-json-jackson](https://www.javadoc.io/doc/io.cloudevents/cloudevents-json-jackson)
|
||||
- [cloudevents-protobuf](https://www.javadoc.io/doc/io.cloudevents/cloudevents-protobuf)
|
||||
- [cloudevents-xml](https://www.javadoc.io/doc/io.cloudevents/cloudevents-xml)
|
||||
- [cloudevents-http-basic](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-basic)
|
||||
- [cloudevents-http-restful-ws](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-restful-ws)
|
||||
- [cloudevents-http-vertx](https://www.javadoc.io/doc/io.cloudevents/cloudevents-http-vertx)
|
||||
- [cloudevents-kafka](https://www.javadoc.io/doc/io.cloudevents/cloudevents-kafka)
|
||||
- [cloudevents-amqp](https://www.javadoc.io/doc/io.cloudevents/cloudevents-amqp)
|
||||
- [cloudevents-spring](https://www.javadoc.io/doc/io.cloudevents/cloudevents-spring)
|
||||
|
||||
You can check out the examples in the [examples](examples) directory.
|
||||
|
||||
## Used By
|
||||
|
||||
| [Occurrent](https://occurrent.org) | [Knative Eventing](https://github.com/knative-sandbox/eventing-kafka-broker )| [http4k][http4k] |
|
||||
| ---------------------------------- | ---------------------------------------------------------------------------- | ---------------|
|
||||
| <a href="https://occurrent.org"><img src="https://raw.githubusercontent.com/johanhaleby/occurrent/master/occurrent-logo-196x196.png" width="98" height="98" alt="Occurrent" title="Occurrent - Event Sourcing Utilities for the JVM"></img></a> | <a href="https://github.com/knative-sandbox/eventing-kafka-broker"><img src="https://cloudevents.io/img/logos/integrations/knative.png" height="98"></img></a> | <a href="https://www.http4k.org/guide/modules/cloud_events/"><img src="https://http4k.org/img/favicon-310.png" height="98" alt="http4k" title="http4k"></img></a> | |
|
||||
|
||||
## Community
|
||||
|
||||
- There are bi-weekly calls immediately following the
|
||||
[Serverless/CloudEvents call](https://github.com/cloudevents/spec#meeting-time)
|
||||
at 9am PT (US Pacific). Which means they will typically start at 10am PT,
|
||||
but if the other call ends early then the SDK call will start early as well.
|
||||
See the
|
||||
[CloudEvents meeting minutes](https://docs.google.com/document/d/1OVF68rpuPK5shIHILK9JOqlZBbfe91RNzQ7u_P7YCDE/edit#)
|
||||
to determine which week will have the call.
|
||||
- Slack: #cloudeventssdk channel under
|
||||
[CNCF's Slack workspace](https://slack.cncf.io/).
|
||||
- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk
|
||||
- Contact for additional information: Francesco Guardiani (`@slinkydeveloper`
|
||||
on slack), Fabio José (`@fabiojose` on slack).
|
||||
|
||||
Each SDK may have its own unique processes, tooling and guidelines, common
|
||||
governance related material can be found in the
|
||||
[CloudEvents `community`](https://github.com/cloudevents/spec/tree/main/docs)
|
||||
directory. In particular, in there you will find information concerning how SDK
|
||||
projects are
|
||||
[managed](https://github.com/cloudevents/spec/blob/main/docs/SDK-GOVERNANCE.md),
|
||||
[guidelines](https://github.com/cloudevents/spec/blob/main/docs/SDK-maintainer-guidelines.md)
|
||||
for how PR reviews and approval, and our
|
||||
[Code of Conduct](https://github.com/cloudevents/spec/blob/main/docs/GOVERNANCE.md#additional-information)
|
||||
information.
|
||||
|
||||
If there is a security concern with one of the CloudEvents specifications, or
|
||||
with one of the project's SDKs, please send an email to
|
||||
[cncf-cloudevents-security@lists.cncf.io](mailto:cncf-cloudevents-security@lists.cncf.io).
|
||||
|
||||
## Additional SDK Resources
|
||||
|
||||
- [List of current active maintainers](MAINTAINERS.md)
|
||||
- [How to contribute to the project](CONTRIBUTING.md)
|
||||
- [SDK's License](LICENSE)
|
||||
- [SDK's Release process](RELEASING.md)
|
||||
- [SDK Maintainer's guide](MAINTAINERS_GUIDE.md)
|
||||
|
||||
[http4k]: https://www.http4k.org/guide/reference/cloud_events/
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# Release Process
|
||||
|
||||
The release process is automated with Github actions. In order to perform a release:
|
||||
|
||||
1. Check if main CI pass.
|
||||
1. Open the Github repository main page and go in the tab "Actions". Trigger the workflow "Bump version" and insert the new version to release. This will create a new release PR.
|
||||
1. Check the release PR, merge it and cleanup the created branch.
|
||||
1. Wait for the CI to complete the deploy of the modules to OSSRH.
|
||||
1. Using the Github UI, create a new release, specifying the release notes and the tag to use.
|
||||
1. Trigger again the workflow "Bump version" to bump versions back to a snapshot version.
|
||||
1. Check the snapshot release PR, merge it and cleanup the created branch.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
# AMQP Protocol Binding
|
||||
|
||||
Javadoc: [](http://www.javadoc.io/doc/io.cloudevents/cloudevents-amqp-proton)
|
||||
|
||||
Documentation: https://cloudevents.github.io/sdk-java/amqp-proton
|
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-parent</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloudevents-amqp-proton</artifactId>
|
||||
<name>CloudEvents - Proton AMQP Binding</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<protonj.version>0.34.1</protonj.version>
|
||||
<jsr305.version>3.0.2</jsr305.version>
|
||||
<module-name>io.cloudevents.amqp.proton</module-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.qpid</groupId>
|
||||
<artifactId>proton-j</artifactId>
|
||||
<version>${protonj.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${jsr305.version}</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-core</artifactId>
|
||||
<classifier>tests</classifier>
|
||||
<type>test-jar</type>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.amqp;
|
||||
|
||||
import io.cloudevents.SpecVersion;
|
||||
import io.cloudevents.amqp.impl.AmqpConstants;
|
||||
import io.cloudevents.amqp.impl.ProtonAmqpBinaryMessageReader;
|
||||
import io.cloudevents.amqp.impl.ProtonAmqpMessageWriter;
|
||||
import io.cloudevents.core.message.MessageReader;
|
||||
import io.cloudevents.core.message.MessageWriter;
|
||||
import io.cloudevents.core.message.impl.GenericStructuredMessageReader;
|
||||
import io.cloudevents.core.message.impl.MessageUtils;
|
||||
import io.cloudevents.lang.Nullable;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
import io.cloudevents.rw.CloudEventWriter;
|
||||
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
|
||||
import org.apache.qpid.proton.amqp.messaging.Section;
|
||||
import org.apache.qpid.proton.message.Message;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* A factory class providing convenience methods for creating {@link MessageReader} and {@link MessageWriter} instances based on Qpid Proton {@link Message}.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public final class ProtonAmqpMessageFactory {
|
||||
|
||||
private ProtonAmqpMessageFactory() {
|
||||
// prevent instantiation
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MessageReader} to read a proton-based {@link Message}.
|
||||
* This reader is able to read both binary and structured encoded {@link io.cloudevents.CloudEvent}.
|
||||
*
|
||||
* @param message The proton {@link Message} to read from.
|
||||
* @return A {@link MessageReader} that can read the given proton {@link Message} to a {@link io.cloudevents.CloudEvent} representation.
|
||||
* @throws CloudEventRWException if something goes wrong while resolving the {@link SpecVersion} or if the message has unknown encoding
|
||||
* @see #createReader(String, ApplicationProperties, Section)
|
||||
*/
|
||||
public static MessageReader createReader(final Message message) throws CloudEventRWException {
|
||||
return createReader(message.getContentType(), message.getApplicationProperties(), message.getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MessageReader to read using the {@code content-type} property, {@code application-properties} and data payload
|
||||
* of a proton-based {@link Message}. This reader is able to read both binary and structured encoded {@link io.cloudevents.CloudEvent}.
|
||||
*
|
||||
* @param contentType The {@code content-type} of the message payload.
|
||||
* @param props The {@code application-properties} section of the proton-message containing cloud event metadata (attributes and/or extensions).
|
||||
* @param body The message body or {@code null} if the message does not contain any body.
|
||||
* @return A {@link MessageReader} capable of representing a {@link io.cloudevents.CloudEvent} from the {@code application-properties},
|
||||
* {@code content-type} and payload of a proton message.
|
||||
* @throws CloudEventRWException if something goes wrong while resolving the {@link SpecVersion} or if the message has unknown encoding
|
||||
*/
|
||||
public static MessageReader createReader(final String contentType, final ApplicationProperties props, @Nullable final Section body) throws CloudEventRWException {
|
||||
final byte[] payload = AmqpConstants.getPayloadAsByteArray(body);
|
||||
return MessageUtils.parseStructuredOrBinaryMessage(
|
||||
() -> contentType,
|
||||
format -> new GenericStructuredMessageReader(format, payload),
|
||||
() -> AmqpConstants.getApplicationProperty(props, AmqpConstants.APP_PROPERTY_SPEC_VERSION, String.class),
|
||||
sv -> new ProtonAmqpBinaryMessageReader(sv, props, contentType, payload)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link MessageWriter} capable of translating both a structured and binary CloudEvent
|
||||
* to a proton-based AMQP 1.0 {@link Message}.
|
||||
*
|
||||
* @return A {@link MessageWriter} to write a {@link io.cloudevents.CloudEvent} to Proton {@link Message} using structured or binary encoding.
|
||||
*/
|
||||
public static MessageWriter<CloudEventWriter<Message>, Message> createWriter() {
|
||||
return new ProtonAmqpMessageWriter<>();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.amqp.impl;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.qpid.proton.amqp.messaging.AmqpValue;
|
||||
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
|
||||
import org.apache.qpid.proton.amqp.messaging.Data;
|
||||
import org.apache.qpid.proton.amqp.messaging.Section;
|
||||
|
||||
import io.cloudevents.core.message.impl.MessageUtils;
|
||||
|
||||
/**
|
||||
* Constants and methods used throughout the Proton-based implementation of the AMQP 1.0 protocol
|
||||
* binding for cloud events.
|
||||
*/
|
||||
public final class AmqpConstants {
|
||||
|
||||
private AmqpConstants() {
|
||||
// prevent instantiation
|
||||
}
|
||||
|
||||
/**
|
||||
* The prefix name for CloudEvent attributes for use in the <em>application-properties</em> section
|
||||
* of an AMQP 1.0 message.
|
||||
*/
|
||||
public static final String CE_PREFIX = "cloudEvents:";
|
||||
|
||||
/**
|
||||
* The AMQP 1.0 <em>content-type</em> message property
|
||||
*/
|
||||
public static final String PROPERTY_CONTENT_TYPE = "content-type";
|
||||
|
||||
/**
|
||||
* Map a cloud event attribute name to a value. All values except the <em>datacontenttype</em> attribute are prefixed
|
||||
* with "cloudEvents:" as mandated by the spec.
|
||||
*/
|
||||
public static final Map<String, String> ATTRIBUTES_TO_PROPERTYNAMES = MessageUtils.generateAttributesToHeadersMapping(CEA -> {
|
||||
if (CEA.equals("datacontenttype")) {
|
||||
return PROPERTY_CONTENT_TYPE;
|
||||
}
|
||||
// prefix the attribute
|
||||
return CE_PREFIX + CEA;
|
||||
});
|
||||
|
||||
public static final String APP_PROPERTY_SPEC_VERSION = ATTRIBUTES_TO_PROPERTYNAMES.get("specversion");
|
||||
|
||||
/**
|
||||
* Gets the value of a specific <em>application property</em>.
|
||||
*
|
||||
* @param <T> The expected type of the property to retrieve.
|
||||
* @param props The application properties to retrieve the value from.
|
||||
* @param name The name of the application property.
|
||||
* @param type The expected value type.
|
||||
* @return The value or {@code null} if the properties do not contain a value of the expected type for the given
|
||||
* name.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getApplicationProperty(final ApplicationProperties props, final String name,
|
||||
final Class<T> type) {
|
||||
|
||||
if (props == null) {
|
||||
return null;
|
||||
} else {
|
||||
final Object value = props.getValue().get(name);
|
||||
if (type.isInstance(value)) {
|
||||
return (T) value;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a message payload into a byte array.
|
||||
* <p>
|
||||
* The bytes in the array are determined as follows:
|
||||
* <ul>
|
||||
* <li>If the body is a Data section, the bytes contained in the
|
||||
* Data section are returned.</li>
|
||||
* <li>If the body is an AmqpValue section and contains a byte array,
|
||||
* the bytes in the array are returned.</li>
|
||||
* <li>If the body is an AmqpValue section and contains a non-empty String,
|
||||
* the UTF-8 encoding of the String is returned.</li>
|
||||
* <li>In all other cases, {@code null} is returned.</li>
|
||||
* </ul>
|
||||
|
||||
* @param payload The message payload to extract the bytes from.
|
||||
* @return The payload bytes or {@code null} if the above stated conditions are not met.
|
||||
*/
|
||||
public static byte[] getPayloadAsByteArray(final Section payload) {
|
||||
if (payload == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (payload instanceof Data) {
|
||||
final Data body = (Data) payload;
|
||||
return body.getValue().getArray();
|
||||
} else if (payload instanceof AmqpValue) {
|
||||
final AmqpValue body = (AmqpValue) payload;
|
||||
if (body.getValue() instanceof byte[]) {
|
||||
return (byte[]) body.getValue();
|
||||
} else if (body.getValue() instanceof String &&
|
||||
((String) body.getValue()).length() > 0 ) {
|
||||
return ((String) body.getValue()).getBytes(StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.amqp.impl;
|
||||
|
||||
import io.cloudevents.SpecVersion;
|
||||
import io.cloudevents.core.data.BytesCloudEventData;
|
||||
import io.cloudevents.core.message.impl.BaseGenericBinaryMessageReaderImpl;
|
||||
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* An AMQP 1.0 message reader that can be read as a <em>CloudEvent</em>.
|
||||
* <p>
|
||||
*
|
||||
* This reader reads sections of an AMQP message to construct a CloudEvent representation by doing the following:
|
||||
* <ul>
|
||||
* <li> If the content-type property is set for an AMQP message, the value of the property
|
||||
* is represented as a cloud event datacontenttype attribute.
|
||||
* <li> If the (mandatory) application-properties of the AMQP message contains attributes and/or extentions,
|
||||
* this reader will represent each property/extension as a cloud event attribute.
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
public final class ProtonAmqpBinaryMessageReader extends BaseGenericBinaryMessageReaderImpl<String, Object> {
|
||||
|
||||
private final String contentType;
|
||||
private final ApplicationProperties applicationProperties;
|
||||
|
||||
/**
|
||||
* Create an instance of an AMQP message reader.
|
||||
*
|
||||
* @param version The version of the cloud event message.
|
||||
* @param applicationProperties The application properties of the AMQP message that contains
|
||||
* the cloud event metadata (i.e attributes and extensions).
|
||||
* The applicationProperties MUST not be {@code null}.
|
||||
* @param contentType The content-type property of the AMQP message or {@code null} if the message content type is unknown.
|
||||
* @param payload The message payload or {@code null} if the message does not contain any payload.
|
||||
*
|
||||
* @throws NullPointerException if the applicationPropereties is {@code null}.
|
||||
*/
|
||||
public ProtonAmqpBinaryMessageReader(final SpecVersion version, final ApplicationProperties applicationProperties,
|
||||
final String contentType, final byte[] payload) {
|
||||
super(version, payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null);
|
||||
this.contentType = contentType;
|
||||
this.applicationProperties = Objects.requireNonNull(applicationProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isContentTypeHeader(final String key) {
|
||||
return key.equals(AmqpConstants.PROPERTY_CONTENT_TYPE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the given attribute key is prefixed with <em>cloudEvents:</em>
|
||||
*
|
||||
* @param key The key to test for the presence of the prefix.
|
||||
* @return True if the specified key starts with the prefix or
|
||||
* false otherwise.
|
||||
*/
|
||||
@Override
|
||||
protected boolean isCloudEventsHeader(final String key) {
|
||||
final int prefixLength = AmqpConstants.CE_PREFIX.length();
|
||||
return key.length() > prefixLength && key.startsWith(AmqpConstants.CE_PREFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cloud event attribute key without the preceding prefix.
|
||||
*
|
||||
* @param key The key containing the AMQP specific prefix.
|
||||
*
|
||||
* @return The key without the prefix.
|
||||
*/
|
||||
@Override
|
||||
protected String toCloudEventsKey(final String key) {
|
||||
return key.substring(AmqpConstants.CE_PREFIX.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits the <em>content-type</em> message property and all <em>application-properties</em> of this message reader.
|
||||
* <p>
|
||||
* This method only visits properties containing a name and value which are not {@code null}.
|
||||
*
|
||||
* @param fn A callback to consume this reader's application-properties
|
||||
* and content-type property.
|
||||
*/
|
||||
@Override
|
||||
protected void forEachHeader(final BiConsumer<String, Object> fn) {
|
||||
if (contentType != null) {
|
||||
// visit the content-type message property
|
||||
fn.accept(AmqpConstants.PROPERTY_CONTENT_TYPE, contentType);
|
||||
}
|
||||
// visit application-properties
|
||||
applicationProperties.getValue().forEach((k, v) -> {
|
||||
if (k != null && v != null) {
|
||||
fn.accept(k, v);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the cloud event representation of the value.
|
||||
* <p>
|
||||
* This method simply returns the string representation of the type of value passed as argument.
|
||||
*
|
||||
* @param value The value of a CloudEvent attribute or extension.
|
||||
*
|
||||
* @return The string representation of the specified value.
|
||||
*/
|
||||
@Override
|
||||
protected String toCloudEventsValue(final Object value) {
|
||||
return value.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.amqp.impl;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.SpecVersion;
|
||||
import io.cloudevents.core.format.EventFormat;
|
||||
import io.cloudevents.core.message.MessageWriter;
|
||||
import io.cloudevents.core.v1.CloudEventV1;
|
||||
import io.cloudevents.rw.CloudEventContextWriter;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
import io.cloudevents.rw.CloudEventWriter;
|
||||
import org.apache.qpid.proton.amqp.Binary;
|
||||
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
|
||||
import org.apache.qpid.proton.amqp.messaging.Data;
|
||||
import org.apache.qpid.proton.message.Message;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A proton-based MessageWriter capable of writing both structured and binary CloudEvent messages to an AMQP 1.0 representation as
|
||||
* mandated by the AMQP 1.0 protocol binding specification for cloud events.
|
||||
* <p>
|
||||
* This writer returns an AMQP message at the end of the write process.
|
||||
*/
|
||||
public final class ProtonAmqpMessageWriter<R> implements MessageWriter<CloudEventWriter<Message>, Message>, CloudEventWriter<Message> {
|
||||
|
||||
private ApplicationProperties applicationProperties;
|
||||
private Message message;
|
||||
|
||||
/**
|
||||
* Creates a proton-base message writer.
|
||||
*/
|
||||
public ProtonAmqpMessageWriter() {
|
||||
message = Message.Factory.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEventContextWriter withContextAttribute(String name, String value) throws CloudEventRWException {
|
||||
if (name.equals(CloudEventV1.DATACONTENTTYPE)) {
|
||||
message.setContentType(value);
|
||||
} else {
|
||||
// for now, extensions are mapped to application-properties
|
||||
// see https://github.com/cloudevents/sdk-java/issues/30#issuecomment-723982190
|
||||
if (applicationProperties == null) {
|
||||
throw new IllegalStateException("This Writer is not initialized");
|
||||
}
|
||||
String propName = AmqpConstants.ATTRIBUTES_TO_PROPERTYNAMES.get(name);
|
||||
if (propName == null) {
|
||||
propName = name;
|
||||
}
|
||||
applicationProperties.getValue().put(propName, value);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtonAmqpMessageWriter<R> create(final SpecVersion version) {
|
||||
if (applicationProperties == null) {
|
||||
applicationProperties = new ApplicationProperties(new HashMap<>());
|
||||
}
|
||||
applicationProperties.getValue().put(AmqpConstants.APP_PROPERTY_SPEC_VERSION, version.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message setEvent(final EventFormat format, final byte[] value) throws CloudEventRWException {
|
||||
message.setContentType(format.serializedContentType());
|
||||
message.setBody(new Data(new Binary(value)));
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message end(final CloudEventData data) throws CloudEventRWException {
|
||||
message.setBody(new Data(new Binary(data.toBytes())));
|
||||
message.setApplicationProperties(applicationProperties);
|
||||
return message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Message end() {
|
||||
message.setBody(null);
|
||||
message.setApplicationProperties(applicationProperties);
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.amqp;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.SpecVersion;
|
||||
import io.cloudevents.amqp.impl.AmqpConstants;
|
||||
import io.cloudevents.core.message.Encoding;
|
||||
import io.cloudevents.core.message.MessageReader;
|
||||
import io.cloudevents.core.mock.CSVFormat;
|
||||
import io.cloudevents.core.test.Data;
|
||||
import io.cloudevents.core.v03.CloudEventV03;
|
||||
import io.cloudevents.core.v1.CloudEventV1;
|
||||
import io.cloudevents.types.Time;
|
||||
import org.apache.qpid.proton.amqp.Binary;
|
||||
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
|
||||
import org.apache.qpid.proton.amqp.messaging.Section;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.util.AbstractMap.SimpleEntry;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests verifying the behavior of the {@code ProtonAmqpMessageFactory}.
|
||||
*/
|
||||
public class ProtonAmqpMessageFactoryTest {
|
||||
|
||||
private static final String PREFIX_TEMPLATE = AmqpConstants.CE_PREFIX + "%s";
|
||||
private static final String DATACONTENTTYPE_NULL = null;
|
||||
private static final byte[] DATAPAYLOAD_NULL = null;
|
||||
|
||||
@ParameterizedTest()
|
||||
@MethodSource("binaryTestArguments")
|
||||
public void readBinary(final Map<String, Object> props, final String contentType, final byte[] body,
|
||||
final CloudEvent event) {
|
||||
final Section bodySection = body != null ? new org.apache.qpid.proton.amqp.messaging.Data(new Binary(body)) : null;
|
||||
final MessageReader amqpReader = ProtonAmqpMessageFactory.createReader(contentType, new ApplicationProperties(props), bodySection);
|
||||
assertThat(amqpReader.getEncoding()).isEqualTo(Encoding.BINARY);
|
||||
assertThat(amqpReader.toEvent()).isEqualTo(event);
|
||||
}
|
||||
|
||||
@ParameterizedTest()
|
||||
@MethodSource("io.cloudevents.core.test.Data#allEventsWithoutExtensions")
|
||||
public void readStructured(final CloudEvent event) {
|
||||
final String contentType = CSVFormat.INSTANCE.serializedContentType() + "; charset=utf8";
|
||||
final byte[] contentPayload = CSVFormat.INSTANCE.serialize(event);
|
||||
|
||||
final MessageReader amqpReader = ProtonAmqpMessageFactory.createReader(contentType, null, new org.apache.qpid.proton.amqp.messaging.Data(new Binary(contentPayload)));
|
||||
assertThat(amqpReader.getEncoding()).isEqualTo(Encoding.STRUCTURED);
|
||||
assertThat(amqpReader.toEvent()).isEqualTo(event);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> binaryTestArguments() {
|
||||
|
||||
return Stream.of(
|
||||
// V03
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()),
|
||||
property(CloudEventV03.ID, Data.ID),
|
||||
property(CloudEventV03.TYPE, Data.TYPE),
|
||||
property(CloudEventV03.SOURCE, Data.SOURCE),
|
||||
property("ignored", "ignore")
|
||||
),
|
||||
DATACONTENTTYPE_NULL,
|
||||
DATAPAYLOAD_NULL,
|
||||
Data.V03_MIN
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()),
|
||||
property(CloudEventV03.ID, Data.ID),
|
||||
property(CloudEventV03.TYPE, Data.TYPE),
|
||||
property(CloudEventV03.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV03.SCHEMAURL, Data.DATASCHEMA.toString()),
|
||||
property(CloudEventV03.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV03.TIME, Time.writeTime(Data.TIME)),
|
||||
property("ignored", "ignore")
|
||||
),
|
||||
Data.DATACONTENTTYPE_JSON,
|
||||
Data.DATA_JSON_SERIALIZED,
|
||||
Data.V03_WITH_JSON_DATA
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()),
|
||||
property(CloudEventV03.ID, Data.ID),
|
||||
property(CloudEventV03.TYPE, Data.TYPE),
|
||||
property(CloudEventV03.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV03.SCHEMAURL, Data.DATASCHEMA.toString()),
|
||||
property(CloudEventV03.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV03.TIME, Time.writeTime(Data.TIME)),
|
||||
property("astring", "aaa"),
|
||||
property("aboolean", "true"),
|
||||
property("anumber", "10"),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_JSON,
|
||||
Data.DATA_JSON_SERIALIZED,
|
||||
Data.V03_WITH_JSON_DATA_WITH_EXT_STRING
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()),
|
||||
property(CloudEventV03.ID, Data.ID),
|
||||
property(CloudEventV03.TYPE, Data.TYPE),
|
||||
property(CloudEventV03.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV03.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV03.TIME, Time.writeTime(Data.TIME)),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_XML,
|
||||
Data.DATA_XML_SERIALIZED,
|
||||
Data.V03_WITH_XML_DATA
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()),
|
||||
property(CloudEventV03.ID, Data.ID),
|
||||
property(CloudEventV03.TYPE, Data.TYPE),
|
||||
property(CloudEventV03.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV03.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV03.TIME, Time.writeTime(Data.TIME)),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_TEXT,
|
||||
Data.DATA_TEXT_SERIALIZED,
|
||||
Data.V03_WITH_TEXT_DATA
|
||||
),
|
||||
// V1
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()),
|
||||
property(CloudEventV1.ID, Data.ID),
|
||||
property(CloudEventV1.TYPE, Data.TYPE),
|
||||
property(CloudEventV1.SOURCE, Data.SOURCE.toString()),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
DATACONTENTTYPE_NULL,
|
||||
DATAPAYLOAD_NULL,
|
||||
Data.V1_MIN
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()),
|
||||
property(CloudEventV1.ID, Data.ID),
|
||||
property(CloudEventV1.TYPE, Data.TYPE),
|
||||
property(CloudEventV1.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV1.DATASCHEMA, Data.DATASCHEMA.toString()),
|
||||
property(CloudEventV1.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV1.TIME, Time.writeTime(Data.TIME)),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_JSON,
|
||||
Data.DATA_JSON_SERIALIZED,
|
||||
Data.V1_WITH_JSON_DATA
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()),
|
||||
property(CloudEventV1.ID, Data.ID),
|
||||
property(CloudEventV1.TYPE, Data.TYPE),
|
||||
property(CloudEventV1.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV1.DATASCHEMA, Data.DATASCHEMA.toString()),
|
||||
property(CloudEventV1.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV1.TIME, Time.writeTime(Data.TIME)),
|
||||
property("astring", "aaa"),
|
||||
property("aboolean", "true"),
|
||||
property("anumber", "10"),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_JSON,
|
||||
Data.DATA_JSON_SERIALIZED,
|
||||
Data.V1_WITH_JSON_DATA_WITH_EXT_STRING
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()),
|
||||
property(CloudEventV1.ID, Data.ID),
|
||||
property(CloudEventV1.TYPE, Data.TYPE),
|
||||
property(CloudEventV1.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV1.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV1.TIME, Time.writeTime(Data.TIME)),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_XML,
|
||||
Data.DATA_XML_SERIALIZED,
|
||||
Data.V1_WITH_XML_DATA
|
||||
),
|
||||
Arguments.of(
|
||||
properties(
|
||||
property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()),
|
||||
property(CloudEventV1.ID, Data.ID),
|
||||
property(CloudEventV1.TYPE, Data.TYPE),
|
||||
property(CloudEventV1.SOURCE, Data.SOURCE.toString()),
|
||||
property(CloudEventV1.SUBJECT, Data.SUBJECT),
|
||||
property(CloudEventV1.TIME, Time.writeTime(Data.TIME)),
|
||||
property("ignored", "ignored")
|
||||
),
|
||||
Data.DATACONTENTTYPE_TEXT,
|
||||
Data.DATA_TEXT_SERIALIZED,
|
||||
Data.V1_WITH_TEXT_DATA
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static final SimpleEntry<String, Object> property(final String name, final Object value) {
|
||||
return name.equalsIgnoreCase("ignored") ?
|
||||
new SimpleEntry<>(name, value) :
|
||||
new SimpleEntry<>(String.format(PREFIX_TEMPLATE, name), value);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
private static final Map<String, Object> properties(final SimpleEntry<String, Object>... entries) {
|
||||
return Stream.of(entries)
|
||||
.collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.amqp;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.qpid.proton.amqp.Binary;
|
||||
import org.apache.qpid.proton.amqp.messaging.ApplicationProperties;
|
||||
import org.apache.qpid.proton.amqp.messaging.Section;
|
||||
import org.apache.qpid.proton.message.Message;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.amqp.impl.ProtonAmqpMessageWriter;
|
||||
import io.cloudevents.core.format.EventFormat;
|
||||
import io.cloudevents.core.message.MessageWriter;
|
||||
import io.cloudevents.core.mock.CSVFormat;
|
||||
|
||||
/**
|
||||
* Tests verifying the behavior of the {@code ProtonAmqpMessageWriter}.
|
||||
*/
|
||||
public class ProtonAmqpMessageWriterTest {
|
||||
|
||||
/**
|
||||
* Verifies that a binary CloudEvent message can be successfully represented
|
||||
* as an AMQP message.
|
||||
*/
|
||||
@ParameterizedTest()
|
||||
@MethodSource("io.cloudevents.core.test.Data#allEventsWithStringExtensions")
|
||||
public void testWriteBinaryCloudEventToAmqpRepresentation(final CloudEvent binaryEvent) {
|
||||
|
||||
final Message expectedMessage = translateBinaryEvent(binaryEvent);
|
||||
|
||||
final MessageWriter<?, Message> writer = new ProtonAmqpMessageWriter<Message>();
|
||||
final Message actualMessage = writer.writeBinary(binaryEvent);
|
||||
|
||||
assertThat(actualMessage.getContentType()).isEqualTo(expectedMessage.getContentType());
|
||||
assertThat(Objects.toString(actualMessage.getBody())).isEqualTo(Objects.toString(expectedMessage.getBody()));
|
||||
assertThat(actualMessage.getApplicationProperties().getValue()).
|
||||
isEqualTo(expectedMessage.getApplicationProperties().getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies that a structured CloudEvent message (in CSV format) can be successfully represented
|
||||
* as an AMQP message.
|
||||
*/
|
||||
@ParameterizedTest()
|
||||
@MethodSource("io.cloudevents.core.test.Data#allEventsWithoutExtensions")
|
||||
public void testWriteStructuredCloudEventToAmqpRepresentation(final CloudEvent event) {
|
||||
final EventFormat format = CSVFormat.INSTANCE;
|
||||
final Message expectedMessage = translateStructured(event, format);
|
||||
|
||||
final MessageWriter<?, Message> writer = new ProtonAmqpMessageWriter<Message>();
|
||||
final Message actualMessage = writer.writeStructured(event, format.serializedContentType());
|
||||
|
||||
assertThat(actualMessage.getContentType()).isEqualTo(expectedMessage.getContentType());
|
||||
assertThat(Objects.toString(actualMessage.getBody())).isEqualTo(Objects.toString(expectedMessage.getBody()));
|
||||
assertThat(actualMessage.getApplicationProperties()).isNull();
|
||||
}
|
||||
|
||||
private Message translateBinaryEvent(final CloudEvent event) {
|
||||
|
||||
final Message message = Message.Factory.create();
|
||||
|
||||
final Map<String, Object> map = new HashMap<>();
|
||||
|
||||
if (!event.getAttributeNames().isEmpty()) {
|
||||
event.getAttributeNames().forEach(name -> {
|
||||
if (name.equals("datacontentencoding")) {
|
||||
// ignore
|
||||
} else if (name.equals("datacontenttype") && event.getAttribute(name) != null) {
|
||||
message.setContentType(event.getAttribute(name).toString());
|
||||
} else {
|
||||
addProperty(map, name, Objects.toString(event.getAttribute(name)), true);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!event.getExtensionNames().isEmpty()) {
|
||||
event.getExtensionNames().forEach(name -> addProperty(map, name, Objects.toString(event.getExtension(name)), false));
|
||||
}
|
||||
|
||||
if (event.getData() != null) {
|
||||
final Section payload = new org.apache.qpid.proton.amqp.messaging.Data(new Binary(event.getData().toBytes()));
|
||||
message.setBody(payload);
|
||||
}
|
||||
|
||||
message.setApplicationProperties(new ApplicationProperties(map));
|
||||
return message;
|
||||
}
|
||||
|
||||
private Message translateStructured(final CloudEvent event, final EventFormat format) {
|
||||
final Message message = Message.Factory.create();
|
||||
message.setContentType(format.serializedContentType());
|
||||
message.setBody(new org.apache.qpid.proton.amqp.messaging.Data(new Binary(format.serialize(event))));
|
||||
return message;
|
||||
}
|
||||
private void addProperty(final Map<String, Object> map, final String name, final String value, final boolean prefix) {
|
||||
if (prefix) {
|
||||
map.put(String.format("cloudEvents:%s", name), value);
|
||||
} else {
|
||||
map.put(name, value);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
# CloudEvents API
|
||||
|
||||
Javadoc: [](http://www.javadoc.io/doc/io.cloudevents/cloudevents-api)
|
||||
|
||||
Documentation: https://cloudevents.github.io/sdk-java/api
|
72
api/pom.xml
72
api/pom.xml
|
@ -1,67 +1,59 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2018 The CloudEvents Authors
|
||||
~ Copyright 2018-Present The CloudEvents Authors
|
||||
~ <p>
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~ <p>
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ <p>
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-parent</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-api</artifactId>
|
||||
<name>CloudEvents - API</name>
|
||||
<version>0.2.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<module-name>io.cloudevents.api</module-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jdk8</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.10.0</version>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jackson.version>2.9.6</jackson.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
|
|
|
@ -1,74 +1,32 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import io.cloudevents.lang.Nullable;
|
||||
|
||||
/**
|
||||
* An abstract event envelope, representing the 0.2 version of the <a href="https://github.com/cloudevents/spec/blob/master/spec.md">CNCF CloudEvent spec</a>.
|
||||
*
|
||||
* Interface representing an in memory read only representation of a CloudEvent,
|
||||
* as specified by the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md">CloudEvents specification</a>.
|
||||
*/
|
||||
public interface CloudEvent<T> {
|
||||
public interface CloudEvent extends CloudEventContext {
|
||||
|
||||
/**
|
||||
* Type of occurrence which has happened. Often this property is used for routing, observability, policy enforcement, etc.
|
||||
* @return The event data, if any, otherwise {@code null}
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* The version of the CloudEvents specification which the event uses. This enables the interpretation of the context.
|
||||
*/
|
||||
String getSpecVersion();
|
||||
|
||||
/**
|
||||
* This describes the event producer. Often this will include information such as the type of the event source, the organization publishing the event, and some unique identifiers.
|
||||
* The exact syntax and semantics behind the data encoded in the URI is event producer defined.
|
||||
*/
|
||||
URI getSource();
|
||||
|
||||
/**
|
||||
* ID of the event. The semantics of this string are explicitly undefined to ease the implementation of producers. Enables deduplication.
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* Timestamp of when the event happened.
|
||||
*/
|
||||
Optional<ZonedDateTime> getTime();
|
||||
|
||||
/**
|
||||
* A link to the schema that the data attribute adheres to.
|
||||
*/
|
||||
Optional<URI> getSchemaURL();
|
||||
|
||||
/**
|
||||
* Describe the data encoding format
|
||||
*/
|
||||
Optional<String> getContentType();
|
||||
|
||||
/**
|
||||
* The event payload. The payload depends on the eventType, schemaURL and eventTypeVersion, the payload is encoded into a media format which is specified by the contentType attribute (e.g. application/json).
|
||||
*/
|
||||
Optional<T> getData();
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
Optional<List<Extension>> getExtensions();
|
||||
}
|
||||
@Nullable
|
||||
CloudEventData getData();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.lang.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.net.URI;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Interface which defines CloudEvent attributes as per specification
|
||||
* <p>
|
||||
* For more info: <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#context-attributes">Context attributes</a>
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventAttributes {
|
||||
|
||||
/**
|
||||
* @return The version of the CloudEvents specification which the event uses
|
||||
*/
|
||||
SpecVersion getSpecVersion();
|
||||
|
||||
/**
|
||||
* @return Identifies the event. Producers MUST ensure that source + id is unique for each distinct event
|
||||
*/
|
||||
String getId();
|
||||
|
||||
/**
|
||||
* @return A value describing the type of event related to the originating occurrence.
|
||||
*/
|
||||
String getType();
|
||||
|
||||
/**
|
||||
* @return The context in which an event happened.
|
||||
*/
|
||||
URI getSource();
|
||||
|
||||
/**
|
||||
* A common way to get the media type of CloudEvents 'data';
|
||||
*
|
||||
* @return If has a value, it MUST follows the <a href="https://tools.ietf.org/html/rfc2046">RFC2046</a>
|
||||
*/
|
||||
@Nullable
|
||||
String getDataContentType();
|
||||
|
||||
/**
|
||||
* @return Return the URI specifying the location of the schema for the provided data
|
||||
*/
|
||||
@Nullable
|
||||
URI getDataSchema();
|
||||
|
||||
/**
|
||||
* @return <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#subject">Subject</a> of the event
|
||||
*/
|
||||
@Nullable
|
||||
String getSubject();
|
||||
|
||||
/**
|
||||
* @return <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#time">Timestamp</a> of when the occurrence happened
|
||||
*/
|
||||
@Nullable
|
||||
OffsetDateTime getTime();
|
||||
|
||||
/**
|
||||
* Get the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#context-attributes">context attribute</a> named {@code attributeName}
|
||||
*
|
||||
* @param attributeName a valid attribute name
|
||||
* @return the attribute value or null if this instance doesn't contain such attribute
|
||||
* @throws IllegalArgumentException if the provided attribute name it's not a valid attribute for this spec
|
||||
*/
|
||||
@Nullable
|
||||
Object getAttribute(String attributeName) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* @return The non-null <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#context-attributes">context attributes</a> names in this instance
|
||||
*/
|
||||
default Set<String> getAttributeNames() {
|
||||
return getSpecVersion()
|
||||
.getAllAttributes()
|
||||
.stream()
|
||||
.filter(s -> getAttribute(s) != null)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,130 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.impl.DefaultCloudEventImpl;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Builder class to create a Java Object representing a CloudEvent implementation
|
||||
* @param <T> type of the data field
|
||||
*/
|
||||
public class CloudEventBuilder<T> {
|
||||
|
||||
private String specversion;
|
||||
private String contentType;
|
||||
private String type;
|
||||
private URI source;
|
||||
private String id;
|
||||
private ZonedDateTime time;
|
||||
private URI schemaURL;
|
||||
private T data;
|
||||
private final List<Extension> extensions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* The version of the CloudEvents specification which the event uses.
|
||||
*/
|
||||
public CloudEventBuilder<T> specVersion(final String specVersion) {
|
||||
this.specversion = specVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type of occurrence which has happened. Often this property is used for routing, observability, policy enforcement, etc.
|
||||
*/
|
||||
public CloudEventBuilder<T> type(final String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* This describes the event producer. Often this will include information such as the type of the event source, the organization publishing the event, and some unique identifiers.
|
||||
* The exact syntax and semantics behind the data encoded in the URI is event producer defined.
|
||||
*/
|
||||
public CloudEventBuilder<T> source(final URI source) {
|
||||
this.source = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ID of the event. The semantics of this string are explicitly undefined to ease the implementation of producers. Enables deduplication.
|
||||
*/
|
||||
public CloudEventBuilder<T> id(final String id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamp of when the event happened.
|
||||
*/
|
||||
public CloudEventBuilder<T> time(final ZonedDateTime time) {
|
||||
this.time = time;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A link to the schema that the data attribute adheres to.
|
||||
*/
|
||||
public CloudEventBuilder<T> schemaURL(final URI schemaURL) {
|
||||
this.schemaURL = schemaURL;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe the data encoding format
|
||||
*/
|
||||
public CloudEventBuilder<T> contentType(final String contentType) {
|
||||
this.contentType = contentType;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The event payload. The payload depends on the type and schemaURL, the payload is encoded into a media format which is specified by the contenttype attribute (e.g. application/json).
|
||||
*/
|
||||
public CloudEventBuilder<T> data(final T data) {
|
||||
this.data = data;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CloudEventBuilder<T> extension(final Extension extension) {
|
||||
this.extensions.add(extension);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link CloudEvent} with the previously-set configuration.
|
||||
*/
|
||||
public CloudEvent<T> build() {
|
||||
|
||||
// forcing latest (default) version
|
||||
if (specversion == null) {
|
||||
specversion = SpecVersion.DEFAULT.toString();
|
||||
}
|
||||
|
||||
if (type == null || source == null || id == null) {
|
||||
throw new IllegalArgumentException("please provide all required fields");
|
||||
}
|
||||
|
||||
return new DefaultCloudEventImpl<T>(type, specversion, source, id, time, schemaURL, contentType, data, extensions);
|
||||
}
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
public interface Extension {
|
||||
/**
|
||||
* Interface representing an in memory read only representation of CloudEvent attributes and extensions.
|
||||
*/
|
||||
public interface CloudEventContext extends CloudEventAttributes, CloudEventExtensions {
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents;
|
||||
|
||||
/**
|
||||
* Interface that defines a wrapper for CloudEvent data.
|
||||
* <p>
|
||||
* This interface can be overridden to include any type of data inside a {@link CloudEvent}, given it has a method to convert back to bytes.
|
||||
*/
|
||||
public interface CloudEventData {
|
||||
|
||||
/**
|
||||
* Returns the bytes representation of this data instance.
|
||||
* <p>
|
||||
* Note: depending on the implementation, this operation may be expensive.
|
||||
*
|
||||
* @return this data, represented as bytes.
|
||||
*/
|
||||
byte[] toBytes();
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.lang.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Materialized CloudEvent extension interface to read/write the extension attributes key/values.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventExtension {
|
||||
|
||||
/**
|
||||
* Fill this materialized extension with values from a {@link CloudEventExtensions} implementation.
|
||||
*
|
||||
* @param extensions the extensions where to read from
|
||||
*/
|
||||
void readFrom(CloudEventExtensions extensions);
|
||||
|
||||
/**
|
||||
* Get the attribute of extension named {@code key}.
|
||||
*
|
||||
* @param key the name of the extension attribute
|
||||
* @return the extension value in one of the valid types String/Number/Boolean/URI/OffsetDateTime/byte[]
|
||||
* @throws IllegalArgumentException if the key is unknown to this extension
|
||||
*/
|
||||
@Nullable
|
||||
Object getValue(String key) throws IllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Get the set of possible extension attribute keys
|
||||
*
|
||||
* @return set of possible extension attribute keys
|
||||
*/
|
||||
Set<String> getKeys();
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.lang.Nullable;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The event extensions.
|
||||
* <p>
|
||||
* Extensions values could be String/Number/Boolean
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventExtensions {
|
||||
|
||||
/**
|
||||
* Get the extension attribute named {@code extensionName}
|
||||
*
|
||||
* @param extensionName the extension name
|
||||
* @return the extension value in one of the valid types String/Number/Boolean or null if this instance doesn't contain such extension
|
||||
*/
|
||||
@Nullable
|
||||
Object getExtension(String extensionName);
|
||||
|
||||
/**
|
||||
* @return The non-null extension attributes names in this instance
|
||||
*/
|
||||
Set<String> getExtensionNames();
|
||||
|
||||
}
|
|
@ -1,68 +1,106 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Represents one of the supported CloudEvents specification versions by this library
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public enum SpecVersion {
|
||||
/**
|
||||
* @see <a href="https://github.com/cloudevents/spec/releases/tag/v0.3">CloudEvents release v0.3</a>
|
||||
*/
|
||||
V03(
|
||||
"0.3",
|
||||
Arrays.asList("specversion", "id", "type", "source"),
|
||||
Arrays.asList("datacontenttype", "datacontentencoding", "schemaurl", "subject", "time")
|
||||
),
|
||||
/**
|
||||
* @see <a href="https://github.com/cloudevents/spec/releases/tag/v1.0">CloudEvents release v1.0</a>
|
||||
*/
|
||||
V1(
|
||||
"1.0",
|
||||
Arrays.asList("specversion", "id", "type", "source"),
|
||||
Arrays.asList("datacontenttype", "dataschema", "subject", "time")
|
||||
);
|
||||
|
||||
V_01("0.1"),
|
||||
V_02("0.2"),
|
||||
DEFAULT(V_02.toString());
|
||||
private final String stringValue;
|
||||
private final Set<String> mandatoryAttributes;
|
||||
private final Set<String> optionalAttributes;
|
||||
private final Set<String> allAttributes;
|
||||
|
||||
private final String version;
|
||||
|
||||
SpecVersion(final String version) {
|
||||
this.version = version;
|
||||
SpecVersion(String stringValue, Collection<String> mandatoryAttributes, Collection<String> optionalAttributes) {
|
||||
this.stringValue = stringValue;
|
||||
this.mandatoryAttributes = Collections.unmodifiableSet(new HashSet<>(mandatoryAttributes));
|
||||
this.optionalAttributes = Collections.unmodifiableSet(new HashSet<>(optionalAttributes));
|
||||
this.allAttributes = Collections.unmodifiableSet(
|
||||
Stream.concat(mandatoryAttributes.stream(), optionalAttributes.stream()).collect(Collectors.toSet())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return version;
|
||||
return this.stringValue;
|
||||
}
|
||||
|
||||
public String version() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public static SpecVersion fromVersion(final String version) {
|
||||
if (version == null)
|
||||
return null;
|
||||
|
||||
final SpecVersion specVersion= VERSION_TO_SPEC.get(version);
|
||||
|
||||
if (specVersion == null)
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
return specVersion;
|
||||
}
|
||||
|
||||
private static final Map<String, SpecVersion> VERSION_TO_SPEC =
|
||||
new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
SpecVersion[] instances = SpecVersion.class.getEnumConstants();
|
||||
|
||||
for (int i = 0; i < instances.length; i++)
|
||||
{
|
||||
VERSION_TO_SPEC.put(instances[i].toString(), instances[i]);
|
||||
/**
|
||||
* Parse a string as {@link SpecVersion}
|
||||
*
|
||||
* @param sv String representing the spec version
|
||||
* @return The parsed spec version
|
||||
* @throws CloudEventRWException When the spec version string is unrecognized
|
||||
*/
|
||||
public static SpecVersion parse(String sv) {
|
||||
switch (sv) {
|
||||
case "0.3":
|
||||
return SpecVersion.V03;
|
||||
case "1.0":
|
||||
return SpecVersion.V1;
|
||||
default:
|
||||
throw CloudEventRWException.newInvalidSpecVersion(sv);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mandatory attributes of the spec version
|
||||
*/
|
||||
public Set<String> getMandatoryAttributes() {
|
||||
return mandatoryAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return optional attributes of the spec version
|
||||
*/
|
||||
public Set<String> getOptionalAttributes() {
|
||||
return optionalAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return all attributes for this spec
|
||||
*/
|
||||
public Set<String> getAllAttributes() {
|
||||
return allAttributes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package io.cloudevents.extensions;
|
||||
|
||||
import io.cloudevents.Extension;
|
||||
|
||||
public class DistributedTracingExtension implements Extension {
|
||||
|
||||
private String traceparent;
|
||||
private String tracestate;
|
||||
|
||||
public String getTraceparent() {
|
||||
return traceparent;
|
||||
}
|
||||
|
||||
public void setTraceparent(String traceparent) {
|
||||
this.traceparent = traceparent;
|
||||
}
|
||||
|
||||
public String getTracestate() {
|
||||
return tracestate;
|
||||
}
|
||||
|
||||
public void setTracestate(String tracestate) {
|
||||
this.tracestate = tracestate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DistributedTracingExtension{" +
|
||||
"traceparent='" + traceparent + '\'' +
|
||||
", tracestate='" + tracestate + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.http;
|
||||
|
||||
import io.cloudevents.SpecVersion;
|
||||
|
||||
import static io.cloudevents.SpecVersion.V_01;
|
||||
|
||||
public interface HttpTransportAttributes {
|
||||
|
||||
// required attrs
|
||||
String typeKey();
|
||||
String specVersionKey();
|
||||
String sourceKey();
|
||||
String idKey();
|
||||
|
||||
// none-required attrs
|
||||
String timeKey();
|
||||
String schemaUrlKey();
|
||||
|
||||
static HttpTransportAttributes getHttpAttributesForSpec(final SpecVersion specVersion) {
|
||||
|
||||
switch (specVersion) {
|
||||
|
||||
case V_01: return new V01HttpTransportMappers();
|
||||
case V_02:
|
||||
case DEFAULT: return new V02HttpTransportMappers();
|
||||
}
|
||||
|
||||
// you should not be here!
|
||||
throw new IllegalArgumentException("Could not find proper version");
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.http;
|
||||
|
||||
public class V01HttpTransportMappers implements HttpTransportAttributes {
|
||||
|
||||
public static final String SPEC_VERSION_KEY = "ce-cloudEventsVersion";
|
||||
|
||||
@Override
|
||||
public String typeKey() {
|
||||
return "ce-eventType";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String specVersionKey() {
|
||||
return SPEC_VERSION_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String sourceKey() {
|
||||
return "ce-source";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String idKey() {
|
||||
return "ce-eventID";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String timeKey() {
|
||||
return "ce-eventTime";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String schemaUrlKey() {
|
||||
return "ce-schemaURL";
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.http;
|
||||
|
||||
public class V02HttpTransportMappers extends V01HttpTransportMappers {
|
||||
|
||||
public static final String SPEC_VERSION_KEY = "ce-specversion";
|
||||
|
||||
@Override
|
||||
public String typeKey() {
|
||||
return "ce-type";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String specVersionKey() {
|
||||
return SPEC_VERSION_KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String idKey() {
|
||||
return "ce-id";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String timeKey() {
|
||||
return "ce-time";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String schemaUrlKey() {
|
||||
return "ce-schemaurl";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.impl;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.Extension;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Default Java implementation of the CloudEvent API.
|
||||
*
|
||||
* @param <T> generic type of the underlying data field.
|
||||
*/
|
||||
@JsonIgnoreProperties(value = { "eventTypeVersion", "extensions" }) // was removed from 0.1
|
||||
public class DefaultCloudEventImpl<T> implements CloudEvent<T>, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
private String specversion;
|
||||
private String type = null;
|
||||
private URI source = null;
|
||||
private String id = null;
|
||||
private ZonedDateTime time = null;
|
||||
private URI schemaURL = null;
|
||||
private String contentType = null;
|
||||
private T data = null;
|
||||
private List<Extension> extensions = null;
|
||||
|
||||
public DefaultCloudEventImpl(final String type, final String specversion, final URI source, final String id, final ZonedDateTime time, final URI schemaURL, final String contentType, final T data, final List<Extension> extensions) {
|
||||
this.specversion = specversion;
|
||||
this.type = type;
|
||||
this.source = source;
|
||||
this.id = id;
|
||||
this.time = time;
|
||||
this.schemaURL = schemaURL;
|
||||
this.contentType = contentType;
|
||||
this.data = data;
|
||||
this.extensions = extensions;
|
||||
}
|
||||
|
||||
DefaultCloudEventImpl() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpecVersion() {
|
||||
return specversion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URI getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ZonedDateTime> getTime() {
|
||||
return Optional.ofNullable(time);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<URI> getSchemaURL() {
|
||||
return Optional.ofNullable(schemaURL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getContentType() {
|
||||
return Optional.ofNullable(contentType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<T> getData() {
|
||||
return Optional.ofNullable(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<List<Extension>> getExtensions() {
|
||||
return Optional.ofNullable(extensions);
|
||||
}
|
||||
|
||||
// protected setters, used for (JSON) deserialization
|
||||
|
||||
@JsonAlias({"specversion", "specVersion", "cloudEventsVersion"})
|
||||
void setSpecversion(String specversion) {
|
||||
this.specversion = specversion;
|
||||
}
|
||||
|
||||
@JsonAlias({"type", "eventType"})
|
||||
void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
void setSource(URI source) {
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
@JsonAlias({"id", "eventID"})
|
||||
void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@JsonDeserialize(using = ZonedDateTimeDeserializer.class)
|
||||
@JsonAlias({"time", "eventTime"})
|
||||
void setTime(ZonedDateTime time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
void setSchemaURL(URI schemaURL) {
|
||||
this.schemaURL = schemaURL;
|
||||
}
|
||||
|
||||
void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
void setData(T data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefaultCloudEventImpl{" +
|
||||
"specversion='" + specversion + '\'' +
|
||||
", type='" + type + '\'' +
|
||||
", source=" + source +
|
||||
", id='" + id + '\'' +
|
||||
", time=" + time +
|
||||
", schemaURL=" + schemaURL +
|
||||
", contentType='" + contentType + '\'' +
|
||||
", data=" + data +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.DateTimeException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
|
||||
public class ZonedDateTimeDeserializer extends StdDeserializer<ZonedDateTime> {
|
||||
|
||||
public ZonedDateTimeDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public ZonedDateTimeDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime deserialize(JsonParser jsonparser, DeserializationContext ctxt) throws IOException {
|
||||
// not serializing timezone data yet
|
||||
try {
|
||||
return ZonedDateTime.parse(jsonparser.getText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
} catch (DateTimeException e) {
|
||||
throw new IllegalArgumentException("could not parse");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||
|
||||
public class ZonedDateTimeSerializer extends StdSerializer<ZonedDateTime> {
|
||||
|
||||
private static final long serialVersionUID = 6245182835980474796L;
|
||||
|
||||
public ZonedDateTimeSerializer() {
|
||||
this(null, false);
|
||||
}
|
||||
|
||||
protected ZonedDateTimeSerializer(Class<?> t, boolean dummy) {
|
||||
super(t, dummy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ZonedDateTime time, JsonGenerator generator,
|
||||
SerializerProvider provider) throws IOException {
|
||||
|
||||
generator.writeString(time.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.lang;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierNickname;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static javax.annotation.meta.When.MAYBE;
|
||||
|
||||
/**
|
||||
* This annotation is used to define a method parameter or return type as nullable.
|
||||
*/
|
||||
@Target(value = {METHOD, PARAMETER, FIELD})
|
||||
@Retention(value = RUNTIME)
|
||||
@Documented
|
||||
@Nonnull(when = MAYBE)
|
||||
@TypeQualifierNickname
|
||||
public @interface Nullable {
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Represents an object that can be read as CloudEvent context attributes and extensions.
|
||||
* <p>
|
||||
* An object (in particular, buffered objects) can implement both this interface and {@link CloudEventReader}.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventContextReader {
|
||||
|
||||
/**
|
||||
* Read the context attributes and extensions using the provided writer
|
||||
*
|
||||
* @param writer context writer
|
||||
* @throws CloudEventRWException if something went wrong during the read.
|
||||
*/
|
||||
void readContext(CloudEventContextWriter writer) throws CloudEventRWException;
|
||||
|
||||
}
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import io.cloudevents.types.Time;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.net.URI;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* Interface to write the context attributes/extensions from a {@link io.cloudevents.rw.CloudEventContextReader} to a new representation.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventContextWriter {
|
||||
|
||||
/**
|
||||
* Set attribute with type {@link String}.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this attribute.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*/
|
||||
CloudEventContextWriter withContextAttribute(String name, String value) throws CloudEventRWException;
|
||||
|
||||
/**
|
||||
* Set attribute with type {@link URI}.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this attribute.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*/
|
||||
default CloudEventContextWriter withContextAttribute(String name, URI value) throws CloudEventRWException {
|
||||
return withContextAttribute(name, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute with type {@link OffsetDateTime} attribute.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this attribute.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*/
|
||||
default CloudEventContextWriter withContextAttribute(String name, OffsetDateTime value) throws CloudEventRWException {
|
||||
return withContextAttribute(name, Time.writeTime(name, value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute with type {@link Number}.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this extension.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*
|
||||
* @deprecated CloudEvent specification only permits {@link Integer} type as a
|
||||
* numeric value.
|
||||
*/
|
||||
default CloudEventContextWriter withContextAttribute(String name, Number value) throws CloudEventRWException {
|
||||
return withContextAttribute(name, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute with type {@link Integer}.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this extension.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*/
|
||||
default CloudEventContextWriter withContextAttribute(String name, Integer value) throws CloudEventRWException {
|
||||
return withContextAttribute(name, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute with type {@link Boolean} attribute.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this extension.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*/
|
||||
default CloudEventContextWriter withContextAttribute(String name, Boolean value) throws CloudEventRWException {
|
||||
return withContextAttribute(name, value.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set attribute with a binary type.
|
||||
* This setter should not be invoked for specversion, because the writer should
|
||||
* already know the specversion or because it doesn't need it to correctly write the value.
|
||||
*
|
||||
* @param name name of the attribute
|
||||
* @param value value of the attribute
|
||||
* @return self
|
||||
* @throws CloudEventRWException if anything goes wrong while writing this extension.
|
||||
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
|
||||
*/
|
||||
default CloudEventContextWriter withContextAttribute(String name, byte[] value) throws CloudEventRWException {
|
||||
return withContextAttribute(name, Base64.getEncoder().encodeToString(value));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Interface to convert a {@link CloudEventData} instance to another one.
|
||||
*
|
||||
* @param <R> the returned {@link CloudEventData} from this mapper.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventDataMapper<R extends CloudEventData> {
|
||||
|
||||
/**
|
||||
* Map {@code data} to another {@link CloudEventData} instance.
|
||||
*
|
||||
* @param data the input data
|
||||
* @return The new data
|
||||
* @throws CloudEventRWException is anything goes wrong while mapping the input data
|
||||
*/
|
||||
R map(CloudEventData data) throws CloudEventRWException;
|
||||
|
||||
/**
|
||||
* @return No-op identity mapper which can be used as default when no mapper is provided.
|
||||
*/
|
||||
static CloudEventDataMapper<CloudEventData> identity() {
|
||||
return d -> d;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,230 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import io.cloudevents.lang.Nullable;
|
||||
|
||||
/**
|
||||
* This class is the exception Protocol Binding and Event Format implementers can use to signal errors while serializing/deserializing CloudEvent.
|
||||
*/
|
||||
public class CloudEventRWException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* The kind of error that happened while serializing/deserializing
|
||||
*/
|
||||
public enum CloudEventRWExceptionKind {
|
||||
/**
|
||||
* Spec version string is not recognized by this particular SDK version.
|
||||
*/
|
||||
INVALID_SPEC_VERSION,
|
||||
/**
|
||||
* The attribute name is not a valid/known context attribute.
|
||||
*/
|
||||
INVALID_ATTRIBUTE_NAME,
|
||||
/**
|
||||
* The extension name is not valid because it doesn't follow the naming convention enforced by the CloudEvents spec.
|
||||
*
|
||||
* @see <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#attribute-naming-convention">naming convention</a>
|
||||
*/
|
||||
INVALID_EXTENSION_NAME,
|
||||
/**
|
||||
* The attribute/extension type is not valid.
|
||||
*/
|
||||
INVALID_ATTRIBUTE_TYPE,
|
||||
/**
|
||||
* The attribute/extension value is not valid.
|
||||
*/
|
||||
INVALID_ATTRIBUTE_VALUE,
|
||||
/**
|
||||
* The data type is not valid.
|
||||
*/
|
||||
INVALID_DATA_TYPE,
|
||||
/**
|
||||
* Error while converting CloudEventData.
|
||||
*/
|
||||
DATA_CONVERSION,
|
||||
/**
|
||||
* Invalid content type or spec version
|
||||
*/
|
||||
UNKNOWN_ENCODING,
|
||||
/**
|
||||
* Other error.
|
||||
*/
|
||||
OTHER
|
||||
}
|
||||
|
||||
private final CloudEventRWExceptionKind kind;
|
||||
|
||||
private CloudEventRWException(CloudEventRWExceptionKind kind, Throwable cause) {
|
||||
super(cause);
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
private CloudEventRWException(CloudEventRWExceptionKind kind, String message) {
|
||||
super(message);
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
private CloudEventRWException(CloudEventRWExceptionKind kind, String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
this.kind = kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link CloudEventRWExceptionKind} associated to this exception instance.
|
||||
*/
|
||||
public CloudEventRWExceptionKind getKind() {
|
||||
return kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param specVersion the invalid input spec version
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newInvalidSpecVersion(String specVersion) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_SPEC_VERSION,
|
||||
"Invalid specversion: " + specVersion
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attributeName the invalid attribute name
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newInvalidAttributeName(String attributeName) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_NAME,
|
||||
"Invalid attribute: " + attributeName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param extensionName the invalid extension name
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newInvalidExtensionName(String extensionName) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_EXTENSION_NAME,
|
||||
"Invalid extensions name: " + extensionName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attributeName the invalid attribute name
|
||||
* @param clazz the type of the attribute
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newInvalidAttributeType(String attributeName, Class<?> clazz) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_TYPE,
|
||||
"Invalid attribute/extension type for \"" + attributeName + "\": " + clazz.getCanonicalName()
|
||||
);
|
||||
}
|
||||
|
||||
public static CloudEventRWException newInvalidAttributeType(String attributeName,Object value){
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_TYPE,
|
||||
"Invalid attribute/extension type for \""
|
||||
+ attributeName
|
||||
+ "\": Type" + value.getClass().getCanonicalName()
|
||||
+ ". Value: " + value
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attributeName the invalid attribute name
|
||||
* @param value the value of the attribute
|
||||
* @param cause an optional cause identifying the eventual validation error
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newInvalidAttributeValue(String attributeName, Object value, @Nullable Throwable cause) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_ATTRIBUTE_VALUE,
|
||||
"Invalid attribute/extension value for \"" + attributeName + "\": " + value,
|
||||
cause
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actual the actual data type
|
||||
* @param allowed the list of allowed data types
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newInvalidDataType(String actual, String... allowed) {
|
||||
String message;
|
||||
if (allowed.length == 0) {
|
||||
message = "Invalid data type: " + actual;
|
||||
} else {
|
||||
message = "Invalid data type: " + actual + ". Allowed: " + String.join(", ", allowed);
|
||||
}
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.INVALID_DATA_TYPE,
|
||||
message
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause the cause of the conversion failure
|
||||
* @param from the input data type
|
||||
* @param to the target data type
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newDataConversion(Throwable cause, String from, String to) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.DATA_CONVERSION,
|
||||
"Error while trying to convert data from " + from + " to " + to,
|
||||
cause
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new {@link CloudEventRWException} instance.
|
||||
*/
|
||||
public static CloudEventRWException newUnknownEncodingException() {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.UNKNOWN_ENCODING,
|
||||
"Could not parse. Unknown encoding. Invalid content type or spec version"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* This wraps a {@link Throwable} in a new generic instance of this exception.
|
||||
*
|
||||
* @param cause the cause of the exception
|
||||
* @return a new {@link CloudEventRWException} instance
|
||||
*/
|
||||
public static CloudEventRWException newOther(Throwable cause) {
|
||||
return new CloudEventRWException(
|
||||
CloudEventRWExceptionKind.OTHER,
|
||||
cause
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* An exception for use where none of the other variants are
|
||||
* appropriate.
|
||||
*
|
||||
* @param msg A description error message.
|
||||
* @return a new {@link CloudEventRWException}
|
||||
*/
|
||||
public static CloudEventRWException newOther(String msg){
|
||||
return new CloudEventRWException(CloudEventRWExceptionKind.OTHER, msg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Represents an object that can be read as CloudEvent.
|
||||
* <p>
|
||||
* The read may consume this object, hence it's not safe to invoke it multiple times, unless it's explicitly allowed by the implementer.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface CloudEventReader {
|
||||
|
||||
/**
|
||||
* Like {@link #read(CloudEventWriterFactory, CloudEventDataMapper)}, but with the identity {@link CloudEventDataMapper}.
|
||||
*
|
||||
* @param <W> The type of the {@link CloudEventWriter} created by writerFactory
|
||||
* @param <R> The return value of the {@link CloudEventWriter} created by writerFactory
|
||||
* @param writerFactory a factory that generates a visitor starting from the SpecVersion of the event
|
||||
* @see #read(CloudEventWriterFactory, CloudEventDataMapper)
|
||||
* @return the value returned by {@link CloudEventWriter#end()} or {@link CloudEventWriter#end(CloudEventData)}
|
||||
* @throws CloudEventRWException if something went wrong during the read.
|
||||
*/
|
||||
default <W extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<W, R> writerFactory) throws CloudEventRWException {
|
||||
return read(writerFactory, CloudEventDataMapper.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read self using the provided writer factory.
|
||||
*
|
||||
* @param <W> the {@link CloudEventWriter} type
|
||||
* @param <R> the return type of the {@link CloudEventWriter}
|
||||
* @param writerFactory a factory that generates a visitor starting from the SpecVersion of the event
|
||||
* @param mapper the mapper to invoke when building the {@link CloudEventData}
|
||||
* @return the value returned by {@link CloudEventWriter#end()} or {@link CloudEventWriter#end(CloudEventData)}
|
||||
* @throws CloudEventRWException if something went wrong during the read.
|
||||
*/
|
||||
<W extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<W, R> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException;
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
|
||||
/**
|
||||
* Interface to write the content (CloudEvents attributes, extensions and payload) from a
|
||||
* {@link io.cloudevents.rw.CloudEventReader} to a new representation.
|
||||
*
|
||||
* @param <R> return value at the end of the write process
|
||||
*/
|
||||
public interface CloudEventWriter<R> extends CloudEventContextWriter {
|
||||
|
||||
/**
|
||||
* End the write with a data payload.
|
||||
*
|
||||
* @param data the data to write
|
||||
* @return an eventual return value
|
||||
* @throws CloudEventRWException if the message writer cannot be ended.
|
||||
*/
|
||||
R end(CloudEventData data) throws CloudEventRWException;
|
||||
|
||||
/**
|
||||
* End the write.
|
||||
*
|
||||
* @return an eventual return value
|
||||
* @throws CloudEventRWException if the message writer cannot be ended.
|
||||
*/
|
||||
R end() throws CloudEventRWException;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.rw;
|
||||
|
||||
import io.cloudevents.SpecVersion;
|
||||
|
||||
/**
|
||||
* This factory is used to enforce setting the {@link SpecVersion} as first step in the writing process.
|
||||
*
|
||||
* @param <W> The type of the {@link CloudEventWriter} created by this factory
|
||||
* @param <R> The return value of the {@link CloudEventWriter} created by this factory
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CloudEventWriterFactory<W extends CloudEventWriter<R>, R> {
|
||||
|
||||
/**
|
||||
* Create a {@link CloudEventWriter} starting from the provided {@link SpecVersion}
|
||||
*
|
||||
* @param version the spec version to create the writer
|
||||
* @return the new writer
|
||||
* @throws CloudEventRWException if the spec version is invalid or the writer cannot be instantiated.
|
||||
*/
|
||||
W create(SpecVersion version) throws CloudEventRWException;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.types;
|
||||
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import java.time.DateTimeException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.format.DateTimeParseException;
|
||||
|
||||
import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||
|
||||
/**
|
||||
* Utilities to handle the <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#type-system">CloudEvent Attribute Timestamp type</a>
|
||||
*/
|
||||
public final class Time {
|
||||
|
||||
private Time() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a {@link String} RFC3339 compliant as {@link OffsetDateTime}.
|
||||
*
|
||||
* @param time the value to parse as time
|
||||
* @return the parsed {@link OffsetDateTime}
|
||||
* @throws DateTimeParseException if something went wrong when parsing the provided time.
|
||||
*/
|
||||
public static OffsetDateTime parseTime(String time) throws DateTimeParseException {
|
||||
return OffsetDateTime.parse(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an attribute/extension with RFC3339 compliant {@link String} value as {@link OffsetDateTime}.
|
||||
*
|
||||
* @param attributeName the attribute/extension name
|
||||
* @param time the value to parse as time
|
||||
* @return the parsed {@link OffsetDateTime}
|
||||
* @throws CloudEventRWException if something went wrong when parsing the attribute/extension.
|
||||
*/
|
||||
public static OffsetDateTime parseTime(String attributeName, String time) throws CloudEventRWException {
|
||||
try {
|
||||
return parseTime(time);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw CloudEventRWException.newInvalidAttributeValue(attributeName, time, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link OffsetDateTime} to a RFC3339 compliant {@link String}.
|
||||
*
|
||||
* @param time the time to write as {@link String}
|
||||
* @return the serialized time
|
||||
* @throws DateTimeException if something went wrong when serializing the provided time.
|
||||
*/
|
||||
public static String writeTime(OffsetDateTime time) throws DateTimeException {
|
||||
return ISO_OFFSET_DATE_TIME.format(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an attribute/extension {@link OffsetDateTime} to a RFC3339 compliant {@link String}.
|
||||
*
|
||||
* @param attributeName the attribute/extension name
|
||||
* @param time the time to write as {@link String}
|
||||
* @return the serialized time
|
||||
* @throws CloudEventRWException if something went wrong when serializing the attribute/extension.
|
||||
*/
|
||||
public static String writeTime(String attributeName, OffsetDateTime time) throws DateTimeException {
|
||||
try {
|
||||
return writeTime(time);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw CloudEventRWException.newInvalidAttributeValue(attributeName, time, e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,198 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.extensions.DistributedTracingExtension;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CloudEventBuilderTest {
|
||||
|
||||
@Test
|
||||
public void testBuilderWithData() {
|
||||
|
||||
// given
|
||||
final Map<String, String> keyValueStore = new HashMap<>();
|
||||
keyValueStore.put("key1", "value1");
|
||||
keyValueStore.put("key2", "value2");
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("/trigger");
|
||||
final String type = "My.Cloud.Event.Type";
|
||||
final ZonedDateTime eventTime = ZonedDateTime.now();
|
||||
final String contentType = "application/json";
|
||||
final URI schemaUri = URI.create("http://cloudevents.io/schema");
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.data(keyValueStore)
|
||||
.contentType(contentType)
|
||||
.type(type)
|
||||
.schemaURL(schemaUri)
|
||||
.time(eventTime)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.build();
|
||||
|
||||
// than
|
||||
simpleKeyValueEvent.getData().ifPresent(data -> {
|
||||
assertThat(data).isNotNull();
|
||||
assertThat(data).containsKeys("key1", "key2");
|
||||
assertThat(data).containsValues("value1", "value2");
|
||||
});
|
||||
|
||||
assertThat(simpleKeyValueEvent.getContentType().get()).isEqualTo(contentType);
|
||||
assertThat(simpleKeyValueEvent.getTime().get()).isEqualTo(eventTime);
|
||||
assertThat(simpleKeyValueEvent.getId()).isEqualTo(id);
|
||||
assertThat(simpleKeyValueEvent.getSchemaURL().get()).isEqualTo(schemaUri);
|
||||
assertThat(simpleKeyValueEvent.getType()).isEqualTo(type);
|
||||
assertThat(simpleKeyValueEvent.getSource()).isEqualTo(src);
|
||||
assertThat(simpleKeyValueEvent.getSpecVersion()).isEqualTo(SpecVersion.DEFAULT.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderWithoutData() {
|
||||
|
||||
// given
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("/trigger");
|
||||
final String type = "My.Cloud.Event.Type";
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.type(type)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.build();
|
||||
// than
|
||||
assertThat(simpleKeyValueEvent.getData().isPresent()).isFalse();
|
||||
assertThat(simpleKeyValueEvent.getTime().isPresent()).isFalse();
|
||||
assertThat(simpleKeyValueEvent.getId()).isEqualTo(id);
|
||||
assertThat(simpleKeyValueEvent.getType()).isEqualTo(type);
|
||||
assertThat(simpleKeyValueEvent.getSource()).isEqualTo(src);
|
||||
assertThat(simpleKeyValueEvent.getSpecVersion()).isEqualTo(SpecVersion.DEFAULT.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderWithoutDataAndUrn() {
|
||||
|
||||
// given
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("urn:event:from:myapi/resourse/123");
|
||||
final String type = "some.Cloud.Event.Type";
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.type(type)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.build();
|
||||
// than
|
||||
assertThat(simpleKeyValueEvent.getSource()).isEqualTo(src);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test01BuilderWithoutDataAndUrn() {
|
||||
|
||||
// given
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("urn:event:from:myapi/resourse/123");
|
||||
final String type = "some.Cloud.Event.Type";
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.specVersion("0.1")
|
||||
.type(type)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.build();
|
||||
// than
|
||||
assertThat(simpleKeyValueEvent.getSource()).isEqualTo(src);
|
||||
assertThat(simpleKeyValueEvent.getSpecVersion()).isEqualTo(SpecVersion.V_01.toString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderWithoutDataAndURISchema() {
|
||||
|
||||
// given
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("urn:event:from:myapi/resourse/123");
|
||||
final String type = "some.Cloud.Event.Type";
|
||||
final URI schema = URI.create("urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.type(type)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.schemaURL(schema)
|
||||
.build();
|
||||
// than
|
||||
assertThat(simpleKeyValueEvent.getSchemaURL().get()).isEqualTo(schema);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderWithoutDataAndMailto() {
|
||||
|
||||
// given
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("mailto:cncf-wg-serverless@lists.cncf.io");
|
||||
final String type = "My.Cloud.Event.Type";
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.type(type)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.build();
|
||||
// than
|
||||
assertThat(simpleKeyValueEvent.getSource()).isEqualTo(src);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuilderWithoutDataAndDistributedTracingExtension() {
|
||||
|
||||
// given
|
||||
final String id = UUID.randomUUID().toString();
|
||||
final URI src = URI.create("mailto:cncf-wg-serverless@lists.cncf.io");
|
||||
final String type = "My.Cloud.Event.Type";
|
||||
final DistributedTracingExtension dte = new DistributedTracingExtension();
|
||||
dte.setTraceparent("00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01");
|
||||
dte.setTracestate("congo=BleGNlZWRzIHRohbCBwbGVhc3VyZS4");
|
||||
|
||||
// when
|
||||
final CloudEvent<Map<String, String>> simpleKeyValueEvent = new CloudEventBuilder()
|
||||
.type(type)
|
||||
.id(id)
|
||||
.source(src)
|
||||
.extension(dte)
|
||||
.build();
|
||||
// than
|
||||
assertThat(simpleKeyValueEvent.getSource()).isEqualTo(src);
|
||||
assertThat(simpleKeyValueEvent.getExtensions().get()).contains(dte);
|
||||
|
||||
Extension receivedDte = simpleKeyValueEvent.getExtensions().get().get(0);
|
||||
assertThat(receivedDte).extracting("traceparent", "tracestate")
|
||||
.contains("00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01", "congo=BleGNlZWRzIHRohbCBwbGVhc3VyZS4");
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.util.JacksonMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class CloudEventJacksonTest {
|
||||
|
||||
@Test
|
||||
public void testParseAzure01JSON() {
|
||||
CloudEvent<Map<String, ?>> ce = JacksonMapper.fromInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream("01_azure.json"));
|
||||
assertThat(ce.getSpecVersion()).isEqualTo(SpecVersion.V_01.toString());
|
||||
assertAzureCloudEvent(ce);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAzure02JSON() {
|
||||
CloudEvent<Map<String, ?>> ce = JacksonMapper.fromInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream("02_azure.json"));
|
||||
assertThat(ce.getSpecVersion()).isEqualTo(SpecVersion.V_02.toString());
|
||||
assertAzureCloudEvent(ce);
|
||||
}
|
||||
|
||||
private void assertAzureCloudEvent(CloudEvent<Map<String, ?>> ce) {
|
||||
assertThat(ce.getType()).isEqualTo("Microsoft.Storage.BlobCreated");
|
||||
|
||||
ce.getData().ifPresent(data -> {
|
||||
assertThat(Map.class).isAssignableFrom(data.getClass());
|
||||
assertThat(data.get("clientRequestId")).isEqualTo("a23b4aba-2755-4107-8020-8ba6c54b203d");
|
||||
assertThat(Map.class).isAssignableFrom(data.get("storageDiagnostics").getClass());
|
||||
Map<String, String> storageDiagnostics = (Map<String, String>) data.get("storageDiagnostics");
|
||||
assertThat(storageDiagnostics).containsOnlyKeys("batchId");
|
||||
assertThat(storageDiagnostics.get("batchId")).isEqualTo("ba4fb664-f289-4742-8067-6c859411b066");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAmazon01JSON() {
|
||||
CloudEvent ce = JacksonMapper.fromInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream("01_aws.json"));
|
||||
assertAmazonCloudEvent(ce);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseAmazon02JSON() {
|
||||
CloudEvent ce = JacksonMapper.fromInputStream(Thread.currentThread().getContextClassLoader().getResourceAsStream("02_aws.json"));
|
||||
assertAmazonCloudEvent(ce);
|
||||
}
|
||||
|
||||
private void assertAmazonCloudEvent(CloudEvent ce) {
|
||||
assertThat(ce.getType()).isEqualTo("aws.s3.object.created");
|
||||
assertThat(ce.getId()).isEqualTo("C234-1234-1234");
|
||||
assertThat(ce.getData().isPresent());
|
||||
assertThat(ce.getSource().equals(URI.create("https://serverless.com")));
|
||||
assertThat(ce.getTime().get()).isEqualTo(ZonedDateTime.parse("2018-04-26T14:48:09.769Z", ISO_ZONED_DATE_TIME));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
|
||||
class SpecVersionTest {
|
||||
|
||||
@Test
|
||||
void parse() {
|
||||
assertAll(
|
||||
() -> assertThat(SpecVersion.parse("1.0")).isEqualTo(SpecVersion.V1),
|
||||
() -> assertThat(SpecVersion.parse("0.3")).isEqualTo(SpecVersion.V03),
|
||||
() -> assertThatCode(() -> SpecVersion.parse("9000.1"))
|
||||
.hasMessage(CloudEventRWException.newInvalidSpecVersion("9000.1").getMessage())
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.http;
|
||||
|
||||
import io.cloudevents.SpecVersion;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class HttpTransportAttributesTest {
|
||||
|
||||
@Test
|
||||
public void testVersion01Headers() {
|
||||
|
||||
final HttpTransportAttributes v01 = HttpTransportAttributes.getHttpAttributesForSpec(SpecVersion.V_01);
|
||||
assertThat(v01.specVersionKey()).isEqualTo("ce-cloudEventsVersion");
|
||||
assertThat(v01.timeKey()).isEqualTo("ce-eventTime");
|
||||
assertThat(v01.idKey()).isEqualTo("ce-eventID");
|
||||
assertThat(v01.schemaUrlKey()).isEqualTo("ce-schemaURL");
|
||||
assertThat(v01.typeKey()).isEqualTo("ce-eventType");
|
||||
|
||||
// non-changed between 01 / 02
|
||||
assertThat(v01.sourceKey()).isEqualTo("ce-source");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersion02Headers() {
|
||||
|
||||
final HttpTransportAttributes v02 = HttpTransportAttributes.getHttpAttributesForSpec(SpecVersion.V_02);
|
||||
assertThat(v02.specVersionKey()).isEqualTo("ce-specversion");
|
||||
assertThat(v02.timeKey()).isEqualTo("ce-time");
|
||||
assertThat(v02.idKey()).isEqualTo("ce-id");
|
||||
assertThat(v02.schemaUrlKey()).isEqualTo("ce-schemaurl");
|
||||
assertThat(v02.typeKey()).isEqualTo("ce-type");
|
||||
|
||||
// non-changed between 01 / 02
|
||||
assertThat(v02.sourceKey()).isEqualTo("ce-source");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.cloudevents.types;
|
||||
|
||||
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
|
||||
public class TimeTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("parseDateArguments")
|
||||
void testParseAndFormatDate(String ts) {
|
||||
OffsetDateTime offsetDateTime = Time.parseTime(ts);
|
||||
assertThat(ts).isEqualTo(offsetDateTime.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParseDateOffset() {
|
||||
assertThat(Time.parseTime("1937-01-01T12:20:27.87+00:20"))
|
||||
.isEqualTo("1937-01-01T12:00:27.87Z");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParseTimeException() {
|
||||
assertThatCode(() -> Time.parseTime("time", "01-01T12:20:27.87+00:20"))
|
||||
.isInstanceOf(CloudEventRWException.class)
|
||||
.hasMessage(CloudEventRWException.newInvalidAttributeValue("time", "01-01T12:20:27.87+00:20", null).getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSerializeDateOffset() {
|
||||
assertThat(Time.writeTime(OffsetDateTime.of(
|
||||
LocalDateTime.of(2020, 8, 3, 18, 10, 0, 0),
|
||||
ZoneOffset.ofHours(2)
|
||||
))).isEqualTo("2020-08-03T18:10:00+02:00");
|
||||
}
|
||||
|
||||
public static Stream<Arguments> parseDateArguments() {
|
||||
return Stream.of(
|
||||
Arguments.of("1985-04-12T23:20:50.520Z"),
|
||||
Arguments.of("1990-12-31T23:59Z"),
|
||||
Arguments.of("1990-12-31T15:59-08:00"),
|
||||
Arguments.of("1937-01-01T12:00:27.870+00:20")
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.util;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.impl.DefaultCloudEventImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.time.DateTimeException;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
public final class JacksonMapper {
|
||||
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static final Logger LOGGER = Logger.getLogger(JacksonMapper.class.getName());
|
||||
|
||||
static {
|
||||
MAPPER.registerModule(new Jdk8Module());
|
||||
|
||||
SimpleModule module = new SimpleModule();
|
||||
// custom types
|
||||
module.addDeserializer(ZonedDateTime.class, new TestZonedDateTimeDeserializer());
|
||||
MAPPER.registerModule(module);
|
||||
}
|
||||
|
||||
public static CloudEvent fromInputStream(final InputStream inputStream) {
|
||||
try {
|
||||
return MAPPER.readValue(inputStream, DefaultCloudEventImpl.class);
|
||||
} catch (IOException e) {
|
||||
LOGGER.severe(e.getMessage());
|
||||
throw new IllegalStateException("input was not parseable", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TestZonedDateTimeDeserializer extends StdDeserializer<ZonedDateTime> {
|
||||
|
||||
public TestZonedDateTimeDeserializer() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public TestZonedDateTimeDeserializer(Class<?> vc) {
|
||||
super(vc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ZonedDateTime deserialize(JsonParser jsonparser, DeserializationContext ctxt) throws IOException {
|
||||
// not serializing timezone data yet
|
||||
try {
|
||||
return ZonedDateTime.parse(jsonparser.getText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||
} catch (DateTimeException e) {
|
||||
throw new IllegalArgumentException("could not parse");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
"eventType": "aws.s3.object.created",
|
||||
"eventID": "C234-1234-1234",
|
||||
"eventTime": "2018-04-26T14:48:09.769Z",
|
||||
"eventTypeVersion": "2.0",
|
||||
"source": "https://serverless.com",
|
||||
"extensions": {},
|
||||
"contentType": "application/json",
|
||||
"cloudEventsVersion": "0.1",
|
||||
"data":
|
||||
{ "s3SchemaVersion": "1.0",
|
||||
"configurationId": "cd267a38-30df-400e-9e3d-d0f1ca6e2410",
|
||||
"bucket":
|
||||
{ "name": "cloudevents",
|
||||
"ownerIdentity": {},
|
||||
"arn": "arn:aws:s3:::cloudevents" },
|
||||
"object":
|
||||
{ "key": "dan_kohn.jpg",
|
||||
"size": 444684,
|
||||
"eTag": "38b01ff16138d7ca0a0eb3f7a88ff815",
|
||||
"sequencer": "005AE1E6A9A3D61490"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"eventID": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
|
||||
"eventTime": "2018-04-23T12:28:22.4579346Z",
|
||||
"eventType": "Microsoft.Storage.BlobCreated",
|
||||
"cloudEventsVersion": "0.1",
|
||||
"data": {
|
||||
"api": "PutBlockList",
|
||||
"clientRequestId": "a23b4aba-2755-4107-8020-8ba6c54b203d",
|
||||
"requestId": "96fb5f0b-001e-0108-6dfe-da6e28000000",
|
||||
"eTag": "0x8D5A915B425AFFD",
|
||||
"contentType": "image/jpeg",
|
||||
"contentLength": 2779325,
|
||||
"blobType": "BlockBlob",
|
||||
"url": "https://cvtest34.blob.core.windows.net/myfiles/IMG_20180224_0004.jpg",
|
||||
"sequencer": "000000000000000000000000000000BA00000000003db46c",
|
||||
"storageDiagnostics": {
|
||||
"batchId": "ba4fb664-f289-4742-8067-6c859411b066"
|
||||
}
|
||||
},
|
||||
"source": "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/cvtest34/providers/Microsoft.Storage/storageAccounts/cvtest34#/blobServices/default/containers/myfiles/blobs/IMG_20180224_0004.jpg"
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"type": "aws.s3.object.created",
|
||||
"id": "C234-1234-1234",
|
||||
"time": "2018-04-26T14:48:09.769Z",
|
||||
"source": "https://serverless.com",
|
||||
"contentType": "application/json",
|
||||
"specversion": "0.2",
|
||||
"data":
|
||||
{ "s3SchemaVersion": "1.0",
|
||||
"configurationId": "cd267a38-30df-400e-9e3d-d0f1ca6e2410",
|
||||
"bucket":
|
||||
{ "name": "cloudevents",
|
||||
"ownerIdentity": {},
|
||||
"arn": "arn:aws:s3:::cloudevents" },
|
||||
"object":
|
||||
{ "key": "dan_kohn.jpg",
|
||||
"size": 444684,
|
||||
"eTag": "38b01ff16138d7ca0a0eb3f7a88ff815",
|
||||
"sequencer": "005AE1E6A9A3D61490"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"id": "96fb5f0b-001e-0108-6dfe-da6e2806f124",
|
||||
"time": "2018-04-23T12:28:22.4579346Z",
|
||||
"type": "Microsoft.Storage.BlobCreated",
|
||||
"specversion": "0.2",
|
||||
"data": {
|
||||
"api": "PutBlockList",
|
||||
"clientRequestId": "a23b4aba-2755-4107-8020-8ba6c54b203d",
|
||||
"requestId": "96fb5f0b-001e-0108-6dfe-da6e28000000",
|
||||
"eTag": "0x8D5A915B425AFFD",
|
||||
"contentType": "image/jpeg",
|
||||
"contentLength": 2779325,
|
||||
"blobType": "BlockBlob",
|
||||
"url": "https://cvtest34.blob.core.windows.net/myfiles/IMG_20180224_0004.jpg",
|
||||
"sequencer": "000000000000000000000000000000BA00000000003db46c",
|
||||
"storageDiagnostics": {
|
||||
"batchId": "ba4fb664-f289-4742-8067-6c859411b066"
|
||||
}
|
||||
},
|
||||
"source": "/subscriptions/326100e2-f69d-4268-8503-075374f62b6e/resourceGroups/cvtest34/providers/Microsoft.Storage/storageAccounts/cvtest34#/blobServices/default/containers/myfiles/blobs/IMG_20180224_0004.jpg"
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<!--
|
||||
~ Copyright 2018-Present The CloudEvents Authors
|
||||
~ <p>
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~ <p>
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ <p>
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-parent</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloudevents-benchmarks</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>CloudEvents - Benchmarks</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<jmh.version>1.23</jmh.version>
|
||||
<javac.target>1.8</javac.target>
|
||||
<!-- Name of the benchmark Uber-JAR to generate. -->
|
||||
<uberjar.name>benchmarks</uberjar.name>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>test-jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-json-jackson</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-kafka</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-sql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<compilerVersion>${javac.target}</compilerVersion>
|
||||
<source>${javac.target}</source>
|
||||
<target>${javac.target}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<finalName>${uberjar.name}</finalName>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>org.openjdk.jmh.Main</mainClass>
|
||||
</transformer>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
|
||||
</transformers>
|
||||
<filters>
|
||||
<filter>
|
||||
<!--
|
||||
Shading signed JARs will fail without this.
|
||||
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
|
||||
-->
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-clean-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>2.8.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>2.4</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.9.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.6</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.17</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.bench.jackson;
|
||||
|
||||
import io.cloudevents.jackson.JsonFormat;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_XML_DATA;
|
||||
|
||||
public class JsonFormatDeserializationBenchmark {
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class DeserializationState {
|
||||
|
||||
public byte[] eventWithJson;
|
||||
public byte[] eventWithXml;
|
||||
public JsonFormat format = new JsonFormat();
|
||||
|
||||
public DeserializationState() {
|
||||
eventWithJson = format.serialize(V1_WITH_JSON_DATA_WITH_EXT);
|
||||
eventWithXml = format.serialize(V1_WITH_XML_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void deserializeWithJsonData(DeserializationState state, Blackhole bh) {
|
||||
bh.consume(
|
||||
state.format.deserialize(state.eventWithJson)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void deserializeWithXmlData(DeserializationState state, Blackhole bh) {
|
||||
bh.consume(
|
||||
state.format.deserialize(state.eventWithXml)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.bench.jackson;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.core.builder.CloudEventBuilder;
|
||||
import io.cloudevents.jackson.JsonFormat;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_XML_DATA;
|
||||
|
||||
public class JsonFormatSerializationBenchmark {
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class SerializationState {
|
||||
public CloudEvent eventWithJson = CloudEventBuilder.v1(V1_WITH_JSON_DATA_WITH_EXT).build();
|
||||
public CloudEvent eventWithXml = CloudEventBuilder.v1(V1_WITH_XML_DATA).build();
|
||||
public JsonFormat format = new JsonFormat();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void serializeWithJsonData(SerializationState state, Blackhole bh) {
|
||||
bh.consume(
|
||||
state.format.serialize(state.eventWithJson)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void serializeWithXmlData(SerializationState state, Blackhole bh) {
|
||||
bh.consume(
|
||||
state.format.serialize(state.eventWithXml)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.bench.kafka;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.core.builder.CloudEventBuilder;
|
||||
import io.cloudevents.jackson.JsonFormat;
|
||||
import io.cloudevents.kafka.KafkaMessageFactory;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
|
||||
|
||||
|
||||
public class CloudEventToKafkaProducerMessageBenchmark {
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class Event {
|
||||
public CloudEvent event = CloudEventBuilder.v1(V1_WITH_JSON_DATA_WITH_EXT).build();
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void testBinaryEncoding(Event event, Blackhole bh) {
|
||||
bh.consume(
|
||||
KafkaMessageFactory
|
||||
.createWriter("aaa")
|
||||
.writeBinary(event.event)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void testStructuredJsonEncoding(Event event, Blackhole bh) {
|
||||
bh.consume(
|
||||
KafkaMessageFactory
|
||||
.createWriter("aaa")
|
||||
.writeStructured(event.event, JsonFormat.CONTENT_TYPE)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.bench.kafka;
|
||||
|
||||
import io.cloudevents.jackson.JsonFormat;
|
||||
import io.cloudevents.kafka.KafkaMessageFactory;
|
||||
import org.apache.kafka.clients.consumer.ConsumerRecord;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.common.record.TimestampType;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
|
||||
|
||||
public class KafkaConsumerMessageToCloudEventBenchmark {
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class BinaryMessage {
|
||||
public ConsumerRecord<String, byte[]> message;
|
||||
|
||||
public BinaryMessage() {
|
||||
// Hack to generate a consumer message
|
||||
ProducerRecord<Void, byte[]> inRecord = KafkaMessageFactory
|
||||
.createWriter("aaa")
|
||||
.writeBinary(V1_WITH_JSON_DATA_WITH_EXT);
|
||||
|
||||
this.message = new ConsumerRecord<>(
|
||||
"aaa",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
TimestampType.NO_TIMESTAMP_TYPE,
|
||||
-1L,
|
||||
ConsumerRecord.NULL_SIZE,
|
||||
ConsumerRecord.NULL_SIZE,
|
||||
"aaa",
|
||||
inRecord.value(),
|
||||
inRecord.headers()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void testBinaryEncoding(BinaryMessage binaryMessage, Blackhole bh) {
|
||||
bh.consume(
|
||||
KafkaMessageFactory
|
||||
.createReader(binaryMessage.message)
|
||||
.toEvent()
|
||||
);
|
||||
}
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class StructuredJsonMessage {
|
||||
public ConsumerRecord<String, byte[]> message;
|
||||
|
||||
public StructuredJsonMessage() {
|
||||
// Hack to generate a consumer message
|
||||
ProducerRecord<Void, byte[]> inRecord = KafkaMessageFactory
|
||||
.createWriter("aaa")
|
||||
.writeStructured(V1_WITH_JSON_DATA_WITH_EXT, JsonFormat.CONTENT_TYPE);
|
||||
|
||||
this.message = new ConsumerRecord<>(
|
||||
"aaa",
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
TimestampType.NO_TIMESTAMP_TYPE,
|
||||
-1L,
|
||||
ConsumerRecord.NULL_SIZE,
|
||||
ConsumerRecord.NULL_SIZE,
|
||||
"aaa",
|
||||
inRecord.value(),
|
||||
inRecord.headers()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.Throughput)
|
||||
public void testStructuredJsonEncoding(StructuredJsonMessage structuredJsonMessage, Blackhole bh) {
|
||||
bh.consume(
|
||||
KafkaMessageFactory
|
||||
.createReader(structuredJsonMessage.message)
|
||||
.toEvent()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package io.cloudevents.bench.sql;
|
||||
|
||||
import io.cloudevents.sql.Parser;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
public class CompileBenchmark {
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testCompileSmallExpression(Blackhole bh) {
|
||||
bh.consume(
|
||||
Parser.parseDefault("(a + b + c) = 10 AND TRUE OR CONCAT('1', '2', id) = '123'")
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testCompileSmallTrueConstantExpression(Blackhole bh) {
|
||||
bh.consume(
|
||||
Parser.parseDefault("(1 + 2 + 3) = 10 AND TRUE OR CONCAT('1', '2', '3') = 123")
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testCompileSmallFalseConstantExpression(Blackhole bh) {
|
||||
bh.consume(
|
||||
Parser.parseDefault("(1 + 2 + 3) = 10 AND FALSE OR CONCAT('1', '2', '3') = 124")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package io.cloudevents.bench.sql;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.core.builder.CloudEventBuilder;
|
||||
import io.cloudevents.sql.Expression;
|
||||
import io.cloudevents.sql.Parser;
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import org.openjdk.jmh.infra.Blackhole;
|
||||
|
||||
import static io.cloudevents.core.test.Data.V1_WITH_JSON_DATA_WITH_EXT;
|
||||
|
||||
public class RunBenchmark {
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class TestCaseSmallExpression {
|
||||
public CloudEvent event = CloudEventBuilder
|
||||
.v1(V1_WITH_JSON_DATA_WITH_EXT)
|
||||
.withExtension("a", "10")
|
||||
.withExtension("b", 3)
|
||||
.withExtension("c", "-3")
|
||||
.build();
|
||||
public Expression expression = Parser
|
||||
.parseDefault("(a + b + c) = 10 AND TRUE OR CONCAT('1', '2', id) = '123'");
|
||||
}
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class TestCaseSmallTrueConstantExpression {
|
||||
public CloudEvent event = CloudEventBuilder
|
||||
.v1(V1_WITH_JSON_DATA_WITH_EXT)
|
||||
.build();
|
||||
public Expression expression = Parser
|
||||
.parseDefault("(1 + 2 + 3) = 10 AND TRUE OR CONCAT('1', '2', '3') = 123");
|
||||
}
|
||||
|
||||
@State(Scope.Thread)
|
||||
public static class TestCaseSmallFalseConstantExpression {
|
||||
public CloudEvent event = CloudEventBuilder
|
||||
.v1(V1_WITH_JSON_DATA_WITH_EXT)
|
||||
.build();
|
||||
public Expression expression = Parser
|
||||
.parseDefault("(1 + 2 + 3) = 10 AND FALSE OR CONCAT('1', '2', '3') = 124");
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testEvaluateSmallExpression(TestCaseSmallExpression testCase, Blackhole bh) {
|
||||
bh.consume(
|
||||
testCase.expression.evaluate(testCase.event)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testTryEvaluateSmallExpression(TestCaseSmallExpression testCase, Blackhole bh) {
|
||||
bh.consume(
|
||||
testCase.expression.tryEvaluate(testCase.event)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testEvaluateSmallTrueConstantExpression(TestCaseSmallTrueConstantExpression testCase, Blackhole bh) {
|
||||
bh.consume(
|
||||
testCase.expression.evaluate(testCase.event)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testTryEvaluateSmallTrueConstantExpression(TestCaseSmallTrueConstantExpression testCase, Blackhole bh) {
|
||||
bh.consume(
|
||||
testCase.expression.tryEvaluate(testCase.event)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testEvaluateSmallFalseConstantExpression(TestCaseSmallFalseConstantExpression testCase, Blackhole bh) {
|
||||
bh.consume(
|
||||
testCase.expression.evaluate(testCase.event)
|
||||
);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode({Mode.Throughput, Mode.AverageTime})
|
||||
public void testTryEvaluateSmallFalseConstantExpression(TestCaseSmallFalseConstantExpression testCase, Blackhole bh) {
|
||||
bh.consume(
|
||||
testCase.expression.tryEvaluate(testCase.event)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2018-Present The CloudEvents Authors
|
||||
~ <p>
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~ <p>
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ <p>
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-parent</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloudevents-bom</artifactId>
|
||||
<name>CloudEvents - Bill of Materials</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-json-jackson</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-protobuf</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-amqp-proton</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-http-basic</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-http-vertx</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-http-restful-ws</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-kafka</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-spring</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-sql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
|
@ -1,54 +0,0 @@
|
|||
# CDI Integration
|
||||
|
||||
## Firing CloudEvents using CDI
|
||||
|
||||
In _Enterprise Java_ applications, implemented with Jakarta EE or the Eclipse Microprofile, it's trivial to combine this CloudEvents API with CDI. Application developers can now fire a CloudEvent for further processing inside of the application:
|
||||
|
||||
```java
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventBuilder;
|
||||
import io.cloudevents.cdi.EventTypeQualifier;
|
||||
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Router {
|
||||
|
||||
@Inject
|
||||
private Event<CloudEvent<MyCustomEvent>> cloudEvent;
|
||||
|
||||
public void routeMe() throws Exception {
|
||||
|
||||
final CloudEvent<MyCustomEvent> event = new CloudEventBuilder<MyCustomEvent>()
|
||||
.type("Cloud.Storage.Item.Created")
|
||||
.source(new URI("/trigger"))
|
||||
.id(UUID.randomUUID().toString())
|
||||
.data(new MyCustomEvent(...))
|
||||
.build();
|
||||
|
||||
cloudEvent.select(
|
||||
new EventTypeQualifier("Cloud.Storage.Item.Created"))
|
||||
.fire(event);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The method above creates a CloudEvent object, and uses the _injected_ CDI `Event` implementation,
|
||||
where a `select()` is performed to fire a _qualified_ event, for all interested parties.
|
||||
|
||||
## Receiving CloudEvents with CDI
|
||||
|
||||
If other parts of the application are interested in the `Cloud.Storage.Item.Created` event,
|
||||
it needs a matching `@Observes` annotation:
|
||||
|
||||
```java
|
||||
public void receiveCloudEvent(
|
||||
@Observes @EventType(name = "My.Cloud.Event.Type") CloudEvent cloudEvent) {
|
||||
// handle the event
|
||||
}
|
||||
```
|
||||
|
||||
The application now is able to work with the _observed_ CloudEvent object.
|
103
cdi/pom.xml
103
cdi/pom.xml
|
@ -1,103 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2018 The CloudEvents Authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-parent</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>cdi</artifactId>
|
||||
<name>CloudEvents - CDI</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian</groupId>
|
||||
<artifactId>arquillian-bom</artifactId>
|
||||
<version>1.1.11.Final</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- Java EE 7 dependency -->
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>7.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>2.19.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian.junit</groupId>
|
||||
<artifactId>arquillian-junit-container</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.arquillian.container</groupId>
|
||||
<artifactId>arquillian-weld-ee-embedded-1.1</artifactId>
|
||||
<version>1.0.0.Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jboss.weld</groupId>
|
||||
<artifactId>weld-core</artifactId>
|
||||
<version>2.3.5.Final</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.6.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.impl.DefaultCloudEventImpl;
|
||||
import org.jboss.shrinkwrap.api.ShrinkWrap;
|
||||
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
|
||||
public abstract class AbstractTestBase {
|
||||
|
||||
public static JavaArchive createFrameworkDeployment() {
|
||||
|
||||
return ShrinkWrap.create(JavaArchive.class)
|
||||
.addPackage(DefaultCloudEventImpl.class.getPackage())
|
||||
.addPackage(MockProvider.class.getPackage())
|
||||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
|
||||
}
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.beans.Receiver;
|
||||
import io.cloudevents.beans.Router;
|
||||
import org.jboss.arquillian.container.test.api.Deployment;
|
||||
import org.jboss.arquillian.junit.Arquillian;
|
||||
import org.jboss.shrinkwrap.api.spec.JavaArchive;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
@RunWith(Arquillian.class)
|
||||
public class CloudEventTest extends AbstractTestBase {
|
||||
|
||||
|
||||
@Inject
|
||||
private Router router;
|
||||
|
||||
@Deployment
|
||||
public static JavaArchive createDeployment() {
|
||||
return AbstractTestBase.createFrameworkDeployment()
|
||||
.addPackage(Router.class.getPackage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatch(final Receiver receiver) throws Exception {
|
||||
router.routeMe();
|
||||
Mockito.verify(receiver, Mockito.times(1)).ack();
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package io.cloudevents.beans;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventBuilder;
|
||||
import io.cloudevents.cdi.EventTypeQualifier;
|
||||
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Router {
|
||||
|
||||
@Inject
|
||||
private Event<CloudEvent<MyCustomEvent>> cloudEvent;
|
||||
|
||||
public void routeMe() throws Exception {
|
||||
|
||||
CloudEvent<MyCustomEvent> event = new CloudEventBuilder<MyCustomEvent>()
|
||||
.type("Cloud.Storage.Item.Created")
|
||||
.source(new URI("/trigger"))
|
||||
.id(UUID.randomUUID().toString())
|
||||
.build();
|
||||
|
||||
cloudEvent.select(
|
||||
new EventTypeQualifier("Cloud.Storage.Item.Created"))
|
||||
.fire(event);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
# CloudEvents Core
|
||||
|
||||
Javadoc: [](http://www.javadoc.io/doc/io.cloudevents/cloudevents-core)
|
||||
|
||||
Documentation: https://cloudevents.github.io/sdk-java/core
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright 2018-Present The CloudEvents Authors
|
||||
~ <p>
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~ <p>
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~ <p>
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
~
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-parent</artifactId>
|
||||
<version>4.1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>cloudevents-core</artifactId>
|
||||
<name>CloudEvents - Core</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<module-name>io.cloudevents.core</module-name>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.cloudevents</groupId>
|
||||
<artifactId>cloudevents-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.findbugs</groupId>
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>3.0.2</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- Test deps -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>test-jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventContext;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.core.builder.CloudEventBuilder;
|
||||
import io.cloudevents.core.impl.CloudEventContextReaderAdapter;
|
||||
import io.cloudevents.core.impl.CloudEventReaderAdapter;
|
||||
import io.cloudevents.lang.Nullable;
|
||||
import io.cloudevents.rw.CloudEventContextReader;
|
||||
import io.cloudevents.rw.CloudEventDataMapper;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
import io.cloudevents.rw.CloudEventReader;
|
||||
|
||||
/**
|
||||
* This class contains a set of utility methods to deal with conversions of {@link io.cloudevents} related interfaces
|
||||
*/
|
||||
public final class CloudEventUtils {
|
||||
|
||||
private CloudEventUtils() {}
|
||||
|
||||
/**
|
||||
* Convert a {@link CloudEvent} to a {@link CloudEventReader}. This method provides a default implementation
|
||||
* for CloudEvent that doesn't implement {@link CloudEventReader}.
|
||||
* <p>
|
||||
* It's safe to use the returned {@link CloudEventReader} multiple times.
|
||||
*
|
||||
* @param event the event to convert
|
||||
* @return the reader implementation
|
||||
*/
|
||||
public static CloudEventReader toReader(CloudEvent event) {
|
||||
if (event instanceof CloudEventReader) {
|
||||
return (CloudEventReader) event;
|
||||
} else {
|
||||
return new CloudEventReaderAdapter(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link CloudEvent} to a {@link CloudEventContextReader}. This method provides a default implementation
|
||||
* for {@link CloudEvent} that doesn't implement {@link CloudEventContextReader}.
|
||||
* <p>
|
||||
* It's safe to use the returned {@link CloudEventReader} multiple times.
|
||||
*
|
||||
* @param event the event to convert
|
||||
* @return the context reader implementation
|
||||
*/
|
||||
public static CloudEventContextReader toContextReader(CloudEventContext event) {
|
||||
if (event instanceof CloudEventContextReader) {
|
||||
return (CloudEventContextReader) event;
|
||||
} else {
|
||||
return new CloudEventContextReaderAdapter(event);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link CloudEventReader} to a {@link CloudEvent}.
|
||||
*
|
||||
* @param reader the reader where to read the message from
|
||||
* @return the reader implementation
|
||||
*/
|
||||
public static CloudEvent toEvent(CloudEventReader reader) throws CloudEventRWException {
|
||||
return toEvent(reader, CloudEventDataMapper.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a {@link CloudEventReader} to a {@link CloudEvent} mapping the data with the provided {@code mapper}.
|
||||
*
|
||||
* @param reader the reader where to read the message from
|
||||
* @param mapper the mapper to use when reading the data
|
||||
* @return the reader implementation
|
||||
*/
|
||||
public static CloudEvent toEvent(CloudEventReader reader, CloudEventDataMapper<?> mapper) throws CloudEventRWException {
|
||||
return reader.read(CloudEventBuilder::fromSpecVersion, mapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data contained in {@code event} and map it using the provided mapper.
|
||||
*
|
||||
* @param event the event eventually containing the data
|
||||
* @param mapper the mapper to use to map the data
|
||||
* @param <R> the returned {@link CloudEventData} implementation from the provided mapper
|
||||
* @return the data contained in {@code event} and mapped with {@code mapper}, if any, otherwise null
|
||||
*/
|
||||
@Nullable
|
||||
public static <R extends CloudEventData> R mapData(CloudEvent event, CloudEventDataMapper<R> mapper) {
|
||||
CloudEventData data = event.getData();
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return mapper.map(data);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,343 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.builder;
|
||||
|
||||
import io.cloudevents.*;
|
||||
import io.cloudevents.rw.CloudEventWriter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.ParametersAreNullableByDefault;
|
||||
import java.net.URI;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
/**
|
||||
* Builder interface to build a {@link CloudEvent}.
|
||||
*/
|
||||
@ParametersAreNullableByDefault
|
||||
public interface CloudEventBuilder extends CloudEventWriter<CloudEvent> {
|
||||
|
||||
/**
|
||||
* Set the {@code id} of the event
|
||||
*
|
||||
* @param id id of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withId(String id);
|
||||
|
||||
/**
|
||||
* Set the {@code source} of the event
|
||||
*
|
||||
* @param source source of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withSource(URI source);
|
||||
|
||||
/**
|
||||
* Set the {@code type} of the event
|
||||
*
|
||||
* @param type type of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withType(String type);
|
||||
|
||||
/**
|
||||
* Set the {@code dataschema} of the event. For CloudEvent v0.3, this will configure the {@code schemaurl} attribute.
|
||||
*
|
||||
* @param dataSchema dataschema of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withDataSchema(URI dataSchema);
|
||||
|
||||
/**
|
||||
* Set the {@code datacontenttype} of the event
|
||||
*
|
||||
* @param dataContentType datacontenttype of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withDataContentType(String dataContentType);
|
||||
|
||||
/**
|
||||
* Set the {@code subject} of the event
|
||||
*
|
||||
* @param subject subject of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withSubject(String subject);
|
||||
|
||||
/**
|
||||
* Set the {@code time} of the event
|
||||
*
|
||||
* @param time time of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withTime(OffsetDateTime time);
|
||||
|
||||
/**
|
||||
* Set the {@code data} of the event
|
||||
*
|
||||
* @param data data of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withData(byte[] data);
|
||||
|
||||
/**
|
||||
* Set the {@code datacontenttype} and {@code data} of the event
|
||||
*
|
||||
* @param dataContentType datacontenttype of the event
|
||||
* @param data data of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withData(String dataContentType, byte[] data);
|
||||
|
||||
/**
|
||||
* Set the {@code datacontenttype}, {@code dataschema} and {@code data} of the event
|
||||
*
|
||||
* @param dataContentType datacontenttype of the event
|
||||
* @param dataSchema dataschema of the event
|
||||
* @param data data of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withData(String dataContentType, URI dataSchema, byte[] data);
|
||||
|
||||
/**
|
||||
* Set the {@code data} of the event
|
||||
*
|
||||
* @param data data of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withData(CloudEventData data);
|
||||
|
||||
/**
|
||||
* Set the {@code datacontenttype} and {@code data} of the event
|
||||
*
|
||||
* @param dataContentType datacontenttype of the event
|
||||
* @param data data of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withData(String dataContentType, CloudEventData data);
|
||||
|
||||
/**
|
||||
* Set the {@code datacontenttype}, {@code dataschema} and {@code data} of the event
|
||||
*
|
||||
* @param dataContentType datacontenttype of the event
|
||||
* @param dataSchema dataschema of the event
|
||||
* @param data data of the event
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withData(String dataContentType, URI dataSchema, CloudEventData data);
|
||||
|
||||
/**
|
||||
* Remove the {@code datacontenttype}, {@code dataschema} and {@code data} from the event
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withoutData();
|
||||
|
||||
/**
|
||||
* Remove the {@code dataschema} from the event
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withoutDataSchema();
|
||||
|
||||
|
||||
/**
|
||||
* Remove the {@code datacontenttype} from the event
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withoutDataContentType();
|
||||
|
||||
/**
|
||||
* Set an extension with provided key and string value
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @param value value of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull String key, @Nonnull String value);
|
||||
|
||||
/**
|
||||
* Set an extension with provided key and numeric value
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @param value value of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull String key, @Nonnull Number value);
|
||||
|
||||
/**
|
||||
* Set an extension with provided key and boolean value
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @param value value of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull String key, @Nonnull Boolean value);
|
||||
|
||||
/**
|
||||
* Set an extension with provided key and uri value
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @param value value of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull String key, @Nonnull URI value);
|
||||
|
||||
/**
|
||||
* Set an extension with provided key and boolean value
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @param value value of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull String key, @Nonnull OffsetDateTime value);
|
||||
|
||||
/**
|
||||
* Set an extension with provided key and binary value
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @param value value of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull String key, @Nonnull byte[] value);
|
||||
|
||||
/**
|
||||
* Add to the builder all the extension key/values of the provided extension
|
||||
*
|
||||
* @param extension materialized extension to set in the builder
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withExtension(@Nonnull CloudEventExtension extension);
|
||||
|
||||
/**
|
||||
* Remove from the the builder the provided extension key, if any
|
||||
*
|
||||
* @param key key of the extension attribute
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withoutExtension(@Nonnull String key);
|
||||
|
||||
/**
|
||||
* Remove from the the builder the provided extension, if any
|
||||
*
|
||||
* @param extension materialized extension to remove from the builder
|
||||
* @return self
|
||||
*/
|
||||
CloudEventBuilder withoutExtension(@Nonnull CloudEventExtension extension);
|
||||
|
||||
/**
|
||||
* Build the event
|
||||
*
|
||||
* @return the built event
|
||||
* @throws IllegalStateException if a required attribute is not configured
|
||||
*/
|
||||
CloudEvent build() throws IllegalStateException;
|
||||
|
||||
/**
|
||||
* Copy this builder, creating a new instance with same values.
|
||||
*
|
||||
* @return A new builder with same values of this instance
|
||||
*/
|
||||
CloudEventBuilder newBuilder();
|
||||
|
||||
/**
|
||||
* @return a new CloudEvent v1 builder
|
||||
*/
|
||||
static io.cloudevents.core.v1.CloudEventBuilder v1() {
|
||||
return new io.cloudevents.core.v1.CloudEventBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event event to bootstrap the builder
|
||||
* @return a new CloudEvent v1 builder filled with content of {@code event}
|
||||
*/
|
||||
static io.cloudevents.core.v1.CloudEventBuilder v1(@Nonnull CloudEvent event) {
|
||||
return new io.cloudevents.core.v1.CloudEventBuilder(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new CloudEvent v0.3 builder
|
||||
*/
|
||||
static io.cloudevents.core.v03.CloudEventBuilder v03() {
|
||||
return new io.cloudevents.core.v03.CloudEventBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event event to bootstrap the builder
|
||||
* @return a new CloudEvent v0.3 builder filled with content of {@code event}
|
||||
*/
|
||||
static io.cloudevents.core.v03.CloudEventBuilder v03(@Nonnull CloudEvent event) {
|
||||
return new io.cloudevents.core.v03.CloudEventBuilder(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder for the specified {@link SpecVersion}
|
||||
*
|
||||
* @param version version to use for the new builder
|
||||
* @return a new builder
|
||||
*/
|
||||
static CloudEventBuilder fromSpecVersion(@Nonnull SpecVersion version) {
|
||||
switch (version) {
|
||||
case V1:
|
||||
return CloudEventBuilder.v1();
|
||||
case V03:
|
||||
return CloudEventBuilder.v03();
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"The provided spec version doesn't exist. Please make sure your io.cloudevents deps versions are aligned."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder starting from the values of the provided event.
|
||||
*
|
||||
* @param event event to copy values from
|
||||
* @return the new builder
|
||||
*/
|
||||
static CloudEventBuilder from(@Nonnull CloudEvent event) {
|
||||
switch (event.getSpecVersion()) {
|
||||
case V1:
|
||||
return CloudEventBuilder.v1(event);
|
||||
case V03:
|
||||
return CloudEventBuilder.v03(event);
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"The provided spec version doesn't exist. Please make sure your io.cloudevents deps versions are aligned."
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder starting from the values of the provided context.
|
||||
*
|
||||
* @param context context to copy values from
|
||||
* @return the new builder
|
||||
*/
|
||||
static CloudEventBuilder fromContext(@Nonnull CloudEventContext context) {
|
||||
switch (context.getSpecVersion()) {
|
||||
case V1:
|
||||
return new io.cloudevents.core.v1.CloudEventBuilder(context);
|
||||
case V03:
|
||||
return new io.cloudevents.core.v03.CloudEventBuilder(context);
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"The provided spec version doesn't exist. Please make sure your io.cloudevents deps versions are aligned."
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package io.cloudevents.core.data;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* An implementation of {@link CloudEventData} that wraps a byte array.
|
||||
*/
|
||||
public class BytesCloudEventData implements CloudEventData {
|
||||
|
||||
private final byte[] value;
|
||||
|
||||
/**
|
||||
* @param value the bytes to wrap
|
||||
* @deprecated use {@link BytesCloudEventData#wrap(byte[])}
|
||||
*/
|
||||
public BytesCloudEventData(byte[] value) {
|
||||
Objects.requireNonNull(value);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toBytes() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
BytesCloudEventData that = (BytesCloudEventData) o;
|
||||
return Arrays.equals(value, that.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Arrays.hashCode(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BytesCloudEventData{" +
|
||||
"value=" + Arrays.toString(value) +
|
||||
'}';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value byte array to wrap
|
||||
* @return byte array wrapped in a {@link BytesCloudEventData}, which implements {@link CloudEventData}.
|
||||
*/
|
||||
public static BytesCloudEventData wrap(byte[] value) {
|
||||
return new BytesCloudEventData(value);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package io.cloudevents.core.data;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* An implementation of {@link CloudEventData} that wraps any POJO.
|
||||
*
|
||||
* @param <T> the type of the wrapped POJO.
|
||||
*/
|
||||
public class PojoCloudEventData<T> implements CloudEventData {
|
||||
|
||||
/**
|
||||
* Interface defining a conversion from T to byte array. This is similar to {@link java.util.function.Function}
|
||||
* but it allows checked exceptions.
|
||||
*
|
||||
* @param <T> the source type of the conversion
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ToBytes<T> {
|
||||
/**
|
||||
* @param data the POJO to convert
|
||||
* @return the serialized byte array.
|
||||
* @throws Exception when something goes wrong during the conversion.
|
||||
*/
|
||||
byte[] convert(T data) throws Exception;
|
||||
}
|
||||
|
||||
private final T value;
|
||||
private byte[] memoizedValue;
|
||||
private final ToBytes<T> mapper;
|
||||
|
||||
private PojoCloudEventData(T value, ToBytes<T> mapper) {
|
||||
this(value, null, mapper);
|
||||
}
|
||||
|
||||
private PojoCloudEventData(T value, byte[] memoizedValue, ToBytes<T> mapper) {
|
||||
Objects.requireNonNull(value);
|
||||
if (memoizedValue == null && mapper == null) {
|
||||
throw new NullPointerException("You must provide the serialized data value or a mapper");
|
||||
}
|
||||
this.value = value;
|
||||
this.memoizedValue = memoizedValue;
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the wrapped POJO
|
||||
*/
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toBytes() {
|
||||
if (this.memoizedValue == null) {
|
||||
try {
|
||||
this.memoizedValue = mapper.convert(this.value);
|
||||
} catch (Exception e) {
|
||||
throw CloudEventRWException.newDataConversion(e, value.getClass().toString(), "byte[]");
|
||||
}
|
||||
}
|
||||
return this.memoizedValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
PojoCloudEventData<?> that = (PojoCloudEventData<?>) o;
|
||||
return Objects.equals(getValue(), that.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the provided data in a {@link PojoCloudEventData} serializable by the provided mapper.
|
||||
*
|
||||
* @param <T> The type of {@code data}
|
||||
* @param data the POJO to wrap
|
||||
* @param mapper converter from {@code data} to bytes, used to implement {@link #toBytes()}
|
||||
* @return the new {@link PojoCloudEventData}
|
||||
*/
|
||||
public static <T> PojoCloudEventData<T> wrap(T data, ToBytes<T> mapper) {
|
||||
return new PojoCloudEventData<>(data, mapper);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.extensions;
|
||||
|
||||
import io.cloudevents.CloudEventExtensions;
|
||||
import io.cloudevents.CloudEventExtension;
|
||||
import io.cloudevents.core.extensions.impl.ExtensionUtils;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This extension supports the "Claim Check Pattern". It allows to specify a reference to a location where the event payload is stored.
|
||||
*
|
||||
* @see <a href=https://github.com/cloudevents/spec/blob/v1.0/extensions/dataref.md>https://github.com/cloudevents/spec/blob/v1.0/extensions/dataref.md</a>
|
||||
*/
|
||||
public final class DatarefExtension implements CloudEventExtension {
|
||||
|
||||
/**
|
||||
* The key of the {@code dataref} extension
|
||||
*/
|
||||
public static final String DATAREF = "dataref";
|
||||
|
||||
private static final Set<String> KEY_SET = Collections.unmodifiableSet(new HashSet<>(Collections.singletonList(DATAREF)));
|
||||
|
||||
private URI dataref;
|
||||
|
||||
/**
|
||||
* @return the {@code dataref} contained in this extension.
|
||||
*/
|
||||
public URI getDataref() {
|
||||
return dataref;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataref the uri to set as {@code dataref}.
|
||||
*/
|
||||
public void setDataref(URI dataref) {
|
||||
this.dataref = dataref;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(CloudEventExtensions extensions) {
|
||||
Object value = extensions.getExtension(DATAREF);
|
||||
if (value != null) {
|
||||
this.dataref = URI.create(value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
if (DATAREF.equals(key)) {
|
||||
return this.dataref.toString();
|
||||
}
|
||||
throw ExtensionUtils.generateInvalidKeyException(this.getClass(), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys() {
|
||||
return KEY_SET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DatarefExtension{" +
|
||||
"dataref='" + dataref + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
return prime + ((dataref == null) ? 0 : dataref.hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DatarefExtension other = (DatarefExtension) obj;
|
||||
if (dataref == null) {
|
||||
return other.dataref == null;
|
||||
} else {
|
||||
return dataref.equals(other.dataref);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.extensions;
|
||||
|
||||
import io.cloudevents.CloudEventExtensions;
|
||||
import io.cloudevents.CloudEventExtension;
|
||||
import io.cloudevents.core.extensions.impl.ExtensionUtils;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* This extension embeds context from Distributed Tracing so that distributed systems can include traces that span an event-driven system.
|
||||
*
|
||||
* @see <a href="https://github.com/cloudevents/spec/blob/main/extensions/distributed-tracing.md">https://github.com/cloudevents/spec/blob/main/extensions/distributed-tracing.md</a>
|
||||
*/
|
||||
public final class DistributedTracingExtension implements CloudEventExtension {
|
||||
|
||||
/**
|
||||
* The key of the {@code traceparent} extension
|
||||
*/
|
||||
public static final String TRACEPARENT = "traceparent";
|
||||
|
||||
/**
|
||||
* The key of the {@code tracestate} extension
|
||||
*/
|
||||
public static final String TRACESTATE = "tracestate";
|
||||
|
||||
private static final Set<String> KEY_SET = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(TRACEPARENT, TRACESTATE)));
|
||||
|
||||
private String traceparent;
|
||||
private String tracestate;
|
||||
|
||||
/**
|
||||
* @return the {@code traceparent} contained in this extension.
|
||||
*/
|
||||
public String getTraceparent() {
|
||||
return traceparent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param traceparent the string to set as {@code traceparent}.
|
||||
*/
|
||||
public void setTraceparent(String traceparent) {
|
||||
this.traceparent = traceparent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@code tracestate} contained in this extension.
|
||||
*/
|
||||
public String getTracestate() {
|
||||
return tracestate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tracestate the string to set as {@code tracestate}.
|
||||
*/
|
||||
public void setTracestate(String tracestate) {
|
||||
this.tracestate = tracestate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(CloudEventExtensions extensions) {
|
||||
Object tp = extensions.getExtension(TRACEPARENT);
|
||||
if (tp != null) {
|
||||
this.traceparent = tp.toString();
|
||||
}
|
||||
Object ts = extensions.getExtension(TRACESTATE);
|
||||
if (ts != null) {
|
||||
this.tracestate = ts.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(String key) {
|
||||
switch (key) {
|
||||
case TRACEPARENT:
|
||||
return this.traceparent;
|
||||
case TRACESTATE:
|
||||
return this.tracestate;
|
||||
}
|
||||
throw ExtensionUtils.generateInvalidKeyException(this.getClass(), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getKeys() {
|
||||
return KEY_SET;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DistributedTracingExtension{" +
|
||||
"traceparent='" + traceparent + '\'' +
|
||||
", tracestate='" + tracestate + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
DistributedTracingExtension that = (DistributedTracingExtension) o;
|
||||
return Objects.equals(getTraceparent(), that.getTraceparent()) &&
|
||||
Objects.equals(getTracestate(), that.getTracestate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getTraceparent(), getTracestate());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.extensions.impl;
|
||||
|
||||
import io.cloudevents.CloudEventExtension;
|
||||
|
||||
/**
|
||||
* Collection of utilities to deal with materialized extensions
|
||||
*/
|
||||
public final class ExtensionUtils {
|
||||
|
||||
private ExtensionUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clazz the {@link CloudEventExtension} class
|
||||
* @param key the invalid key
|
||||
* @return an {@link IllegalArgumentException} when trying to access a key of the extension not existing.
|
||||
*/
|
||||
public static IllegalArgumentException generateInvalidKeyException(Class<? extends CloudEventExtension> clazz, String key) {
|
||||
return new IllegalArgumentException(clazz.getName() + " doesn't expect the attribute key \"" + key + "\"");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.format;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.rw.CloudEventDataMapper;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>A construct that aggregates a two-part identifier of file formats and format contents transmitted on the Internet.
|
||||
*
|
||||
* <p>The two parts of a {@code ContentType} are its <em>type</em> and a <em>subtype</em>; separated by a forward slash ({@code /}).
|
||||
*
|
||||
* <p>The constants enumerated by {@code ContentType} correspond <em>only</em> to the specialized formats supported by the Java™ SDK for CloudEvents.
|
||||
*
|
||||
* @see io.cloudevents.core.format.EventFormat
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public enum ContentType {
|
||||
|
||||
/**
|
||||
* Content type associated with the JSON event format
|
||||
*/
|
||||
JSON("application/cloudevents+json"),
|
||||
/**
|
||||
* The content type for transports sending cloudevents in the protocol buffer format.
|
||||
*/
|
||||
PROTO("application/cloudevents+protobuf"),
|
||||
/**
|
||||
* The content type for transports sending cloudevents in the compact Avro format.
|
||||
*/
|
||||
AVRO_COMPACT("application/cloudevents+avrocompact"),
|
||||
/**
|
||||
* The content type for transports sending cloudevents in XML format.
|
||||
*/
|
||||
XML("application/cloudevents+xml");
|
||||
|
||||
private String value;
|
||||
|
||||
private ContentType(String value) { this.value = value; }
|
||||
|
||||
/**
|
||||
* Return a string consisting of the slash-delimited ({@code /}) two-part identifier for this {@code enum} constant.
|
||||
*/
|
||||
public String value() { return value; }
|
||||
|
||||
/**
|
||||
* Return a string consisting of the slash-delimited ({@code /}) two-part identifier for this {@code enum} constant.
|
||||
*/
|
||||
@Override
|
||||
public String toString() { return value(); }
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.format;
|
||||
|
||||
/**
|
||||
* Exception representing a deserialization error while using an {@link EventFormat}.
|
||||
*/
|
||||
public class EventDeserializationException extends RuntimeException {
|
||||
/**
|
||||
* @param cause the cause of the exception
|
||||
*/
|
||||
public EventDeserializationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.format;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.rw.CloudEventDataMapper;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.util.Collections;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* An <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#event-format">Event format</a>
|
||||
* specifies how to serialize a CloudEvent as a sequence of bytes.
|
||||
* <p>
|
||||
* An implementation of this interface should support all specification versions of {@link CloudEvent}.
|
||||
* <p>
|
||||
* Implementations of this interface can be registered to the {@link io.cloudevents.core.provider.EventFormatProvider} to use them.
|
||||
*
|
||||
* @see io.cloudevents.core.provider.EventFormatProvider
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface EventFormat {
|
||||
|
||||
/**
|
||||
* Serialize a {@link CloudEvent} to a byte array.
|
||||
*
|
||||
* @param event the event to serialize.
|
||||
* @return the byte representation of the provided event.
|
||||
* @throws EventSerializationException if something goes wrong during serialization.
|
||||
*/
|
||||
byte[] serialize(CloudEvent event) throws EventSerializationException;
|
||||
|
||||
/**
|
||||
* Like {@link #deserialize(byte[], CloudEventDataMapper)}, but with the identity {@link CloudEventDataMapper}.
|
||||
*
|
||||
* @see #deserialize(byte[], CloudEventDataMapper)
|
||||
*/
|
||||
default CloudEvent deserialize(byte[] bytes) throws EventDeserializationException {
|
||||
return this.deserialize(bytes, CloudEventDataMapper.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a byte array to a {@link CloudEvent}.
|
||||
*
|
||||
* @param bytes the serialized event.
|
||||
* @param mapper the mapper to use to map the data.
|
||||
* @return the deserialized event.
|
||||
* @throws EventDeserializationException if something goes wrong during deserialization.
|
||||
*/
|
||||
CloudEvent deserialize(byte[] bytes, CloudEventDataMapper<? extends CloudEventData> mapper) throws EventDeserializationException;
|
||||
|
||||
/**
|
||||
* @return the set of content types this event format can deserialize. These content types are used
|
||||
* by the {@link io.cloudevents.core.provider.EventFormatProvider} to resolve an {@link EventFormat} starting
|
||||
* from the content type {@link String}.
|
||||
*/
|
||||
default Set<String> deserializableContentTypes() {
|
||||
return Collections.singleton(serializedContentType());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The content type to use when writing an event with this {@link EventFormat}.
|
||||
*/
|
||||
String serializedContentType();
|
||||
|
||||
}
|
|
@ -1,33 +1,30 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.cloudevents;
|
||||
|
||||
import io.cloudevents.beans.Receiver;
|
||||
import org.mockito.Mockito;
|
||||
package io.cloudevents.core.format;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
|
||||
@ApplicationScoped
|
||||
public class MockProvider {
|
||||
|
||||
private Receiver receiver = Mockito.mock(Receiver.class);
|
||||
|
||||
@Produces
|
||||
public Receiver receiver() {
|
||||
return receiver;
|
||||
/**
|
||||
* Exception representing a serialization error while using an {@link EventFormat}.
|
||||
*/
|
||||
public class EventSerializationException extends RuntimeException {
|
||||
/**
|
||||
* @param cause the cause of the exception
|
||||
*/
|
||||
public EventSerializationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.impl;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.rw.*;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class BaseCloudEvent implements CloudEvent, CloudEventReader, CloudEventContextReader {
|
||||
|
||||
private final CloudEventData data;
|
||||
protected final Map<String, Object> extensions;
|
||||
|
||||
protected BaseCloudEvent(CloudEventData data, Map<String, Object> extensions) {
|
||||
this.data = data;
|
||||
this.extensions = extensions != null ? extensions : new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEventData getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getExtension(String extensionName) {
|
||||
return this.extensions.get(extensionName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getExtensionNames() {
|
||||
return this.extensions.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException, IllegalStateException {
|
||||
CloudEventWriter<V> writer = writerFactory.create(this.getSpecVersion());
|
||||
this.readContext(writer);
|
||||
|
||||
if (this.data != null) {
|
||||
return writer.end(mapper.map(this.data));
|
||||
}
|
||||
|
||||
return writer.end();
|
||||
}
|
||||
|
||||
protected void readExtensions(CloudEventContextWriter writer) throws CloudEventRWException {
|
||||
// TODO to be improved
|
||||
for (Map.Entry<String, Object> entry : this.extensions.entrySet()) {
|
||||
if (entry.getValue() instanceof String) {
|
||||
writer.withContextAttribute(entry.getKey(), (String) entry.getValue());
|
||||
} else if (entry.getValue() instanceof Number) {
|
||||
writer.withContextAttribute(entry.getKey(), (Number) entry.getValue());
|
||||
} else if (entry.getValue() instanceof Boolean) {
|
||||
writer.withContextAttribute(entry.getKey(), (Boolean) entry.getValue());
|
||||
} else if (entry.getValue() instanceof URI) {
|
||||
writer.withContextAttribute(entry.getKey(), (URI) entry.getValue());
|
||||
} else if (entry.getValue() instanceof OffsetDateTime) {
|
||||
writer.withContextAttribute(entry.getKey(), (OffsetDateTime) entry.getValue());
|
||||
} else if (entry.getValue() instanceof byte[]) {
|
||||
writer.withContextAttribute(entry.getKey(), (byte[]) entry.getValue());
|
||||
} else {
|
||||
// This should never happen because we build that map only through our builders
|
||||
throw new IllegalStateException("Illegal value inside extensions map: " + entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.impl;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventContext;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.CloudEventExtension;
|
||||
import io.cloudevents.core.builder.CloudEventBuilder;
|
||||
import io.cloudevents.core.data.BytesCloudEventData;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.net.URI;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.cloudevents.core.v03.CloudEventV03.SPECVERSION;
|
||||
|
||||
public abstract class BaseCloudEventBuilder<SELF extends BaseCloudEventBuilder<SELF, T>, T extends CloudEvent> implements CloudEventBuilder {
|
||||
|
||||
// This is a little trick for enabling fluency
|
||||
private final SELF self;
|
||||
|
||||
protected CloudEventData data;
|
||||
protected Map<String, Object> extensions = new HashMap<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public BaseCloudEventBuilder() {
|
||||
this.self = (SELF) this;
|
||||
}
|
||||
|
||||
public BaseCloudEventBuilder(CloudEventContext context) {
|
||||
this();
|
||||
setAttributes(context);
|
||||
}
|
||||
|
||||
public BaseCloudEventBuilder(CloudEvent event) {
|
||||
this();
|
||||
this.setAttributes(event);
|
||||
this.data = event.getData();
|
||||
}
|
||||
|
||||
protected abstract void setAttributes(CloudEventContext event);
|
||||
|
||||
//TODO builder should accept data as Object and use data codecs (that we need to implement)
|
||||
// to encode data
|
||||
|
||||
public SELF withData(byte[] data) {
|
||||
this.data = BytesCloudEventData.wrap(data);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
public SELF withData(String dataContentType, byte[] data) {
|
||||
withDataContentType(dataContentType);
|
||||
withData(data);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
public SELF withData(String dataContentType, URI dataSchema, byte[] data) {
|
||||
withDataContentType(dataContentType);
|
||||
withDataSchema(dataSchema);
|
||||
withData(data);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
public SELF withData(CloudEventData data) {
|
||||
this.data = data;
|
||||
return this.self;
|
||||
}
|
||||
|
||||
public SELF withData(String dataContentType, CloudEventData data) {
|
||||
withDataContentType(dataContentType);
|
||||
withData(data);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
public SELF withData(String dataContentType, URI dataSchema, CloudEventData data) {
|
||||
withDataContentType(dataContentType);
|
||||
withDataSchema(dataSchema);
|
||||
withData(data);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEventBuilder withoutData() {
|
||||
this.data = null;
|
||||
return this.self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEventBuilder withoutDataSchema() {
|
||||
withDataSchema(null);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEventBuilder withoutDataContentType() {
|
||||
withDataContentType(null);
|
||||
return this.self;
|
||||
}
|
||||
|
||||
public SELF withExtension(@Nonnull String key, @Nonnull String value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
// @TODO - I think this method should be removed/deprecated
|
||||
// **Number** Is NOT a valid CE Context atrribute type.
|
||||
|
||||
public SELF withExtension(@Nonnull String key, @Nonnull Number value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
public SELF withExtension(@Nonnull String key, @Nonnull Integer value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
public SELF withExtension(@Nonnull String key, @Nonnull Boolean value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SELF withExtension(@Nonnull String key, @Nonnull URI value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SELF withExtension(@Nonnull String key, @Nonnull OffsetDateTime value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEventBuilder withExtension(@Nonnull String key, @Nonnull byte[] value) {
|
||||
if (!isValidExtensionName(key)) {
|
||||
throw CloudEventRWException.newInvalidExtensionName(key);
|
||||
}
|
||||
this.extensions.put(key, value);
|
||||
return self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SELF withoutExtension(@Nonnull String key) {
|
||||
this.extensions.remove(key);
|
||||
return self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SELF withoutExtension(@Nonnull CloudEventExtension extension) {
|
||||
extension.getKeys().forEach(this::withoutExtension);
|
||||
return self;
|
||||
}
|
||||
|
||||
public SELF withExtension(@Nonnull CloudEventExtension extension) {
|
||||
for (String key : extension.getKeys()) {
|
||||
Object value = extension.getValue(key);
|
||||
if (value != null) {
|
||||
this.extensions.put(key, value);
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEvent end(CloudEventData value) throws CloudEventRWException {
|
||||
this.data = value;
|
||||
return build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CloudEvent end() {
|
||||
try {
|
||||
return build();
|
||||
} catch (Exception e) {
|
||||
throw CloudEventRWException.newOther(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static IllegalStateException createMissingAttributeException(String attributeName) {
|
||||
return new IllegalStateException("Attribute '" + attributeName + "' cannot be null");
|
||||
}
|
||||
|
||||
protected static IllegalStateException createEmptyAttributeException(String attributeName) {
|
||||
return new IllegalStateException("Attribute '" + attributeName + "' cannot be empty");
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the extension name as defined in CloudEvents spec.
|
||||
*
|
||||
* @param name the extension name
|
||||
* @return true if extension name is valid, false otherwise
|
||||
* @see <a href="https://github.com/cloudevents/spec/blob/main/cloudevents/spec.md#naming-conventions">attribute-naming-conventions</a>
|
||||
*/
|
||||
private static boolean isValidExtensionName(String name) {
|
||||
for (int i = 0; i < name.length(); i++) {
|
||||
if (!isValidChar(name.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isValidChar(char c) {
|
||||
return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
|
||||
}
|
||||
|
||||
protected void requireValidAttributeWrite(String name) {
|
||||
if (name.equals(SPECVERSION)) {
|
||||
throw new IllegalArgumentException("You should not set the specversion attribute through withContextAttribute methods");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.impl;
|
||||
|
||||
import io.cloudevents.CloudEventContext;
|
||||
import io.cloudevents.rw.CloudEventContextReader;
|
||||
import io.cloudevents.rw.CloudEventContextWriter;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import java.net.URI;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
public class CloudEventContextReaderAdapter implements CloudEventContextReader {
|
||||
|
||||
private final CloudEventContext event;
|
||||
|
||||
public CloudEventContextReaderAdapter(CloudEventContext event) {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public void readAttributes(CloudEventContextWriter writer) throws RuntimeException {
|
||||
writer.withContextAttribute("id", event.getId());
|
||||
writer.withContextAttribute("source", event.getSource());
|
||||
writer.withContextAttribute("type", event.getType());
|
||||
if (event.getDataContentType() != null) {
|
||||
writer.withContextAttribute("datacontenttype", event.getDataContentType());
|
||||
}
|
||||
if (event.getDataSchema() != null) {
|
||||
writer.withContextAttribute("dataschema", event.getDataSchema());
|
||||
}
|
||||
if (event.getSubject() != null) {
|
||||
writer.withContextAttribute("subject", event.getSubject());
|
||||
}
|
||||
if (event.getTime() != null) {
|
||||
writer.withContextAttribute("time", event.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
public void readExtensions(CloudEventContextWriter writer) throws RuntimeException {
|
||||
for (String key : event.getExtensionNames()) {
|
||||
Object value = event.getExtension(key);
|
||||
if (value instanceof String) {
|
||||
writer.withContextAttribute(key, (String) value);
|
||||
} else if (value instanceof Number) {
|
||||
writer.withContextAttribute(key, (Number) value);
|
||||
} else if (value instanceof Boolean) {
|
||||
writer.withContextAttribute(key, (Boolean) value);
|
||||
} else if (value instanceof URI) {
|
||||
writer.withContextAttribute(key, (URI) value);
|
||||
} else if (value instanceof OffsetDateTime) {
|
||||
writer.withContextAttribute(key, (OffsetDateTime) value);
|
||||
} else {
|
||||
// This should never happen because we build that map only through our builders
|
||||
throw new IllegalStateException("Illegal value inside extensions map: " + key + " " + value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readContext(CloudEventContextWriter writer) throws CloudEventRWException {
|
||||
this.readAttributes(writer);
|
||||
this.readExtensions(writer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.impl;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.rw.*;
|
||||
|
||||
public class CloudEventReaderAdapter extends CloudEventContextReaderAdapter implements CloudEventReader {
|
||||
|
||||
private final CloudEvent event;
|
||||
|
||||
public CloudEventReaderAdapter(CloudEvent event) {
|
||||
super(event);
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<V, R> writerFactory,
|
||||
CloudEventDataMapper<? extends CloudEventData> mapper) throws RuntimeException {
|
||||
CloudEventWriter<R> visitor = writerFactory.create(event.getSpecVersion());
|
||||
this.readAttributes(visitor);
|
||||
this.readExtensions(visitor);
|
||||
|
||||
if (event.getData() != null) {
|
||||
return visitor.end(mapper.map(event.getData()));
|
||||
}
|
||||
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +1,31 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.cloudevents.cdi;
|
||||
|
||||
import javax.enterprise.util.AnnotationLiteral;
|
||||
package io.cloudevents.core.impl;
|
||||
|
||||
public class EventTypeQualifier extends AnnotationLiteral<EventType> implements EventType {
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String eventName;
|
||||
final public class StringUtils {
|
||||
|
||||
public EventTypeQualifier(final String name) {
|
||||
eventName=name;
|
||||
private StringUtils() {
|
||||
// Prevent construction.
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return eventName;
|
||||
public static boolean startsWithIgnoreCase(@Nonnull final String s, @Nonnull final String prefix) {
|
||||
return s.regionMatches(true /* ignoreCase */, 0, prefix, 0, prefix.length());
|
||||
}
|
||||
}
|
|
@ -1,21 +1,32 @@
|
|||
/**
|
||||
* Copyright 2018 The CloudEvents Authors
|
||||
*
|
||||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
package io.cloudevents.beans;
|
||||
|
||||
public interface Receiver {
|
||||
package io.cloudevents.core.message;
|
||||
|
||||
void ack();
|
||||
/**
|
||||
* One of the possible encodings of a <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#message">CloudEvent message</a>
|
||||
*/
|
||||
public enum Encoding {
|
||||
/**
|
||||
* Structured mode
|
||||
*/
|
||||
STRUCTURED,
|
||||
/**
|
||||
* Binary mode
|
||||
*/
|
||||
BINARY
|
||||
}
|
|
@ -0,0 +1,126 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.SpecVersion;
|
||||
import io.cloudevents.core.CloudEventUtils;
|
||||
import io.cloudevents.rw.*;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Represents a <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#message">CloudEvent message</a> reader.
|
||||
* <p>
|
||||
* This class expands the {@link CloudEventReader} to define reading both binary and structured messages.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface MessageReader extends StructuredMessageReader, CloudEventReader {
|
||||
|
||||
/**
|
||||
* Like {@link #read(CloudEventWriterFactory, CloudEventDataMapper)}, but with the identity {@link CloudEventDataMapper}.
|
||||
*
|
||||
* @see #read(CloudEventWriterFactory, CloudEventDataMapper)
|
||||
*/
|
||||
default <W extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<W, R> writerFactory) throws CloudEventRWException, IllegalStateException {
|
||||
return read(writerFactory, CloudEventDataMapper.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the message as binary encoded message using the provided writer factory.
|
||||
*
|
||||
* @param <W> the {@link CloudEventWriter} type
|
||||
* @param <R> the return type of the {@link CloudEventWriter}
|
||||
* @param writerFactory a factory that generates a reader starting from the {@link SpecVersion} of the event
|
||||
* @param mapper the mapper to use to map the data, if any.
|
||||
* @throws CloudEventRWException if something went wrong during the visit.
|
||||
* @throws IllegalStateException if the message is not in binary encoding.
|
||||
*/
|
||||
<W extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<W, R> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* Read the message as structured encoded message using the provided writer
|
||||
*
|
||||
* @param <R> the return type of the {@link StructuredMessageWriter}
|
||||
* @param writer Structured Message writer
|
||||
* @throws CloudEventRWException if something went wrong during the visit.
|
||||
* @throws IllegalStateException if the message is not in structured encoding.
|
||||
*/
|
||||
<R> R read(StructuredMessageWriter<R> writer) throws CloudEventRWException, IllegalStateException;
|
||||
|
||||
/**
|
||||
* @return The message encoding
|
||||
*/
|
||||
Encoding getEncoding();
|
||||
|
||||
/**
|
||||
* Read the content of this object using a {@link MessageWriter}. This method allows to transcode an event from one transport to another without
|
||||
* converting it to {@link CloudEvent}. The resulting encoding will be the same as the original encoding.
|
||||
*
|
||||
* @param <BW> the {@link CloudEventWriter} type
|
||||
* @param <R> the return type of both {@link CloudEventWriter} and {@link StructuredMessageWriter}
|
||||
* @param writer the {@link MessageWriter} accepting this Message
|
||||
* @return The return value of the {@link MessageWriter}
|
||||
* @throws CloudEventRWException if something went wrong during the visit.
|
||||
* @throws IllegalStateException if the message has an unknown encoding.
|
||||
*/
|
||||
default <BW extends CloudEventWriter<R>, R> R read(MessageWriter<BW, R> writer) throws CloudEventRWException, IllegalStateException {
|
||||
switch (getEncoding()) {
|
||||
case BINARY:
|
||||
return this.read((CloudEventWriterFactory<BW, R>) writer);
|
||||
case STRUCTURED:
|
||||
return this.read((StructuredMessageWriter<R>) writer);
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"The provided Encoding doesn't exist. Please make sure your io.cloudevents deps versions are aligned."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Like {@link #toEvent(CloudEventDataMapper)}, but with the identity {@link CloudEventDataMapper}.
|
||||
*
|
||||
* @see #toEvent(CloudEventDataMapper)
|
||||
*/
|
||||
default CloudEvent toEvent() throws CloudEventRWException, IllegalStateException {
|
||||
return toEvent(CloudEventDataMapper.identity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate this message into a {@link CloudEvent} representation, mapping the data with the provided {@code mapper}.
|
||||
*
|
||||
* @param mapper the mapper to use to map the data, if any.
|
||||
* @return A {@link CloudEvent} with the contents of this message.
|
||||
* @throws CloudEventRWException if something went wrong during the read.
|
||||
* @throws IllegalStateException if the message has an unknown encoding.
|
||||
*/
|
||||
default CloudEvent toEvent(CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException, IllegalStateException {
|
||||
switch (getEncoding()) {
|
||||
case BINARY:
|
||||
return CloudEventUtils.toEvent(this, mapper);
|
||||
case STRUCTURED:
|
||||
return this.read((format, value) -> format.deserialize(value, mapper));
|
||||
default:
|
||||
throw new IllegalStateException(
|
||||
"The provided Encoding doesn't exist. Please make sure your io.cloudevents deps versions are aligned."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.core.CloudEventUtils;
|
||||
import io.cloudevents.core.format.EventFormat;
|
||||
import io.cloudevents.core.message.impl.GenericStructuredMessageReader;
|
||||
import io.cloudevents.rw.CloudEventWriter;
|
||||
import io.cloudevents.rw.CloudEventWriterFactory;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Interface to write the {@link MessageReader} content (CloudEvents attributes, extensions and payload) to a new representation.
|
||||
*
|
||||
* @param <R> return value at the end of the write process.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface MessageWriter<CEV extends CloudEventWriter<R>, R> extends CloudEventWriterFactory<CEV, R>, StructuredMessageWriter<R> {
|
||||
|
||||
/**
|
||||
* Write the provided event as structured.
|
||||
*
|
||||
* @param event event to write.
|
||||
* @param format {@link EventFormat} to use to serialize the event.
|
||||
* @return return value at the end of the write process.
|
||||
*/
|
||||
default R writeStructured(CloudEvent event, String format) {
|
||||
GenericStructuredMessageReader message = GenericStructuredMessageReader.from(event, format);
|
||||
if (message == null) {
|
||||
throw new IllegalArgumentException("Format " + format + " not found");
|
||||
}
|
||||
|
||||
return message.read((StructuredMessageWriter<R>) this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the provided event as structured.
|
||||
*
|
||||
* @param event event to write.
|
||||
* @param format string to resolve the {@link EventFormat} to use to serialize the event.
|
||||
* @return return value at the end of the write process.
|
||||
*/
|
||||
default R writeStructured(CloudEvent event, EventFormat format) {
|
||||
return GenericStructuredMessageReader.from(event, format).read((StructuredMessageWriter<R>) this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the provided event as binary.
|
||||
*
|
||||
* @param event event to write.
|
||||
* @return return value at the end of the write process.
|
||||
*/
|
||||
default R writeBinary(CloudEvent event) {
|
||||
return CloudEventUtils.toReader(event).read(this);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.core.format.EventFormat;
|
||||
import io.cloudevents.core.message.impl.GenericStructuredMessageReader;
|
||||
import io.cloudevents.rw.CloudEventDataMapper;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Represents a <a href="https://github.com/cloudevents/spec/blob/v1.0/spec.md#message">CloudEvent message</a> in structured mode.
|
||||
*/
|
||||
@FunctionalInterface
|
||||
@ParametersAreNonnullByDefault
|
||||
public interface StructuredMessageReader {
|
||||
|
||||
/**
|
||||
* Read self using the provided writer.
|
||||
*
|
||||
* @param <R> the return type of the {@link StructuredMessageWriter}
|
||||
* @param writer the writer to use to write out the message
|
||||
* @return the return value returned by {@link StructuredMessageWriter#setEvent(EventFormat, byte[])}
|
||||
* @throws CloudEventRWException If something went wrong when
|
||||
* @throws IllegalStateException If the message is not a valid structured message
|
||||
*/
|
||||
<R> R read(StructuredMessageWriter<R> writer) throws CloudEventRWException, IllegalStateException;
|
||||
|
||||
default CloudEvent toEvent() throws CloudEventRWException, IllegalStateException {
|
||||
return this.read(EventFormat::deserialize);
|
||||
}
|
||||
|
||||
default CloudEvent toEvent(CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException, IllegalStateException {
|
||||
return this.read((format, value) -> format.deserialize(value, mapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic structured message from a {@link CloudEvent}.
|
||||
*
|
||||
* @param event the event to convert to {@link StructuredMessageReader}
|
||||
* @param contentType content type to use to resolve the {@link EventFormat}
|
||||
* @return null if format was not found, otherwise returns the built message
|
||||
*/
|
||||
static StructuredMessageReader from(CloudEvent event, String contentType) {
|
||||
return GenericStructuredMessageReader.from(event, contentType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic structured message from a {@link CloudEvent}.
|
||||
*
|
||||
* @param event the event to convert to {@link StructuredMessageReader}
|
||||
* @param format the format to use to perform the conversion
|
||||
* @return null if format was not found, otherwise returns the built message
|
||||
*/
|
||||
static StructuredMessageReader from(CloudEvent event, EventFormat format) {
|
||||
return GenericStructuredMessageReader.from(event, format);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message;
|
||||
|
||||
import io.cloudevents.core.format.EventFormat;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
/**
|
||||
* Interface to write the {@link MessageReader} content (CloudEvents attributes, extensions and payload) to a new representation structured representation.
|
||||
*
|
||||
* @param <R> return value at the end of the write process.
|
||||
*/
|
||||
@ParametersAreNonnullByDefault
|
||||
@FunctionalInterface
|
||||
public interface StructuredMessageWriter<R> {
|
||||
|
||||
/**
|
||||
* Write an event using the provided {@link EventFormat}.
|
||||
*/
|
||||
R setEvent(EventFormat format, byte[] value) throws CloudEventRWException;
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message.impl;
|
||||
|
||||
import io.cloudevents.core.message.Encoding;
|
||||
import io.cloudevents.core.message.MessageReader;
|
||||
import io.cloudevents.core.message.StructuredMessageWriter;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
/**
|
||||
* Base {@link MessageReader} implementation for a binary message
|
||||
*/
|
||||
public abstract class BaseBinaryMessageReader implements MessageReader {
|
||||
|
||||
@Override
|
||||
public Encoding getEncoding() {
|
||||
return Encoding.BINARY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T read(StructuredMessageWriter<T> writer) throws CloudEventRWException, IllegalStateException {
|
||||
throw MessageUtils.generateWrongEncoding(Encoding.STRUCTURED, Encoding.BINARY);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message.impl;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.SpecVersion;
|
||||
import io.cloudevents.core.v1.CloudEventV1;
|
||||
import io.cloudevents.rw.CloudEventDataMapper;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
import io.cloudevents.rw.CloudEventWriter;
|
||||
import io.cloudevents.rw.CloudEventWriterFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* This class implements a Binary {@link io.cloudevents.core.message.MessageReader},
|
||||
* providing common logic to most protocol bindings which supports both Binary and Structured mode.
|
||||
* <p>
|
||||
* Content-type is handled separately using a key not prefixed with CloudEvents header prefix.
|
||||
*
|
||||
* @param <HK> Header key type
|
||||
* @param <HV> Header value type
|
||||
*/
|
||||
public abstract class BaseGenericBinaryMessageReaderImpl<HK, HV> extends BaseBinaryMessageReader {
|
||||
|
||||
private final SpecVersion version;
|
||||
private final CloudEventData body;
|
||||
|
||||
protected BaseGenericBinaryMessageReaderImpl(SpecVersion version, CloudEventData body) {
|
||||
Objects.requireNonNull(version);
|
||||
this.version = version;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends CloudEventWriter<V>, V> V read(CloudEventWriterFactory<T, V> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) throws CloudEventRWException, IllegalStateException {
|
||||
CloudEventWriter<V> visitor = writerFactory.create(this.version);
|
||||
|
||||
// Grab from headers the attributes and extensions
|
||||
// This implementation avoids to use visitAttributes and visitExtensions
|
||||
// in order to complete the visit in one loop
|
||||
this.forEachHeader((key, value) -> {
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
if (isContentTypeHeader(key)) {
|
||||
visitor.withContextAttribute(CloudEventV1.DATACONTENTTYPE, toCloudEventsValue(value));
|
||||
} else if (isCloudEventsHeader(key)) {
|
||||
String name = toCloudEventsKey(key);
|
||||
if (name.equals(CloudEventV1.SPECVERSION)) {
|
||||
return;
|
||||
}
|
||||
visitor.withContextAttribute(name, toCloudEventsValue(value));
|
||||
}
|
||||
});
|
||||
|
||||
// Set the payload
|
||||
if (this.body != null) {
|
||||
return visitor.end(mapper.map(this.body));
|
||||
}
|
||||
|
||||
return visitor.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param key header key
|
||||
* @return true if this header is the content type header, false otherwise
|
||||
*/
|
||||
protected abstract boolean isContentTypeHeader(HK key);
|
||||
|
||||
/**
|
||||
* @param key header key
|
||||
* @return true if this header is a CloudEvents header, false otherwise
|
||||
*/
|
||||
protected abstract boolean isCloudEventsHeader(HK key);
|
||||
|
||||
/**
|
||||
* @param key header key
|
||||
* @return the key converted to a CloudEvents context attribute/extension name
|
||||
*/
|
||||
protected abstract String toCloudEventsKey(HK key);
|
||||
|
||||
/**
|
||||
* Iterate over all the headers in the headers map.
|
||||
*
|
||||
* @param fn header consumer
|
||||
*/
|
||||
protected abstract void forEachHeader(BiConsumer<HK, HV> fn);
|
||||
|
||||
/**
|
||||
* @param value header key
|
||||
* @return the value converted to a valid CloudEvents attribute value as {@link String}.
|
||||
*/
|
||||
protected abstract String toCloudEventsValue(HV value);
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message.impl;
|
||||
|
||||
import io.cloudevents.CloudEventData;
|
||||
import io.cloudevents.core.message.Encoding;
|
||||
import io.cloudevents.core.message.MessageReader;
|
||||
import io.cloudevents.rw.CloudEventDataMapper;
|
||||
import io.cloudevents.rw.CloudEventWriter;
|
||||
import io.cloudevents.rw.CloudEventWriterFactory;
|
||||
|
||||
/**
|
||||
* Base {@link MessageReader} implementation for a structured message
|
||||
*/
|
||||
public abstract class BaseStructuredMessageReader implements MessageReader {
|
||||
|
||||
@Override
|
||||
public Encoding getEncoding() {
|
||||
return Encoding.STRUCTURED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <V extends CloudEventWriter<R>, R> R read(CloudEventWriterFactory<V, R> writerFactory, CloudEventDataMapper<? extends CloudEventData> mapper) {
|
||||
throw MessageUtils.generateWrongEncoding(Encoding.BINARY, Encoding.STRUCTURED);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright 2018-Present The CloudEvents Authors
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.cloudevents.core.message.impl;
|
||||
|
||||
import io.cloudevents.CloudEvent;
|
||||
import io.cloudevents.core.format.EventFormat;
|
||||
import io.cloudevents.core.message.StructuredMessageWriter;
|
||||
import io.cloudevents.core.provider.EventFormatProvider;
|
||||
import io.cloudevents.lang.Nullable;
|
||||
import io.cloudevents.rw.CloudEventRWException;
|
||||
|
||||
/**
|
||||
* Generic implementation of a structured message.
|
||||
*/
|
||||
public class GenericStructuredMessageReader extends BaseStructuredMessageReader {
|
||||
|
||||
private final EventFormat format;
|
||||
private final byte[] payload;
|
||||
|
||||
public GenericStructuredMessageReader(EventFormat format, byte[] payload) {
|
||||
this.format = format;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T read(StructuredMessageWriter<T> writer) throws CloudEventRWException, IllegalStateException {
|
||||
return writer.setEvent(format, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic structured message from a payload
|
||||
*
|
||||
* @param contentType content type to use to resolve the {@link EventFormat}
|
||||
* @param payload serialized event
|
||||
* @return null if format was not found, otherwise returns the built message
|
||||
*/
|
||||
public static GenericStructuredMessageReader fromContentType(String contentType, byte[] payload) {
|
||||
EventFormat format = EventFormatProvider.getInstance().resolveFormat(contentType);
|
||||
if (format == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new GenericStructuredMessageReader(format, payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic structured message from a {@link CloudEvent}
|
||||
*
|
||||
* @param event
|
||||
* @param contentType content type to use to resolve the {@link EventFormat}
|
||||
* @return null if format was not found, otherwise returns the built message
|
||||
*/
|
||||
@Nullable
|
||||
public static GenericStructuredMessageReader from(CloudEvent event, String contentType) {
|
||||
EventFormat format = EventFormatProvider.getInstance().resolveFormat(contentType);
|
||||
if (format == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return from(event, format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a generic structured message from a {@link CloudEvent}
|
||||
*
|
||||
* @param event
|
||||
* @param format
|
||||
* @return returns the built message
|
||||
*/
|
||||
public static GenericStructuredMessageReader from(CloudEvent event, EventFormat format) {
|
||||
return new GenericStructuredMessageReader(format, format.serialize(event));
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue