Skip to content
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

Add support for cxf 4.0 jaxws #12077

Merged
merged 1 commit into from
Aug 27, 2024
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {

testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0-cxf-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies {

testInstrumentation(project(":instrumentation:servlet:servlet-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-2.0-cxf-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent"))
testInstrumentation(project(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent"))

// wildfly version used to run tests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
id("otel.javaagent-testing")
}

dependencies {
testLibrary("org.apache.cxf:cxf-rt-frontend-jaxws:4.0.0")
testLibrary("org.apache.cxf:cxf-rt-transports-http:4.0.0")

testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0")
testImplementation(project(":instrumentation:jaxws:jaxws-3.0-common-testing"))

testInstrumentation(project(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent"))

testInstrumentation(project(":instrumentation:servlet:servlet-5.0:javaagent"))
testInstrumentation(project(":instrumentation:jetty:jetty-11.0:javaagent"))
}

otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_17)
}

tasks.withType<Test>().configureEach {
// required on jdk17
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
jvmArgs("-Dotel.instrumentation.common.experimental.controller-telemetry.enabled=true")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

import hello.HelloServiceImpl
import io.opentelemetry.api.trace.Span
import io.opentelemetry.context.Context
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan
import org.apache.cxf.jaxws.EndpointImpl
import org.apache.cxf.message.Message
import org.apache.cxf.phase.AbstractPhaseInterceptor
import org.apache.cxf.phase.Phase
import org.apache.cxf.transport.servlet.CXFNonSpringServlet

import jakarta.servlet.ServletConfig

class TestWsServlet extends CXFNonSpringServlet {
@Override
void loadBus(ServletConfig servletConfig) {
super.loadBus(servletConfig)

// publish test webservice
Object implementor = new HelloServiceImpl()
EndpointImpl endpoint = new EndpointImpl(bus, implementor)
endpoint.publish("/HelloService")
endpoint.getOutInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.SETUP) {
@Override
void handleMessage(Message message) {
Context context = Context.current()
if (LocalRootSpan.fromContext(context) != Span.fromContext(context)) {
throw new IllegalStateException("handler span should be ended before outgoing interceptors")
}
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies {
compileOnly("javax.servlet:javax.servlet-api:3.0.1")
compileOnly("org.apache.cxf:cxf-rt-frontend-jaxws:3.0.0")

implementation(project(":instrumentation:jaxws:jaxws-2.0-cxf-3.0:javaagent"))
implementation(project(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent"))

testImplementation(project(":instrumentation-api"))
testImplementation("org.apache.cxf:cxf-rt-frontend-jaxws:3.0.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ muzzle {
module.set("cxf-rt-frontend-jaxws")
// all earlier versions in maven central also pass muzzle check,
// but 3.0.0 is already 8 years old and testing earlier versions adds complexity
versions.set("[3.0.0,4)")
versions.set("[3.0.0,)")
extraDependency("javax.servlet:javax.servlet-api:3.0.1")
extraDependency("jakarta.servlet:jakarta.servlet-api:5.0.0")
}
}

Expand All @@ -18,6 +19,8 @@ dependencies {

library("org.apache.cxf:cxf-rt-frontend-jaxws:3.0.0")
compileOnly("javax.servlet:javax.servlet-api:3.0.1")
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")
compileOnly(project(":muzzle"))

testLibrary("org.apache.cxf:cxf-rt-transports-http:3.0.0")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.cxf;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.javaagent.bootstrap.servlet.ServletContextPath;
import io.opentelemetry.javaagent.tooling.muzzle.NoMuzzle;

public final class CxfServerSpanNaming {
private static final Class<?> JAVAX_SERVLET_REQUEST =
loadClass("javax.servlet.http.HttpServletRequest");
private static final Class<?> JAKARTA_SERVLET_REQUEST =
loadClass("jakarta.servlet.http.HttpServletRequest");

private static Class<?> loadClass(String className) {
try {
return Class.forName(className);
} catch (ClassNotFoundException exception) {
return null;
}
}

public static void updateServerSpanName(Context context, CxfRequest cxfRequest) {
String spanName = cxfRequest.spanName();
if (spanName == null) {
return;
}

Span serverSpan = LocalRootSpan.fromContextOrNull(context);
if (serverSpan == null) {
return;
}

Object request = cxfRequest.message().get("HTTP.REQUEST");
if (request != null) {
String servletPath = null;
if (JAVAX_SERVLET_REQUEST != null && JAVAX_SERVLET_REQUEST.isInstance(request)) {
servletPath = getJavaxServletPath(request);
} else if (JAKARTA_SERVLET_REQUEST != null && JAKARTA_SERVLET_REQUEST.isInstance(request)) {
servletPath = getJakartaServletPath(request);
}
if (servletPath != null && !servletPath.isEmpty()) {
spanName = servletPath + "/" + spanName;
}
}

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

@NoMuzzle
private static String getJavaxServletPath(Object request) {
return ((javax.servlet.http.HttpServletRequest) request).getServletPath();
}

@NoMuzzle
private static String getJakartaServletPath(Object request) {
return ((jakarta.servlet.http.HttpServletRequest) request).getServletPath();
}

private CxfServerSpanNaming() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import io.opentelemetry.javaagent.bootstrap.internal.ExperimentalConfig;

public class CxfSingletons {
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxws-2.0-cxf-3.0";
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jaxws-cxf-3.0";

private static final Instrumenter<CxfRequest, Void> INSTRUMENTER;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

class CxfJaxWsTest extends AbstractJaxWsTest {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" metadata-complete="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<servlet>
<servlet-name>wsServlet</servlet-name>
<servlet-class>TestWsServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>wsServlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
</web-app>
5 changes: 3 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,15 @@ include(":instrumentation:jaxws:jaxws-2.0:javaagent")
include(":instrumentation:jaxws:jaxws-2.0-arquillian-testing")
include(":instrumentation:jaxws:jaxws-2.0-axis2-1.6:javaagent")
include(":instrumentation:jaxws:jaxws-2.0-common-testing")
include(":instrumentation:jaxws:jaxws-2.0-cxf-3.0:javaagent")
include(":instrumentation:jaxws:jaxws-2.0-cxf-3.0:javaagent-unit-tests")
include(":instrumentation:jaxws:jaxws-2.0-metro-2.2-testing")
include(":instrumentation:jaxws:jaxws-2.0-tomee-testing")
include(":instrumentation:jaxws:jaxws-2.0-wildfly-testing")
include(":instrumentation:jaxws:jaxws-3.0-common-testing")
include(":instrumentation:jaxws:jaxws-3.0-cxf-4.0-testing")
include(":instrumentation:jaxws:jaxws-3.0-metro-2.2-testing")
include(":instrumentation:jaxws:jaxws-common:javaagent")
include(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent")
include(":instrumentation:jaxws:jaxws-cxf-3.0:javaagent-unit-tests")
include(":instrumentation:jaxws:jaxws-jws-api-1.1:javaagent")
include(":instrumentation:jaxws:jaxws-metro-2.2:javaagent")
include(":instrumentation:jboss-logmanager:jboss-logmanager-appender-1.1:javaagent")
Expand Down
Loading