Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cloudfoundry specific actuators should not be affected if server.context-path is changed #9081

Closed
mbhave opened this issue May 3, 2017 · 15 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@mbhave
Copy link
Contributor

mbhave commented May 3, 2017

No description provided.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 3, 2017
@mbhave mbhave added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels May 3, 2017
@mbhave mbhave added this to the 1.5.4 milestone May 3, 2017
@mbhave mbhave added priority: normal status: on-hold We can't start working on this issue yet and removed priority: high labels May 25, 2017
@mbhave mbhave modified the milestones: 2.0.0, 1.5.4 May 25, 2017
@mbhave
Copy link
Contributor Author

mbhave commented May 25, 2017

It turned out too be quite a big change for 1.5.4. We can revisit this in 2.0

@zmb3
Copy link

zmb3 commented Jun 13, 2017

It would be really nice to support context path in 1.5.X. Upgrading to 2.0 may be a challenge for larger organizations, especially those that haven't made the move to Java 8 yet. Are there any workarounds for the folks on 1.5 until this is revisited?

@mbhave
Copy link
Contributor Author

mbhave commented Jun 13, 2017

@zmb3 For 1.5.3, the workaround is to add a new context that can handle requests to "/cloudfoundryapplication" and forward them to the original context. Here's the example for tomcat.

@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("/*");
	};
}

@sworisbreathing
Copy link

sworisbreathing commented Sep 27, 2017

As an alternative, is there a way to tell cloudfoundry the correct path for the /cloudfoundryapplication endpoint via some other means (i.e. in the manifest file?) I've had a peek through the https://github.com/cloudfoundry/java-buildpack repo but couldn't find any references to this path in the code. It's bound to be specified/hard-coded somewhere in Cloudfoundry but I can't seem to find it.

@toplac
Copy link

toplac commented Oct 25, 2017

@mbhave I tried your suggestion using Spring Boot 1.5.4 , but I am recieving a null pointer exception. Am i missing something?

2017-10-25T11:00:34.161+02:00 [RTR/0] [OUT] - [2017-10-25T09:00:34.156+0000] "OPTIONS /cloudfoundryapplication HTTP/1.1" 500 0 1310 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0" "10.26.193.153:37166" "10.26.199.14:61165" x_forwarded_for:"-" x_forwarded_proto:"https" vcap_request_id:"0734725c-705e-404f-6c5c-05c162ec0bea" response_time:0.00441584 app_id:"88cc883c-0c48-41c2-a463-5000317ec029" app_index:"0" x_b3_traceid:"4a0b63b5c40bc6ba" x_b3_spanid:"4a0b63b5c40bc6ba" x_b3_parentspanid:"-"
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] [09:01:04.008] ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/cloudfoundryapplication].[cloudfoundry] [http-nio-8080-exec-10]: Servlet.service() for servlet [cloudfoundry] in context with path [/cloudfoundryapplication] threw exception
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at foo.org.context.TomcatConfiguration$2.service(TomcatConfiguration.java:48) ~[edge-chassis-0-SNAPSHOT.jar!/:0-SNAPSHOT]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] java.lang.NullPointerException: null
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:677) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar!/:8.5.11]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_141]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_141]
2017-10-25T11:01:04.009+02:00 [APP/PROC/WEB/0] [OUT] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]

@wilkinsona
Copy link
Member

@toplac Are you sure you're using Spring Boot 1.5.4? It uses Tomcat 8.5.15 by default but your stack trace indicates that you're using 8.5.11.

@toplac
Copy link

toplac commented Oct 25, 2017

@wilkinsona Thanks for the hint. There was an indeed an error in my pom.xml. I have fixed the dependency issue, but i still get the same error:

ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/cloudfoundryapplication].[cloudfoundry] [http-nio-8080-exec-6]: Servlet.service() for servlet [cloudfoundry] in context with path [/cloudfoundryapplication] threw exception
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] java.lang.NullPointerException: null
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at foo.org.context.TomcatConfiguration$2.service(TomcatConfiguration.java:48) ~[edge-chassis-0-SNAPSHOT.jar!/:0-SNAPSHOT]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:677) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_141]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_141]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.15.jar!/:8.5.15]
2017-10-25T14:57:55.983+02:00 [APP/PROC/WEB/1] [OUT] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_141]

@wilkinsona
Copy link
Member

@toplac That NullPointerException is happening in your code that you haven't shared. If you need some help figuring out what's going on, please ask a question on Stack Overflow.

@toplac
Copy link

toplac commented Oct 25, 2017

@wilkinsona I have applied the suggestion from #9081 (comment)

EDIT: We solved it using zuul in combination using "forward"

Here is an example:

routes:
    cloudfoundryapplicationReRoute:
      path: /cloudfoundryapplication/**
      stripPrefix: false
      url: "forward:${server.servlet-path:}"

@wilkinsona wilkinsona added type: documentation A documentation update and removed type: bug A general bug status: on-hold We can't start working on this issue yet labels Oct 27, 2017
@wilkinsona
Copy link
Member

wilkinsona commented Oct 27, 2017

We're going to document this as a known limitation.

@philwebb philwebb modified the milestones: 2.0.0, 2.0.0.RC2 Jan 31, 2018
@mbhave mbhave self-assigned this Feb 1, 2018
@mbhave mbhave closed this as completed in d0a2613 Feb 3, 2018
@mcordeiro73
Copy link

Is there a similar solution to this problem when using the newly introduced spring.webflux.base-path in a reactive application?

@philwebb
Copy link
Member

@mcordeiro73 can you open a new issue for that one please?

@mcordeiro73
Copy link

@mcordeiro73 can you open a new issue for that one please?

New issue created for Reactive based applications #24991

@sathish593
Copy link

is this issue resolved? iam using spring boot 2.6.1 and getting the same error am using undertow, can anyone share a workaround for it, thanks

@mbhave
Copy link
Contributor Author

mbhave commented Sep 6, 2022

@sathish593 This is documented as a known limitation. There would be some undertow-specific configuration similar to Tomcat. Can you open a new issue so that we can look into documenting it for Undertow and Jetty as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

9 participants