Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ jobs:
test-java-distribution: ${{ matrix.distribution }}
command: ./mvnw install -DskipTests=true -Dmaven.javadoc.skip=true
- name: Run tests for ${{ matrix.version }}:${{ matrix.distribution }}
run: ./mvnw test -Delastic.jdkCompatibilityTest=true -Dtest_java_binary=${{ env.TEST_JAVA_BINARY }}
run: ./mvnw test -Delastic.jdkCompatibilityTest=true -Dtest_java_binary=${{ env.TEST_JAVA_BINARY }} -Dtest_java_version=${{ matrix.version }}
- name: Store test results
if: success() || failure()
uses: actions/upload-artifact@v6
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This file contains all changes which are not released yet.
<!--FIXES-END-->
# Features and enhancements
<!--ENHANCEMENTS-START-->

* Support Spring Boot 4
<!--ENHANCEMENTS-END-->
# Deprecations
<!--DEPRECATIONS-START-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,19 @@
<scope>test</scope>
</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 @@ -66,7 +66,7 @@ protected boolean isRedirectFollowingSupported() {
* The code is compiled with java 17 but potentially run with java 11.
* JUnit will inspect the test class, therefore it must not contain any references to java 17 code.
*/
private static class Java17Code {
public static class Java17Code {
public static void performGet(Object restClient, String path) {
((RestClient) restClient).get().uri(path).retrieve().body(String.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class SpringRestRequestHeaderSetter implements TextHeaderSetter<HttpReque

@Override
public void setHeader(String headerName, String headerValue, HttpRequest request) {
if (!request.getHeaders().containsKey(headerName)) {
// In Spring Framework 7, containsKey no longer exists
if (request.getHeaders().getFirst(headerName) == null) {
// the org.springframework.http.HttpRequest has only be introduced in 3.1.0
request.getHeaders().add(headerName, headerValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-httpclient-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-spring-resttemplate-plugin</artifactId>
Expand All @@ -31,6 +38,13 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-spring-restclient-test</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.ivy</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.resttemplate;

import co.elastic.apm.agent.restclient.SpringRestClientInstrumentationTest;
import co.elastic.apm.agent.testutils.TestClassWithDependencyRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@EnabledForJreRange(min = JRE.JAVA_17, disabledReason = "Spring 6 and up require JDK 17")
public class SpringRestClientVersionsIT {


@Test
void version6() throws Exception {
testVersionImpl("6.1.0");
}

@Test
void version7() throws Exception {
testVersionImpl("7.0.0");
}

void testVersionImpl(String version) throws Exception {
var springDependencies = Stream.of(
"spring-webmvc",
"spring-aop",
"spring-beans",
"spring-context",
"spring-core",
"spring-expression",
"spring-web")
.map(s -> String.format("org.springframework:%s:%s", s, version));

var additionalDependencies = Stream.of(
"io.micrometer:micrometer-observation:1.10.2",
"io.micrometer:micrometer-commons:1.10.2",
"commons-logging:commons-logging:1.3.0",
"org.apache.logging.log4j:log4j-api:2.25.3"
);

List<String> dependencies = Stream.concat(springDependencies, additionalDependencies).collect(Collectors.toList());

new TestClassWithDependencyRunner(dependencies, SpringRestClientInstrumentationTest.class.getName(), SpringRestClientInstrumentationTest.Java17Code.class.getName()).run();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ void testVersion6(String version) throws Exception {
));
}

@ParameterizedTest
@ValueSource(strings = {
"7.0.0"
})
@EnabledForJreRange(min = JRE.JAVA_17, disabledReason = "Spring 7 requires JDK 17")
void testVersion7(String version) throws Exception {
testVersionImpl(version, true, List.of(
"commons-logging:commons-logging:1.3.0",
"io.micrometer:micrometer-observation:1.10.2",
"io.micrometer:micrometer-commons:1.10.2",
"org.apache.logging.log4j:log4j-api:2.25.3"
));
}

void testVersionImpl(String version, boolean isSupported, List<String> additionalDependencies) throws Exception {
List<String> dependencies = Stream.of(
"spring-webmvc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>apm-spring-webmvc</artifactId>
<groupId>co.elastic.apm</groupId>
<version>1.55.5-SNAPSHOT</version>
</parent>

<artifactId>apm-spring-webmvc-spring7-test</artifactId>
<name>${project.groupId}:${project.artifactId}</name>

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

<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>4.0.0</version> <!-- must be 4.X to correspond to spring 7 -->
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-spring-webmvc-plugin</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>apm-spring-webmvc-spring5</artifactId>
<type>test-jar</type>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring6</artifactId>
<scope>test</scope>
</dependency>
</dependencies>



<profiles>
<profile>
<!-- Spring Boot 4 / Spring Framework 7 requires junit 6 which requires java 17 -->
<id>testing-jdk-11</id>
<activation>
<property>
<name>test_java_version</name>
<value>11</value>
</property>
</activation>
<properties>
<skipTests>true</skipTests>
</properties>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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.springwebmvc;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.ServletWrappingController;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.function.Function;

public class Spring7TransactionNameInstrumentationTest extends AbstractSpringTransactionNameInstrumentationTest {
public static class TestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.getWriter().print("TestServlet");
}
}

@Configuration
public static class TestConfiguration extends AbstractTestConfiguration {

@Override
protected Class<?> getTestServletClass() {
return TestServlet.class;
}

@Override
protected void configureTestServletOnController(ServletWrappingController controller) {
controller.setServletClass(TestServlet.class);
}

@Override
protected ServletWrappingController createMyCustomController(Function<PrintWriter, ModelAndView> handler) {
return new MyCustomController(handler);
}

@Override
protected ServletWrappingController createAnonymousController(Function<PrintWriter, ModelAndView> handler) {
return new ServletWrappingController() {
@Override
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return handler.apply(response.getWriter());
}
};
}
}


private static class MyCustomController extends ServletWrappingController {

private final Function<PrintWriter, ModelAndView> handler;

public MyCustomController(Function<PrintWriter, ModelAndView> handler) {
this.handler = handler;
}

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
return handler.apply(response.getWriter());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.springwebmvc.exception;

public class Spring7ExceptionHandlerInstrumentationWithExceptionHandlerTest extends Spring5ExceptionHandlerInstrumentationWithExceptionHandlerTest {

}
Loading
Loading