默认情况下,Togglz管理控制台在应用程序端口上运行(由server.port
属性配置)。我希望将其公开在management.port
上。我的问题是:这可行吗?
默认情况下,Togglz管理控制台在应用程序端口上运行(由server.port
属性配置)。我希望将其公开在management.port
上。我的问题是:这可行吗?
public class HystrixStreamEndpoint extends ServletWrappingEndpoint {
public HystrixStreamEndpoint() {
super(HystrixMetricsStreamServlet.class, "hystrixStream", "/hystrix.stream",
true, true);
}
}
TogglzConsoleServlet
的情况比较特殊,由于它从请求URI中提取前缀的方式,因此需要进行一些有关路径的额外处理,所以整个解决方案看起来有点丑陋:
@Component
class TogglzConsoleEndpoint implements MvcEndpoint {
private static final String ADMIN_CONSOLE_URL = "/togglz-console";
private final TogglzConsoleServlet togglzConsoleServlet;
@Autowired
TogglzConsoleEndpoint(final ServletContext servletContext) throws ServletException {
this.togglzConsoleServlet = new TogglzConsoleServlet();
togglzConsoleServlet.init(new DelegatingServletConfig(servletContext));
}
@Override
public String getPath() {
return ADMIN_CONSOLE_URL;
}
@Override
public boolean isSensitive() {
return true;
}
@Override
public Class<? extends Endpoint> getEndpointType() {
return null;
}
@RequestMapping("**")
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response) throws Exception {
HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(request) {
@Override
public String getServletPath() {
return ADMIN_CONSOLE_URL;
}
};
togglzConsoleServlet.service(requestWrapper, response);
return null;
}
private class DelegatingServletConfig implements ServletConfig {
private final ServletContext servletContext;
DelegatingServletConfig(final ServletContext servletContext) {
this.servletContext = servletContext;
}
@Override
public String getServletName() {
return TogglzConsoleEndpoint.this.togglzConsoleServlet.getServletName();
}
@Override
public ServletContext getServletContext() {
return servletContext;
}
@Override
public String getInitParameter(final String name) {
return servletContext.getInitParameter(name);
}
@Override
public Enumeration<String> getInitParameterNames() {
return servletContext.getInitParameterNames();
}
}
}