1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.apiclient.webflux.contract.spring;
18
19 import static java.util.Objects.nonNull;
20
21 import java.util.List;
22 import java.util.stream.Collectors;
23 import org.bremersee.apiclient.webflux.Invocation;
24 import org.bremersee.apiclient.webflux.InvocationParameter;
25 import org.bremersee.apiclient.webflux.contract.RequestBodyInserter;
26 import org.springframework.web.bind.annotation.RequestBody;
27
28
29
30
31
32
33 public abstract class AbstractRequestBodyInserter implements RequestBodyInserter {
34
35 @Override
36 public boolean canInsert(Invocation invocation) {
37 return canInsert(findPossibleBodies(invocation));
38 }
39
40
41
42
43
44
45
46 protected boolean canInsert(List<InvocationParameter> possibleBodies) {
47 return !possibleBodies.isEmpty();
48 }
49
50
51
52
53
54
55
56 protected List<InvocationParameter> findPossibleBodies(Invocation invocation) {
57 return invocation.toMethodParameterStream()
58 .filter(this::isPossibleBody)
59 .sorted(new RequestBodyComparator())
60 .collect(Collectors.toList());
61 }
62
63
64
65
66
67
68
69 protected boolean isPossibleBody(InvocationParameter invocationParameter) {
70 return nonNull(invocationParameter.getValue())
71 && isPossibleBodyValue(invocationParameter)
72 && hasMappingAnnotation(invocationParameter);
73 }
74
75
76
77
78
79
80
81 protected abstract boolean isPossibleBodyValue(InvocationParameter invocationParameter);
82
83
84
85
86
87
88
89 protected boolean hasMappingAnnotation(InvocationParameter invocationParameter) {
90 return invocationParameter.hasParameterAnnotation(RequestBody.class);
91 }
92
93 }