1
1
package functions ;
2
2
3
- import static org .springframework .cloud .function .cloudevent .CloudEventMessageUtils .HTTP_ATTR_PREFIX ;
4
3
import static org .springframework .cloud .function .cloudevent .CloudEventMessageUtils .ID ;
5
4
import static org .springframework .cloud .function .cloudevent .CloudEventMessageUtils .SOURCE ;
6
5
import static org .springframework .cloud .function .cloudevent .CloudEventMessageUtils .SPECVERSION ;
12
11
import java .util .logging .Logger ;
13
12
import org .springframework .boot .SpringApplication ;
14
13
import org .springframework .boot .autoconfigure .SpringBootApplication ;
15
- import org .springframework .cloud .function .cloudevent .CloudEventAttributesProvider ;
14
+ import org .springframework .cloud .function .cloudevent .CloudEventHeaderEnricher ;
16
15
import org .springframework .cloud .function .web .util .HeaderUtils ;
17
16
import org .springframework .context .annotation .Bean ;
18
17
import org .springframework .http .HttpHeaders ;
@@ -29,42 +28,37 @@ public static void main(String[] args) {
29
28
}
30
29
31
30
@ Bean
32
- public Function <Message <Input >, Output > uppercase (
33
- CloudEventAttributesProvider provider ) {
31
+ public Function <Message <Input >, Output > uppercase (CloudEventHeaderEnricher enricher ) {
34
32
return m -> {
35
33
HttpHeaders httpHeaders = HeaderUtils .fromMessage (m .getHeaders ());
36
-
37
- ;
34
+
38
35
LOGGER .log (Level .INFO , "Input CE Id:{0}" , httpHeaders .getFirst (
39
- HTTP_ATTR_PREFIX + ID ));
36
+ ID ));
40
37
LOGGER .log (Level .INFO , "Input CE Spec Version:{0}" ,
41
- httpHeaders .getFirst (HTTP_ATTR_PREFIX + SPECVERSION ));
38
+ httpHeaders .getFirst (SPECVERSION ));
42
39
LOGGER .log (Level .INFO , "Input CE Source:{0}" ,
43
- httpHeaders .getFirst (HTTP_ATTR_PREFIX + SOURCE ));
40
+ httpHeaders .getFirst (SOURCE ));
44
41
LOGGER .log (Level .INFO , "Input CE Subject:{0}" ,
45
- httpHeaders .getFirst (HTTP_ATTR_PREFIX + SUBJECT ));
42
+ httpHeaders .getFirst (SUBJECT ));
46
43
47
44
Input input = m .getPayload ();
48
45
LOGGER .log (Level .INFO , "Input {0} " , input );
49
46
Output output = new Output ();
50
47
output .input = input .input ;
51
- output .operation = httpHeaders .getFirst (HTTP_ATTR_PREFIX + SUBJECT );
52
- output .output =
53
- input .input != null ? input .input .toUpperCase () : "NO DATA" ;
48
+ output .operation = httpHeaders .getFirst (SUBJECT );
49
+ output .output = input .input != null ? input .input .toUpperCase () : "NO DATA" ;
54
50
return output ;
55
51
};
56
52
}
57
53
58
54
@ Bean
59
- public CloudEventAttributesProvider attributesProvider () {
60
- return attributes -> {
61
- attributes
62
- .setSpecversion ("1.0" )
63
- .setId (UUID .randomUUID ()
64
- .toString ())
65
- .setSource ("http://example.com/uppercase" )
66
- .setType ("com.redhat.faas.springboot.events" );
67
- };
55
+ public CloudEventHeaderEnricher attributesProvider () {
56
+ return attributes -> attributes
57
+ .setSpecVersion ("1.0" )
58
+ .setId (UUID .randomUUID ()
59
+ .toString ())
60
+ .setSource ("http://example.com/uppercase" )
61
+ .setType ("com.redhat.faas.springboot.events" );
68
62
}
69
63
70
64
/**
0 commit comments