Makes jakarta servlet dependency optional

without this change if you use Spring Cloud Contract WireMock with e.g. WebFlux your Spring Boot context can fail to start beacuse of it can't decide whether the application should be reactive or not.

with this change we're making the dependency optional because it should come from the user, we shouldn't be providing it. Also RestDocs are assuming that that dependency is a runtime one

fixes gh-1854
This commit is contained in:
Marcin Grzejszczak
2023-12-14 10:52:30 +01:00
parent cfeefcd910
commit ebac7f176c
2 changed files with 8 additions and 0 deletions

View File

@@ -46,6 +46,7 @@
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>

View File

@@ -21,6 +21,7 @@ import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@@ -48,6 +49,7 @@ import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
@@ -111,6 +113,8 @@ public class ContractExchangeHandler extends WireMockVerifyHelper<EntityExchange
class WireMockHttpRequestAdapter implements Request {
private static final boolean SERVLET_API_PRESENT = ClassUtils.isPresent("jakarta.servlet.http.Part", null);
private EntityExchangeResult<?> result;
WireMockHttpRequestAdapter(EntityExchangeResult<?> result) {
@@ -246,6 +250,9 @@ class WireMockHttpRequestAdapter implements Request {
@Override
public Collection<Part> getParts() {
try {
if (!SERVLET_API_PRESENT) {
return Collections.emptyList();
}
return getWireMockParts();
}
catch (Exception e) {