Skip to content

added support of jakartaee to jaxws plugin #2247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ by the agent may be different. This was done in order to improve the integration
* Added <<config-span-stack-trace-min-duration,`span_stack_trace_min_duration`>> option.
This replaces the now deprecated `span_frames_min_duration` option.
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]
* Add support to Jakarta EE for JAX-WS - {pull}2247[#2247]

[float]
===== Performance improvements
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.report;

import javax.annotation.Nonnull;
Expand Down
40 changes: 40 additions & 0 deletions apm-agent-plugins/apm-jaxws-plugin-jakartaee-test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>apm-agent-plugins</artifactId>
<groupId>co.elastic.apm</groupId>
<version>1.26.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>apm-jaxws-plugin-jakartaee-test</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

<properties>
<apm-agent-parent.base.dir>${project.basedir}/../..</apm-agent-parent.base.dir>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.platform</groupId>
<artifactId>jakarta.jakartaee-api</artifactId>
<version>9.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-jaxws-plugin</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-jaxws-plugin</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
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;

class JakartaeeJaxWsTransactionNameInstrumentationTest extends AbstractJaxWsInstrumentationTest {

@BeforeEach
void setUp() {
helloWorldService = new HelloWorldServiceImpl();
}

@SOAPBinding(style = SOAPBinding.Style.RPC)
@WebService(targetNamespace = "elastic")
public interface HelloWorldService extends BaseHelloWorldService {
@WebMethod
String sayHello();
}

@WebService(serviceName = "HelloWorldService", portName = "HelloWorld", name = "HelloWorld",
endpointInterface = "co.elastic.apm.agent.jaxws.JaxWsTransactionNameInstrumentationTest.HelloWorldService",
targetNamespace = "elastic")
public static class HelloWorldServiceImpl implements HelloWorldService {
@Override
public String sayHello() {
return "Hello World";
}
}

}
15 changes: 15 additions & 0 deletions apm-agent-plugins/apm-jaxws-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,19 @@
</dependency>
</dependencies>


<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import static net.bytebuddy.matcher.ElementMatchers.isAnnotatedWith;
import static net.bytebuddy.matcher.ElementMatchers.isBootstrapClassLoader;
import static net.bytebuddy.matcher.ElementMatchers.isInterface;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import static net.bytebuddy.matcher.ElementMatchers.not;

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

@Override
public ElementMatcher.Junction<ClassLoader> getClassLoaderMatcher() {
return not(isBootstrapClassLoader())
.and(classLoaderCanLoadClass("javax.jws.WebService"));
.and(classLoaderCanLoadClass("javax.jws.WebService")
.or(classLoaderCanLoadClass("jakarta.jws.WebService")));
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.jaxws;

import co.elastic.apm.agent.AbstractInstrumentationTest;
import co.elastic.apm.agent.impl.Scope;
import co.elastic.apm.agent.impl.transaction.Transaction;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

public abstract class AbstractJaxWsInstrumentationTest extends AbstractInstrumentationTest {

protected BaseHelloWorldService helloWorldService;

@Test
void testTransactionName() {
final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader());
try (Scope scope = transaction.activateInScope()) {
helloWorldService.sayHello();
} finally {
transaction.end();
}
assertThat(transaction.getNameAsString()).isEqualTo("HelloWorldServiceImpl#sayHello");
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
}

public interface BaseHelloWorldService {
String sayHello();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,23 @@
*/
package co.elastic.apm.agent.jaxws;

import co.elastic.apm.agent.AbstractInstrumentationTest;
import co.elastic.apm.agent.impl.Scope;
import co.elastic.apm.agent.impl.transaction.Transaction;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

import static org.assertj.core.api.Assertions.assertThat;

class JaxWsTransactionNameInstrumentationTest extends AbstractInstrumentationTest {

private HelloWorldService helloWorldService;
class JaxWsTransactionNameInstrumentationTest extends AbstractJaxWsInstrumentationTest {

@BeforeEach
void setUp() {
helloWorldService = new HelloWorldServiceImpl();
}

@Test
void testTransactionName() {
final Transaction transaction = tracer.startRootTransaction(getClass().getClassLoader());
try (Scope scope = transaction.activateInScope()) {
helloWorldService.sayHello();
} finally {
transaction.end();
}
assertThat(transaction.getNameAsString()).isEqualTo("HelloWorldServiceImpl#sayHello");
assertThat(transaction.getFrameworkName()).isEqualTo("JAX-WS");
}

@SOAPBinding(style = SOAPBinding.Style.RPC)
@WebService(targetNamespace = "elastic")
public interface HelloWorldService {
public interface HelloWorldService extends BaseHelloWorldService {
@Override
@WebMethod
String sayHello();
}
Expand Down
1 change: 1 addition & 0 deletions apm-agent-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<module>apm-sparkjava-plugin</module>
<module>apm-javalin-plugin</module>
<module>apm-servlet-jakarta-test</module>
<module>apm-jaxws-plugin-jakartaee-test</module>
</modules>

<dependencies>
Expand Down