Skip to content

Commit

Permalink
Add support for jax-ws method annotated with @webmethod not declared …
Browse files Browse the repository at this point in the history
…by super-interfaces (#3850)
  • Loading branch information
JonasKunz authored Nov 18, 2024
1 parent 7faedf2 commit 17cd358
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Use subheadings with the "=====" level for adding notes for unreleased changes:
[float]
===== Bug fixes
* Fix JMX metric warning message about unsupported composite value types - {pull}3849[#3849]
* Fix JAX-WS transaction naming for @WebMethod annotated methods - {pull}3850[#3850]
[[release-notes-1.x]]
=== Java Agent version 1.x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package co.elastic.apm.agent.jaxws;

import jakarta.jws.WebMethod;
import jakarta.jws.WebService;
import jakarta.jws.soap.SOAPBinding;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -42,6 +43,11 @@ public static class HelloWorldServiceImpl implements HelloWorldService {
public String sayHello() {
return "Hello World";
}

@WebMethod
public String webMethodAnnotated() {
return "foo bar";
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@
*/
package co.elastic.apm.agent.jaxws;

import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature;
import co.elastic.apm.agent.sdk.ElasticApmInstrumentation;
import co.elastic.apm.agent.sdk.bytebuddy.MethodHierarchyMatcher;
import co.elastic.apm.agent.sdk.bytebuddy.SimpleMethodSignatureOffsetMappingFactory.SimpleMethodSignature;
import co.elastic.apm.agent.tracer.GlobalTracer;
import co.elastic.apm.agent.tracer.Tracer;
import co.elastic.apm.agent.tracer.Transaction;
Expand Down Expand Up @@ -94,13 +95,19 @@ public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {

@Override
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
return overridesOrImplementsMethodThat(
MethodHierarchyMatcher annotatedMethodMatcher = overridesOrImplementsMethodThat(
isAnnotatedWith(
namedOneOf("javax.jws.WebMethod", "jakarta.jws.WebMethod")))
.onSuperClassesThat(isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any()));

MethodHierarchyMatcher interfaceInheritedMatcher = overridesOrImplementsMethodThat(
isPublic().and(isDeclaredBy(isInterface()))
).whereHierarchyContains(
isInterface().and(isAnnotatedWith(namedOneOf("javax.jws.WebService", "jakarta.jws.WebService")))
).onSuperClassesThat(
isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any())
);
return interfaceInheritedMatcher.or(annotatedMethodMatcher);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ void testTransactionName() {
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
}


@Test
void testTransactionNameForWebMethod() throws Exception {
final TransactionImpl transaction = tracer.startRootTransaction(getClass().getClassLoader());
try (Scope scope = transaction.activateInScope()) {
helloWorldService.getClass().getMethod("webMethodAnnotated").invoke(helloWorldService);
} finally {
transaction.end();
}
assertThat(transaction.getNameAsString()).isEqualTo("HelloWorldServiceImpl#webMethodAnnotated");
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
}

public interface BaseHelloWorldService {
String sayHello();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public static class HelloWorldServiceImpl implements HelloWorldService {
public String sayHello() {
return "Hello World";
}

@WebMethod
public String webMethodAnnotated() {
return "foo bar";
}
}

}

0 comments on commit 17cd358

Please sign in to comment.