# Tomcat elastic-apm-agent, and application version in context path fails on ProtectionDomain

**URL:** <https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899>\
**Category:** APM\
**Tags:** java\
**Created:** [June 9, 2019, 10:05pm UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899 "2019-06-09T22:05:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_harris/32/47773_2.png) [@Paul\_Harris](https://discuss.elastic.co/u/Paul_Harris)\
**Post date:** [June 9, 2019, 10:05pm UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/1 "2019-06-09T22:05:27Z")

</div>

I'm currently configuring a Java app in tomcat7 to use elastic-apm-agent.  
Java - elastic-apm-agent-1.6.1  
Tomcat is running on a linux ec2-instance, its' currently at tomcat-7.0.94.

I've copied the agent in, added the configuration to my tomcat7.conf, and started the tomcat service, and in catalina.out i get:  
2019-06-10 07:38:47.860 [localhost-startStop-1] ERROR  
co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers - Cannot read implementation  
version based on ProtectionDomain ProtectionDomain  
(file:/var/lib/tomcat7/webapps/portal%23%23k000226/WEB-INF/lib/httpclient-4.5.2.jar )  
WebappClassLoader  
context: /portal##k000226  
delegate: false  
repositories:  
/WEB-INF/classes/  
----------\> Parent Classloader:  
java.net.URLClassLoader@2f490758

```
 <no principals>
 java.security.Permissions@31421bfe (
 ("java.io.FilePermission" "/var/lib/tomcat7/webapps/portal##k000226/WEB-INF/lib/httpclient-4.5.2.jar" "read")
)

```

If i remove the application version from the deployed war, this problem goes away. It seems like the filename is corrupted when checking for ProtectionDomain? Is there any other way I can get this to work and still retain the application version in the context path?

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [June 10, 2019, 9:31am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/2 "2019-06-10T09:31:32Z")

</div>

Hi and welcome to the forum 🙂

I think I better change the behavior so that if version is not found, we default to instrument, so we at least attempt (in this case there will be no harm in any case).

Still, can you please provide the full related log entry? The log section you added should be followed by an Exception and stack trace.

---

<div class="post-metadata">

**Author:** ![Paul\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_harris/32/47773_2.png) [@Paul\_Harris](https://discuss.elastic.co/u/Paul_Harris)\
**Post date:** [June 10, 2019, 9:48am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/3 "2019-06-10T09:48:38Z")

</div>

Ok yep I can get that tomorrow, time zone beat me today!  
The bit that didn’t format above with the same file but %23 instead of hash where it said protectiondomain I think is the root cause, it looks to have URL encoded a file path, that’s not right I think? Certainly if I try to ‘ls’ that path, the shell can’t locate it....

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [June 10, 2019, 10:22am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/4 "2019-06-10T10:22:21Z")

</div>

It may very well be the case, so decoding is an optional solution. I just want to see what we actually logged, as it should direct us.

---

<div class="post-metadata">

**Author:** ![Paul\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_harris/32/47773_2.png) [@Paul\_Harris](https://discuss.elastic.co/u/Paul_Harris)\
**Post date:** [June 10, 2019, 9:16pm UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/5 "2019-06-10T21:16:31Z")

</div>

```auto
2019-06-10T07:38:11.439+1000: [CMS-concurrent-abortable-preclean-start]
2019-06-10 07:38:14.108 [localhost-startStop-1] ERROR co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers - Cannot read implementation version based on ProtectionDomain ProtectionDomain (file:/var/lib/tomcat7/webapps/v4%23%23k000306/WEB-INF/lib/httpclient-4.5.6.jar <no signer certificates>)
 WebappClassLoader^M
  context: /v4##k000306^M
  delegate: false^M
  repositories:^M
    /WEB-INF/classes/^M
----------> Parent Classloader:^M
java.net.URLClassLoader@2f490758^M

 <no principals>
 java.security.Permissions@2a51013e (
 ("java.io.FilePermission" "/var/lib/tomcat7/webapps/v4##k000306/WEB-INF/lib/httpclient-4.5.6.jar" "read")
)

java.io.FileNotFoundException: /var/lib/tomcat7/webapps/v4%23%23k000306/WEB-INF/lib/httpclient-4.5.6.jar (No such file or directory)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(ZipFile.java:225)
        at java.util.zip.ZipFile.<init>(ZipFile.java:155)
        at java.util.jar.JarFile.<init>(JarFile.java:166)
        at java.util.jar.JarFile.<init>(JarFile.java:103)
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.readImplementationVersionFromManifest(CustomElementMatchers.java:152)
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers.access$100(CustomElementMatchers.java:44)
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers$2.matches(CustomElementMatchers.java:128)
        at co.elastic.apm.agent.bci.bytebuddy.CustomElementMatchers$2.matches(CustomElementMatchers.java:125)
        at co.elastic.apm.agent.bci.ElasticApmAgent$4.matches(ElasticApmAgent.java:187)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple.matches(AgentBuilder.java:9983)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Simple.resolve(AgentBuilder.java:9996)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$Transformation$Compound.resolve(AgentBuilder.java:10252)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.resolve(AgentBuilder.java:10584)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:10551)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10514)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1500(AgentBuilder.java:10280)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10889)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$LegacyVmDispatcher.run(AgentBuilder.java:10836)
        at java.security.AccessController.doPrivileged(Native Method)
        at co.elastic.apm.agent.shaded.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:10437)
        at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
        at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:3222)
        at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:1409)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1897)
        at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1771)
        at org.apache.http.impl.nio.client.HttpAsyncClients.createSystem(HttpAsyncClients.java:70)
        at org.springframework.http.client.HttpComponentsAsyncClientHttpRequestFactory.<init>(HttpComponentsAsyncClientHttpRequestFactory.java:58)
        at com.pds.common.http.AbstractHttpClient.<clinit>(AbstractHttpClient.java:174)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147)

```

different app, same issue... (hence portal from above is now v4)  
In case it is important - this is tomcat 7.0.94...

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [June 11, 2019, 8:50am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/6 "2019-06-11T08:50:55Z")

</div>

Thanks for log. It is indeed the encoding.  
Please test [this snapshot](http://src/github.com/elastic/apm-agent-java/elastic-apm-agent/target/elastic-apm-agent-1.6.2-SNAPSHOT.jar) and see if it fixes the problem.  
Thanks,  
Eyal.

---

<div class="post-metadata">

**Author:** ![Paul\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_harris/32/47773_2.png) [@Paul\_Harris](https://discuss.elastic.co/u/Paul_Harris)\
**Post date:** [June 11, 2019, 9:04pm UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/7 "2019-06-11T21:04:54Z")

</div>

I'd love to test it, but the link doesn't seem to be valid?

I tried the snapshot link and got elastic-apm-agent-1.6.2-20190611.093948-46.jar, but that didnt seem to include your fix, or didn't work if it did... Having a look at the code, i'd say it didn't include your fix...

I tried to build it but I'm using JDK8 so its not so simple 😕

Cheers,

Paul.

---

<div class="post-metadata">

**Author:** ![Eyal\_Koren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eyal_koren/32/36830_2.png) [@Eyal\_Koren](https://discuss.elastic.co/u/Eyal_Koren)\
**Post date:** [June 12, 2019, 5:08am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/8 "2019-06-12T05:08:29Z")

</div>

Sorry, corrupted link 🤦‍♂️  
Please try [this one](https://apm-ci.elastic.co/job/apm-agent-java/job/apm-agent-java-mbp/job/PR-658/3/artifact/src/github.com/elastic/apm-agent-java/elastic-apm-agent/target/elastic-apm-agent-1.6.2-SNAPSHOT.jar) instead.  
In any case, we will probably release 1.7.0 this week, which should fix this.

---

<div class="post-metadata">

**Author:** ![Paul\_Harris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_harris/32/47773_2.png) [@Paul\_Harris](https://discuss.elastic.co/u/Paul_Harris)\
**Post date:** [June 12, 2019, 5:19am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/9 "2019-06-12T05:19:18Z")

</div>

Hi Eyal,  
Thanks for the new link - i tried that new snapshot and it's resolved the issue!

Cheers,

Paul.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 3, 2019, 1:19am UTC](https://discuss.elastic.co/t/tomcat-elastic-apm-agent-and-application-version-in-context-path-fails-on-protectiondomain/184899/10 "2019-07-03T01:19:26Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
