Skip to content

Commit d536bb5

Browse files
committed
Fix instrumentation for latest axis2
1 parent 11b59d0 commit d536bb5

File tree

17 files changed

+208
-43
lines changed

17 files changed

+208
-43
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
plugins {
2+
id("otel.javaagent-testing")
3+
}
4+
5+
dependencies {
6+
val axis2Version = "1.6.0"
7+
testLibrary("org.apache.axis2:axis2-jaxws:$axis2Version")
8+
testLibrary("org.apache.axis2:axis2-transport-http:$axis2Version")
9+
testLibrary("org.apache.axis2:axis2-transport-local:$axis2Version")
10+
11+
testImplementation(project(":instrumentation:jaxws:jaxws-2.0-common-testing"))
12+
13+
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0:javaagent"))
14+
testInstrumentation(project(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent"))
15+
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent"))
16+
17+
testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
18+
testInstrumentation(project(":instrumentation:jetty:jetty-8.0:javaagent"))
19+
20+
testImplementation("javax.xml.bind:jaxb-api:2.2.11")
21+
testImplementation("com.sun.xml.bind:jaxb-core:2.2.11")
22+
testImplementation("com.sun.xml.bind:jaxb-impl:2.2.11")
23+
24+
testImplementation("com.sun.xml.ws:jaxws-rt:2.2.8")
25+
testImplementation("com.sun.xml.ws:jaxws-tools:2.2.8")
26+
27+
latestDepTestLibrary("org.apache.axis2:axis2-jaxws:1.+") // see jaxws-3.0-axis2-1.6-testing module
28+
latestDepTestLibrary("org.apache.axis2:axis2-transport-http:1.+") // see jaxws-3.0-axis2-1.6-testing module
29+
latestDepTestLibrary("org.apache.axis2:axis2-transport-local:1.+") // see jaxws-3.0-axis2-1.6-testing module
30+
}
31+
32+
configurations.configureEach {
33+
if (name.contains("test")) {
34+
// axis has a dependency on servlet2 api, get rid of it - otherwise the servlet3 instrumentation
35+
// will fail during tests
36+
exclude("javax.servlet", "servlet-api")
37+
}
38+
}
39+
40+
tasks.withType<Test>().configureEach {
41+
// required on jdk17
42+
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
43+
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
44+
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
45+
}

instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/build.gradle.kts

+3-33
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,11 @@ muzzle {
1616
}
1717
}
1818

19-
configurations.configureEach {
20-
if (name.contains("test")) {
21-
// axis has a dependency on servlet2 api, get rid of it - otherwise the servlet3 instrumentation
22-
// will fail during tests
23-
exclude("javax.servlet", "servlet-api")
24-
}
25-
}
26-
2719
dependencies {
2820
bootstrap(project(":instrumentation:servlet:servlet-common:bootstrap"))
2921

30-
val axis2Version = "1.6.0"
31-
library("org.apache.axis2:axis2-jaxws:$axis2Version")
32-
testLibrary("org.apache.axis2:axis2-transport-http:$axis2Version")
33-
testLibrary("org.apache.axis2:axis2-transport-local:$axis2Version")
34-
35-
testImplementation(project(":instrumentation:jaxws:jaxws-2.0-common-testing"))
36-
37-
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0:javaagent"))
38-
testInstrumentation(project(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent"))
39-
40-
testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
41-
testInstrumentation(project(":instrumentation:jetty:jetty-8.0:javaagent"))
42-
43-
testImplementation("javax.xml.bind:jaxb-api:2.2.11")
44-
testImplementation("com.sun.xml.bind:jaxb-core:2.2.11")
45-
testImplementation("com.sun.xml.bind:jaxb-impl:2.2.11")
46-
47-
testImplementation("com.sun.xml.ws:jaxws-rt:2.2.8")
48-
testImplementation("com.sun.xml.ws:jaxws-tools:2.2.8")
49-
}
22+
library("org.apache.axis2:axis2-jaxws:1.6.0")
5023

51-
tasks.withType<Test>().configureEach {
52-
// required on jdk17
53-
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
54-
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
55-
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
24+
compileOnly(project(":muzzle"))
25+
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
5626
}

instrumentation/jaxws/jaxws-2.0-axis2-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/axis2/Axis2ServerSpanNaming.java

+25-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
import io.opentelemetry.context.Context;
1010
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
1111
import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath;
12-
import javax.servlet.http.HttpServletRequest;
12+
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle;
1313
import org.apache.axis2.jaxws.core.MessageContext;
1414

1515
public final class Axis2ServerSpanNaming {
16+
private static final Class<?> JAVAX_REQUEST = loadClass("javax.servlet.http.HttpServletRequest");
17+
private static final Class<?> JAKARTA_REQUEST =
18+
loadClass("jakarta.servlet.http.HttpServletRequest");
1619

1720
public static void updateServerSpan(Context context, Axis2Request axis2Request) {
1821
Span serverSpan = LocalRootSpan.fromContextOrNull(context);
@@ -22,17 +25,34 @@ public static void updateServerSpan(Context context, Axis2Request axis2Request)
2225

2326
String spanName = axis2Request.spanName();
2427
MessageContext message = axis2Request.message();
25-
HttpServletRequest request =
26-
(HttpServletRequest) message.getMEPContext().get("transport.http.servletRequest");
28+
Object request = message.getMEPContext().get("transport.http.servletRequest");
2729
if (request != null) {
28-
String servletPath = request.getServletPath();
29-
if (!servletPath.isEmpty()) {
30+
String servletPath = getServletPath(request);
31+
if (servletPath != null && !servletPath.isEmpty()) {
3032
spanName = servletPath + "/" + spanName;
3133
}
3234
}
3335

3436
serverSpan.updateName(ServletContextPath.prepend(context, spanName));
3537
}
3638

39+
private static Class<?> loadClass(String name) {
40+
try {
41+
return Class.forName(name);
42+
} catch (ClassNotFoundException exception) {
43+
return null;
44+
}
45+
}
46+
47+
@NoMuzzle
48+
private static String getServletPath(Object request) {
49+
if (JAVAX_REQUEST != null && JAVAX_REQUEST.isInstance(request)) {
50+
return ((javax.servlet.http.HttpServletRequest) request).getServletPath();
51+
} else if (JAKARTA_REQUEST != null && JAKARTA_REQUEST.isInstance(request)) {
52+
return ((jakarta.servlet.http.HttpServletRequest) request).getServletPath();
53+
}
54+
return null;
55+
}
56+
3757
private Axis2ServerSpanNaming() {}
3858
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
plugins {
2+
id("otel.javaagent-testing")
3+
}
4+
5+
dependencies {
6+
val axis2Version = "2.0.0"
7+
testLibrary("org.apache.axis2:axis2-jaxws:$axis2Version") {
8+
exclude(group = "org.eclipse.jetty.ee9")
9+
}
10+
testLibrary("org.apache.axis2:axis2-transport-http:$axis2Version")
11+
testLibrary("org.apache.axis2:axis2-transport-local:$axis2Version")
12+
13+
testImplementation(project(":instrumentation:jaxws:jaxws-3.0-common-testing"))
14+
15+
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent"))
16+
17+
testInstrumentation(project(":instrumentation:servlet:servlet-5.0:javaagent"))
18+
testInstrumentation(project(":instrumentation:jetty:jetty-11.0:javaagent"))
19+
}
20+
21+
otelJava {
22+
minJavaVersionSupported.set(JavaVersion.VERSION_17)
23+
}
24+
25+
tasks.withType<Test>().configureEach {
26+
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.axis2;
7+
8+
import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.AbstractJaxWs3Test;
9+
import java.io.File;
10+
import java.io.IOException;
11+
import java.nio.charset.StandardCharsets;
12+
import org.apache.commons.io.FileUtils;
13+
import org.apache.commons.io.IOUtils;
14+
15+
class Axis2JaxWs2Test extends AbstractJaxWs3Test {
16+
static {
17+
try {
18+
updateConfiguration();
19+
} catch (IOException exception) {
20+
throw new IllegalStateException(exception);
21+
}
22+
}
23+
24+
private static void updateConfiguration() throws IOException {
25+
// read default configuration file inside axis2 jar
26+
String configuration =
27+
IOUtils.toString(
28+
Axis2JaxWs2Test.class.getClassLoader().getResourceAsStream("axis2.xml"),
29+
StandardCharsets.UTF_8);
30+
31+
// customize deployer so axis2 can find our services
32+
configuration =
33+
configuration.replace(
34+
"org.apache.axis2.jaxws.framework.JAXWSDeployer", CustomJaxWsDeployer.class.getName());
35+
configuration =
36+
configuration.replace(
37+
"<!--<parameter name=\"servicePath\">services</parameter>-->",
38+
"<parameter name=\"servicePath\">ws</parameter>");
39+
configuration =
40+
configuration.replace(
41+
"<parameter name=\"useGeneratedWSDLinJAXWS\">false</parameter>",
42+
"<parameter name=\"useGeneratedWSDLinJAXWS\">true</parameter>");
43+
configuration = configuration.replace("<module ref=\"addressing\"/>", "");
44+
45+
File configurationDirectory = new File("build/axis-conf/");
46+
configurationDirectory.mkdirs();
47+
FileUtils.writeStringToFile(
48+
new File(configurationDirectory, "axis2.xml"), configuration, StandardCharsets.UTF_8);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.axis2;
7+
8+
import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello.HelloService;
9+
import io.opentelemetry.javaagent.instrumentation.jaxws.v3_0.hello.HelloServiceImpl;
10+
import java.io.File;
11+
import java.util.ArrayList;
12+
import java.util.Arrays;
13+
import org.apache.axis2.jaxws.framework.JAXWSDeployer;
14+
15+
// used in axis2.xml
16+
public class CustomJaxWsDeployer extends JAXWSDeployer {
17+
18+
@Override
19+
protected void deployServicesInWARClassPath() {
20+
this.axisConfig.getParameter("artifactsDIR").setValue(new File("build/axis2/"));
21+
super.deployServicesInWARClassPath();
22+
}
23+
24+
@Override
25+
@SuppressWarnings("NonApiType") // errorprone bug that it doesn't recognize this is an override
26+
protected ArrayList<String> getClassesInWebInfDirectory(File file) {
27+
// help axis find our webservice classes
28+
return new ArrayList<>(
29+
Arrays.asList(HelloService.class.getName(), HelloServiceImpl.class.getName()));
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
axis requires WEB-INF/classes to exist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
axis requires WEB-INF/lib to exist
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app version="3.0" metadata-complete="false"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns="http://java.sun.com/xml/ns/javaee"
5+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
6+
7+
<servlet>
8+
<servlet-name>AxisServlet</servlet-name>
9+
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
10+
<init-param>
11+
<param-name>axis2.xml.path</param-name>
12+
<!-- this configuration file is generated by test -->
13+
<param-value>build/axis-conf/axis2.xml</param-value>
14+
</init-param>
15+
<load-on-startup>1</load-on-startup>
16+
</servlet>
17+
18+
<servlet-mapping>
19+
<servlet-name>AxisServlet</servlet-name>
20+
<url-pattern>/ws/*</url-pattern>
21+
</servlet-mapping>
22+
23+
</web-app>

instrumentation/jaxws/jaxws-3.0-cxf-4.0-testing/build.gradle.kts

-3
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@ otelJava {
2020
}
2121

2222
tasks.withType<Test>().configureEach {
23-
// required on jdk17
24-
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
25-
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
2623
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
2724
}

instrumentation/jaxws/jaxws-3.0-metro-2.2-testing/build.gradle.kts

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ otelJava {
2020

2121
tasks.withType<Test>().configureEach {
2222
// required on jdk17
23-
jvmArgs("--add-exports=java.xml/com.sun.org.apache.xerces.internal.dom=ALL-UNNAMED")
24-
jvmArgs("--add-exports=java.xml/com.sun.org.apache.xerces.internal.jaxp=ALL-UNNAMED")
2523
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
2624
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
2725
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")

settings.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,12 @@ include(":instrumentation:jaxrs-client:jaxrs-client-2.0-testing")
299299
include(":instrumentation:jaxws:jaxws-2.0:javaagent")
300300
include(":instrumentation:jaxws:jaxws-2.0-arquillian-testing")
301301
include(":instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent")
302+
include(":instrumentation:jaxws:jaxws-2.0-axis2-1.6-testing")
302303
include(":instrumentation:jaxws:jaxws-2.0-common-testing")
303304
include(":instrumentation:jaxws:jaxws-2.0-metro-2.2-testing")
304305
include(":instrumentation:jaxws:jaxws-2.0-tomee-testing")
305306
include(":instrumentation:jaxws:jaxws-2.0-wildfly-testing")
307+
include(":instrumentation:jaxws:jaxws-3.0-axis2-1.6-testing")
306308
include(":instrumentation:jaxws:jaxws-3.0-common-testing")
307309
include(":instrumentation:jaxws:jaxws-3.0-cxf-4.0-testing")
308310
include(":instrumentation:jaxws:jaxws-3.0-metro-2.2-testing")

0 commit comments

Comments
 (0)