Skip to content

Commit

Permalink
Makes jakarta servlet dependency optional
Browse files Browse the repository at this point in the history
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
  • Loading branch information
marcingrzejszczak committed Dec 14, 2023
1 parent cfeefcd commit ebac7f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions spring-cloud-contract-wiremock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -48,6 +49,7 @@
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;
Expand Down Expand Up @@ -111,6 +113,8 @@ protected byte[] getRequestBodyContent(EntityExchangeResult<?> result) {

class WireMockHttpRequestAdapter implements Request {

private static final boolean SERVLET_API_PRESENT = ClassUtils.isPresent("jakarta.servlet.http.Part", null);

private EntityExchangeResult<?> result;

WireMockHttpRequestAdapter(EntityExchangeResult<?> result) {
Expand Down Expand Up @@ -246,6 +250,9 @@ public boolean isMultipart() {
@Override
public Collection<Part> getParts() {
try {
if (!SERVLET_API_PRESENT) {
return Collections.emptyList();
}
return getWireMockParts();
}
catch (Exception e) {
Expand Down

0 comments on commit ebac7f1

Please sign in to comment.