Skip to content

Conversation

@SylvainJuge
Copy link
Member

@SylvainJuge SylvainJuge commented Oct 30, 2020

What does this PR do?

Deploying https://github.com/spring-petclinic/spring-framework-petclinic application on a Tomcat server 9.0.x produces the following exception on startup:

java.lang.UnsupportedOperationException

java.lang.UnsupportedOperationException: Section 4.4 of the Servlet 3.0 specification does not permit this method to be called from a ServletContextListener that was not defined in web.xml, a web-fragment.xml file nor annotated with @WebListener at org.apache.catalina.core.StandardContext$NoPluggabilityServletContext.getClassLoader(StandardContext.java:6675) at co.elastic.apm.agent.springwebmvc.SpringServiceNameInstrumentation$SpringServiceNameAdvice.afterInitPropertySources(SpringServiceNameInstrumentation.java:75) at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.initPropertySources(AbstractRefreshableWebApplicationContext.java:214) at org.springframework.context.support.AbstractApplicationContext.prepareRefresh(AbstractApplicationContext.java:600) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:519) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:401) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:292) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4676) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5139) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:706) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1848) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112) at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:773) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:427) at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1576) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:309) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123) at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423) at org.apache.catalina.util.LifecycleBase.setState(LifecycleBase.java:366) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:936) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:843) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1384) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1374) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) 

On top of that, we can already initialize the application name with getApplicationName() method on the application context.

Checklist

  • This is a bugfix
Copy link
Member

@felixbarny felixbarny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A minor comment. Otherwise LGTM.


// fallback when application name isn't set through an environment property
if (appName.isEmpty()) {
appName = applicationContext.getApplicationName();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better guard against null. I've seen servletContext.getContextPath() return null on some application servers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also wondering should we make this work for older versions of Spring framework < 3.x

@codecov-io
Copy link

codecov-io commented Oct 30, 2020

Codecov Report

Merging #1464 into master will decrease coverage by 0.00%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@ ## master #1464 +/- ## ============================================ - Coverage 59.73% 59.72% -0.01%  Complexity 91 91 ============================================ Files 391 391 Lines 17528 17540 +12 Branches 2408 2411 +3 ============================================ + Hits 10470 10476 +6  - Misses 6340 6347 +7  + Partials 718 717 -1 
Impacted Files Coverage Δ Complexity Δ
...springwebmvc/SpringServiceNameInstrumentation.java 27.27% <0.00%> (-32.73%) 0.00 <0.00> (ø)
...va/co/elastic/apm/agent/impl/ElasticApmTracer.java 66.03% <100.00%> (ø) 0.00 <0.00> (ø)
...va/co/elastic/apm/agent/impl/transaction/Span.java 82.14% <100.00%> (ø) 0.00 <0.00> (ø)
...o/elastic/apm/agent/profiler/SamplingProfiler.java 72.96% <0.00%> (+0.23%) 0.00% <0.00%> (ø%)
...ic/apm/agent/profiler/collections/LongHashSet.java 17.85% <0.00%> (+1.98%) 0.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 640696b...6f51ae6. Read the comment docs.

@ghost
Copy link

ghost commented Oct 30, 2020

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: [Pull request #1464 updated]

  • Start Time: 2020-11-03T09:57:50.233+0000

  • Duration: 45 min 1 sec

Test stats 🧪

Test Results
Failed 0
Passed 1617
Skipped 12
Total 1629

@SylvainJuge SylvainJuge merged commit 7eeda88 into elastic:master Nov 3, 2020
@SylvainJuge SylvainJuge deleted the fix-spring-app-name-startup-exception branch November 3, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants