Revision 47124
Added by Claudio Atzori almost 7 years ago
EndpointDocController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib; |
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 |
import java.util.Map.Entry; |
|
5 | 4 |
import java.util.Set; |
5 |
import java.util.stream.Collectors; |
|
6 |
import java.util.stream.Stream; |
|
6 | 7 |
|
7 |
import com.google.common.collect.Sets; |
|
8 | 8 |
import org.apache.commons.logging.Log; |
9 | 9 |
import org.apache.commons.logging.LogFactory; |
10 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 11 |
import org.springframework.web.bind.annotation.RequestMapping; |
12 | 12 |
import org.springframework.web.bind.annotation.RequestMethod; |
13 | 13 |
import org.springframework.web.bind.annotation.RestController; |
14 |
import org.springframework.web.method.HandlerMethod; |
|
15 |
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; |
|
16 | 14 |
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; |
17 | 15 |
|
18 | 16 |
/** |
... | ... | |
28 | 26 |
|
29 | 27 |
@RequestMapping(value = "/endpointdoc", method = RequestMethod.GET) |
30 | 28 |
public Set<String> show() { |
31 |
|
|
32 |
final Set<String> res = Sets.newHashSet(); |
|
33 |
for(RequestMappingHandlerMapping handler : handlerMappings) { |
|
34 |
|
|
35 |
for(Entry<RequestMappingInfo, HandlerMethod> e : handler.getHandlerMethods().entrySet()) { |
|
36 |
final RequestMappingInfo info = e.getKey(); |
|
37 |
res.add(info.toString()); |
|
38 |
} |
|
39 |
} |
|
40 |
return res; |
|
29 |
return handlerMappings.stream() |
|
30 |
.map(h -> h.getHandlerMethods().entrySet().stream() |
|
31 |
.map(m -> m.getKey()) |
|
32 |
.map(i -> i.toString())) |
|
33 |
.reduce(Stream::concat) |
|
34 |
.orElseGet(Stream::empty) |
|
35 |
.collect(Collectors.toSet()); |
|
41 | 36 |
} |
42 | 37 |
|
43 | 38 |
} |
Also available in: Unified diff
implemented using java8 functional methods