Skip to content

Commit 17cd358

Browse files
authored
Add support for jax-ws method annotated with @webmethod not declared by super-interfaces (#3850)
1 parent 7faedf2 commit 17cd358

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

CHANGELOG.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
3434
[float]
3535
===== Bug fixes
3636
* Fix JMX metric warning message about unsupported composite value types - {pull}3849[#3849]
37+
* Fix JAX-WS transaction naming for @WebMethod annotated methods - {pull}3850[#3850]
3738
3839
[[release-notes-1.x]]
3940
=== Java Agent version 1.x

apm-agent-plugins/apm-jaxws-plugin-jakartaee-test/src/test/java/co/elastic/apm/agent/jaxws/JakartaeeJaxWsTransactionNameInstrumentationTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package co.elastic.apm.agent.jaxws;
2020

21+
import jakarta.jws.WebMethod;
2122
import jakarta.jws.WebService;
2223
import jakarta.jws.soap.SOAPBinding;
2324
import org.junit.jupiter.api.BeforeEach;
@@ -42,6 +43,11 @@ public static class HelloWorldServiceImpl implements HelloWorldService {
4243
public String sayHello() {
4344
return "Hello World";
4445
}
46+
47+
@WebMethod
48+
public String webMethodAnnotated() {
49+
return "foo bar";
50+
}
4551
}
4652

4753
}

apm-agent-plugins/apm-jaxws-plugin/src/main/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentation.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
*/
1919
package co.elastic.apm.agent.jaxws;
2020

21-
import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature;
2221
import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
22+
import co.elastic.apm.agent.sdk.bytebuddy.MethodHierarchyMatcher;
23+
import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature;
2324
import co.elastic.apm.agent.tracer.GlobalTracer;
2425
import co.elastic.apm.agent.tracer.Tracer;
2526
import co.elastic.apm.agent.tracer.Transaction;
@@ -94,13 +95,19 @@ public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
9495

9596
@Override
9697
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
97-
return overridesOrImplementsMethodThat(
98+
MethodHierarchyMatcher annotatedMethodMatcher = overridesOrImplementsMethodThat(
99+
isAnnotatedWith(
100+
namedOneOf("javax.jws.WebMethod", "jakarta.jws.WebMethod")))
101+
.onSuperClassesThat(isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any()));
102+
103+
MethodHierarchyMatcher interfaceInheritedMatcher = overridesOrImplementsMethodThat(
98104
isPublic().and(isDeclaredBy(isInterface()))
99105
).whereHierarchyContains(
100106
isInterface().and(isAnnotatedWith(namedOneOf("javax.jws.WebService", "jakarta.jws.WebService")))
101107
).onSuperClassesThat(
102108
isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any())
103109
);
110+
return interfaceInheritedMatcher.or(annotatedMethodMatcher);
104111
}
105112

106113
@Override

apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/AbstractJaxWsInstrumentationTest.java

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ void testTransactionName() {
4141
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
4242
}
4343

44+
45+
@Test
46+
void testTransactionNameForWebMethod() throws Exception {
47+
final TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader());
48+
try (Scope scope = transaction.activateInScope()) {
49+
helloWorldService.getClass().getMethod("webMethodAnnotated").invoke(helloWorldService);
50+
} finally {
51+
transaction.end();
52+
}
53+
assertThat(transaction.getNameAsString()).isEqualTo("HelloWorldServiceImpl#webMethodAnnotated");
54+
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
55+
}
56+
4457
public interface BaseHelloWorldService {
4558
String sayHello();
4659
}

apm-agent-plugins/apm-jaxws-plugin/src/test/java/co/elastic/apm/agent/jaxws/JaxWsTransactionNameInstrumentationTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public static class HelloWorldServiceImpl implements HelloWorldService {
4747
public String sayHello() {
4848
return "Hello World";
4949
}
50+
51+
@WebMethod
52+
public String webMethodAnnotated() {
53+
return "foo bar";
54+
}
5055
}
5156

5257
}

0 commit comments

Comments
 (0)