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 java.util.function.Function;
20 import org.bremersee.apiclient.webflux.Invocation;
21 import org.springframework.util.StringUtils;
22 import org.springframework.web.bind.annotation.DeleteMapping;
23 import org.springframework.web.bind.annotation.GetMapping;
24 import org.springframework.web.bind.annotation.PatchMapping;
25 import org.springframework.web.bind.annotation.PostMapping;
26 import org.springframework.web.bind.annotation.PutMapping;
27 import org.springframework.web.bind.annotation.RequestMapping;
28
29
30
31
32
33
34 public class RequestPathResolver implements Function<Invocation, String> {
35
36 @Override
37 public String apply(Invocation invocation) {
38
39 String clsPath = invocation
40 .findAnnotationValueOnTargetClass(
41 RequestMapping.class, a -> a.value().length > 0, a -> a.value()[0])
42 .orElse("");
43
44
45 String path = invocation
46 .findAnnotationValueOnMethod(
47 RequestMapping.class, a -> a.value().length > 0, a -> a.value()[0])
48 .orElse("");
49 if (StringUtils.hasText(path)) {
50 return clsPath + path;
51 }
52
53
54 path = invocation
55 .findAnnotationValueOnMethod(
56 GetMapping.class, a -> a.value().length > 0, a -> a.value()[0])
57 .orElse("");
58 if (StringUtils.hasText(path)) {
59 return clsPath + path;
60 }
61
62
63 path = invocation
64 .findAnnotationValueOnMethod(
65 PostMapping.class, a -> a.value().length > 0, a -> a.value()[0])
66 .orElse("");
67 if (StringUtils.hasText(path)) {
68 return clsPath + path;
69 }
70
71
72 path = invocation
73 .findAnnotationValueOnMethod(
74 PutMapping.class, a -> a.value().length > 0, a -> a.value()[0])
75 .orElse("");
76 if (StringUtils.hasText(path)) {
77 return clsPath + path;
78 }
79
80
81 path = invocation
82 .findAnnotationValueOnMethod(
83 PatchMapping.class, a -> a.value().length > 0, a -> a.value()[0])
84 .orElse("");
85 if (StringUtils.hasText(path)) {
86 return clsPath + path;
87 }
88
89
90 path = invocation
91 .findAnnotationValueOnMethod(
92 DeleteMapping.class, a -> a.value().length > 0, a -> a.value()[0])
93 .orElse("");
94 return clsPath + path;
95 }
96 }