Last active
July 23, 2019 14:42
-
-
Save mastern2k3/5c56301f34558ae83e6709f7d2230bbb to your computer and use it in GitHub Desktop.
Super simple spring index controller for available paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.Stream; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RestController; | |
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | |
@RestController | |
@RequestMapping(path = "") | |
public class HomeController { | |
private static String template = | |
"<html><body><pre>\n" + | |
"Welcome\n" + | |
"==================\n\n" + | |
"%s" + | |
"</pre></body></html>"; | |
@Autowired | |
private ApplicationContext appContext; | |
@GetMapping(path="", produces = "text/html") | |
public String getEmployees() { | |
Stream<String> names = | |
appContext.getBean(RequestMappingHandlerMapping.class).getHandlerMethods().keySet().stream() | |
.flatMap(m -> m.getPatternsCondition().getPatterns().stream()) | |
.filter(p -> !p.isEmpty() && !p.startsWith("/error")); | |
return String.format(template, String.join("\n", (Iterable<String>)names::iterator)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment