Document CF actuator limitation if context-path changes
Closes gh-9081
This commit is contained in:
parent
b5c4ce230d
commit
d0a2613241
|
|
@ -1432,6 +1432,53 @@ include::{code-examples}/cloudfoundry/CloudFoundryIgnorePathsExample.java[tag=se
|
|||
|
||||
|
||||
|
||||
=== Custom context path
|
||||
|
||||
If the server's context-path has been configured to anything other then `/`, the Cloud Foundry endpoints
|
||||
will not be available at the root of the application. For example, if `server.servlet.context-path=/foo`,
|
||||
Cloud Foundry endpoints will be available at `/foo/cloudfoundryapplication/*`.
|
||||
|
||||
If you expect the Cloud Foundry endpoints to always be available at `/cloudfoundryapplication/*`, regardless of
|
||||
the server's context-path, you will need to explicitly configure that in your application. The configuration will differ
|
||||
depending on the web server in use. For Tomcat, the following configuration can be added:
|
||||
|
||||
[source,java,indent=0]
|
||||
----
|
||||
@Bean
|
||||
public TomcatEmbeddedServletContainerFactory servletContainerFactory() {
|
||||
return new TomcatEmbeddedServletContainerFactory() {
|
||||
@Override
|
||||
protected void prepareContext(Host host,
|
||||
ServletContextInitializer[] initializers) {
|
||||
super.prepareContext(host, initializers);
|
||||
StandardContext child = new StandardContext();
|
||||
child.addLifecycleListener(new Tomcat.FixContextListener());
|
||||
child.setPath("/cloudfoundryapplication");
|
||||
ServletContainerInitializer initializer = getServletContextInitializer(getContextPath());
|
||||
child.addServletContainerInitializer(initializer, Collections.emptySet());
|
||||
child.setCrossContext(true);
|
||||
host.addChild(child);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private ServletContainerInitializer getServletContextInitializer(String contextPath) {
|
||||
return (c, context) -> {
|
||||
Servlet servlet = new GenericServlet() {
|
||||
@Override
|
||||
public void service(ServletRequest req, ServletResponse res)
|
||||
throws ServletException, IOException {
|
||||
ServletContext context = req.getServletContext().getContext(contextPath);
|
||||
context.getRequestDispatcher("/cloudfoundryapplication").forward(req, res);
|
||||
}
|
||||
};
|
||||
context.addServlet("cloudfoundry", servlet).addMapping("/*");
|
||||
};
|
||||
}
|
||||
----
|
||||
|
||||
|
||||
|
||||
[[production-ready-whats-next]]
|
||||
== What to Read Next
|
||||
If you want to explore some of the concepts discussed in this chapter, you can take a
|
||||
|
|
|
|||
Loading…
Reference in New Issue