Skip to content

Commit 69b64f6

Browse files
authored
added support of jakartaee to jaxws plugin (elastic#2247)
* added support of jakartaee to jaxws plugin * replaced named with namedOneOf. Added entry to changelog * added common AbstractJaxWsInstrumentationTest * make test class abstract * added creating test jar
1 parent b9be1ea commit 69b64f6

File tree

9 files changed

+180
-26
lines changed

9 files changed

+180
-26
lines changed

CHANGELOG.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ by the agent may be different. This was done in order to improve the integration
4848
* Added <<config-span-stack-trace-min-duration,`span_stack_trace_min_duration`>> option.
4949
This replaces the now deprecated `span_frames_min_duration` option.
5050
The difference is that the new option has more intuitive semantics for negative values (never collect stack trace) and zero (always collect stack trace). - {pull}2220[#2220]
51+
* Add support to Jakarta EE for JAX-WS - {pull}2247[#2247]
5152
5253
[float]
5354
===== Performance improvements

apm-agent-core/src/main/java/co/elastic/apm/agent/report/CountingOutputStream.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
119
package co.elastic.apm.agent.report;
220

321
import javax.annotation.Nonnull;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>apm-agent-plugins</artifactId>
7+
<groupId>co.elastic.apm</groupId>
8+
<version>1.26.1-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>apm-jaxws-plugin-jakartaee-test</artifactId>
13+
<name>${project.groupId}:${project.artifactId}</name>
14+
15+
<properties>
16+
<apm-agent-parent.base.dir>${project.basedir}/../..</apm-agent-parent.base.dir>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>jakarta.platform</groupId>
22+
<artifactId>jakarta.jakartaee-api</artifactId>
23+
<version>9.0.0</version>
24+
<scope>test</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>${project.groupId}</groupId>
28+
<artifactId>apm-jaxws-plugin</artifactId>
29+
<version>${project.version}</version>
30+
<scope>test</scope>
31+
</dependency>
32+
<dependency>
33+
<groupId>${project.groupId}</groupId>
34+
<artifactId>apm-jaxws-plugin</artifactId>
35+
<version>${project.version}</version>
36+
<type>test-jar</type>
37+
<scope>test</scope>
38+
</dependency>
39+
</dependencies>
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package co.elastic.apm.agent.jaxws;
20+
21+
import jakarta.jws.WebMethod;
22+
import jakarta.jws.WebService;
23+
import jakarta.jws.soap.SOAPBinding;
24+
import org.junit.jupiter.api.BeforeEach;
25+
26+
class JakartaeeJaxWsTransactionNameInstrumentationTest extends AbstractJaxWsInstrumentationTest {
27+
28+
@BeforeEach
29+
void setUp() {
30+
helloWorldService = new HelloWorldServiceImpl();
31+
}
32+
33+
@SOAPBinding(style = SOAPBinding.Style.RPC)
34+
@WebService(targetNamespace = "elastic")
35+
public interface HelloWorldService extends BaseHelloWorldService {
36+
@WebMethod
37+
String sayHello();
38+
}
39+
40+
@WebService(serviceName = "HelloWorldService", portName = "HelloWorld", name = "HelloWorld",
41+
endpointInterface = "co.elastic.apm.agent.jaxws.JaxWsTransactionNameInstrumentationTest.HelloWorldService",
42+
targetNamespace = "elastic")
43+
public static class HelloWorldServiceImpl implements HelloWorldService {
44+
@Override
45+
public String sayHello() {
46+
return "Hello World";
47+
}
48+
}
49+
50+
}

apm-agent-plugins/apm-jaxws-plugin/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,19 @@
2424
</dependency>
2525
</dependencies>
2626

27+
28+
<build>
29+
<plugins>
30+
<plugin>
31+
<artifactId>maven-jar-plugin</artifactId>
32+
<executions>
33+
<execution>
34+
<goals>
35+
<goal>test-jar</goal>
36+
</goals>
37+
</execution>
38+
</executions>
39+
</plugin>
40+
</plugins>
41+
</build>
2742
</project>

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
4141
import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader;
4242
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
43-
import static net.bytebuddy.matcher.ElementMatchers.named;
43+
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
4444
import static net.bytebuddy.matcher.ElementMatchers.not;
4545

4646
public class JaxWsTransactionNameInstrumentation extends TracerAwareInstrumentation {
@@ -76,20 +76,21 @@ public ElementMatcher<? super TypeDescription> getTypeMatcher() {
7676
// the implementations have to be annotated as well
7777
// quote from javadoc:
7878
// "Marks a Java class as implementing a Web Service, or a Java interface as defining a Web Service interface."
79-
return isAnnotatedWith(named("javax.jws.WebService")).and(not(isInterface()));
79+
return isAnnotatedWith(namedOneOf("javax.jws.WebService", "jakarta.jws.WebService")).and(not(isInterface()));
8080
}
8181

8282
@Override
8383
public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
8484
return not(isBootstrapClassLoader())
85-
.and(classLoaderCanLoadClass("javax.jws.WebService"));
85+
.and(classLoaderCanLoadClass("javax.jws.WebService")
86+
.or(classLoaderCanLoadClass("jakarta.jws.WebService")));
8687
}
8788

8889
@Override
8990
public ElementMatcher<? super MethodDescription> getMethodMatcher() {
9091
return overridesOrImplementsMethodThat(
9192
isAnnotatedWith(
92-
named("javax.jws.WebMethod")))
93+
namedOneOf("javax.jws.WebMethod", "jakarta.jws.WebMethod")))
9394
.onSuperClassesThat(isInAnyPackage(applicationPackages, ElementMatchers.<NamedElement>any()));
9495
}
9596

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package co.elastic.apm.agent.jaxws;
20+
21+
import co.elastic.apm.agent.AbstractInstrumentationTest;
22+
import co.elastic.apm.agent.impl.Scope;
23+
import co.elastic.apm.agent.impl.transaction.Transaction;
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
public abstract class AbstractJaxWsInstrumentationTest extends AbstractInstrumentationTest {
29+
30+
protected BaseHelloWorldService helloWorldService;
31+
32+
@Test
33+
void testTransactionName() {
34+
final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader());
35+
try (Scope scope = transaction.activateInScope()) {
36+
helloWorldService.sayHello();
37+
} finally {
38+
transaction.end();
39+
}
40+
assertThat(transaction.getNameAsString()).isEqualTo("HelloWorldServiceImpl#sayHello");
41+
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
42+
}
43+
44+
public interface BaseHelloWorldService {
45+
String sayHello();
46+
}
47+
}

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,23 @@
1818
*/
1919
package co.elastic.apm.agent.jaxws;
2020

21-
import co.elastic.apm.agent.AbstractInstrumentationTest;
22-
import co.elastic.apm.agent.impl.Scope;
23-
import co.elastic.apm.agent.impl.transaction.Transaction;
2421
import org.junit.jupiter.api.BeforeEach;
25-
import org.junit.jupiter.api.Test;
2622

2723
import javax.jws.WebMethod;
2824
import javax.jws.WebService;
2925
import javax.jws.soap.SOAPBinding;
3026

31-
import static org.assertj.core.api.Assertions.assertThat;
32-
33-
class JaxWsTransactionNameInstrumentationTest extends AbstractInstrumentationTest {
34-
35-
private HelloWorldService helloWorldService;
27+
class JaxWsTransactionNameInstrumentationTest extends AbstractJaxWsInstrumentationTest {
3628

3729
@BeforeEach
3830
void setUp() {
3931
helloWorldService = new HelloWorldServiceImpl();
4032
}
4133

42-
@Test
43-
void testTransactionName() {
44-
final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader());
45-
try (Scope scope = transaction.activateInScope()) {
46-
helloWorldService.sayHello();
47-
} finally {
48-
transaction.end();
49-
}
50-
assertThat(transaction.getNameAsString()).isEqualTo("HelloWorldServiceImpl#sayHello");
51-
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
52-
}
53-
5434
@SOAPBinding(style = SOAPBinding.Style.RPC)
5535
@WebService(targetNamespace = "elastic")
56-
public interface HelloWorldService {
36+
public interface HelloWorldService extends BaseHelloWorldService {
37+
@Override
5738
@WebMethod
5839
String sayHello();
5940
}

apm-agent-plugins/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<module>apm-sparkjava-plugin</module>
6666
<module>apm-javalin-plugin</module>
6767
<module>apm-servlet-jakarta-test</module>
68+
<module>apm-jaxws-plugin-jakartaee-test</module>
6869
</modules>
6970

7071
<dependencies>

0 commit comments

Comments
 (0)