Skip to content

Commit cdbbabb

Browse files
committed
⬆️ Upgrade WireMock to latest version
Also, start using WireMock/Spring Boot integration. This will allow for random ports to be used in that test. Fixed an issue that surfaced during testing. New version of WireMock/Spring Integration uses new version of Apache HTTP client that does not like duplicate headers. The POST proxy code was generating duplicate Transfer-Encoding headers, so had to implement code to remove the duplicate.
1 parent 7f3309d commit cdbbabb

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

spring/fluentforms-spring-boot-autoconfigure/pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
<jasypt.maven.plugin.version>3.0.5</jasypt.maven.plugin.version>
2020
<fluentforms.version>0.0.5-SNAPSHOT</fluentforms.version>
2121
<fp.hamcrest.matchers.version>0.0.4-SNAPSHOT</fp.hamcrest.matchers.version>
22-
<wiremock.version>4.0.0-beta.16</wiremock.version>
22+
<wiremock.version>4.0.0-beta.21</wiremock.version>
23+
<wiremock-spring-boot.version>4.0.8</wiremock-spring-boot.version>
2324
<pitest.maven.plugin.version>1.20.2</pitest.maven.plugin.version>
2425
<pitest.junit5.maven.plugin.version>1.2.3</pitest.junit5.maven.plugin.version>
2526
</properties>
@@ -86,6 +87,7 @@
8687
<artifactId>rest-services.client</artifactId>
8788
<version>${fluentforms.version}</version>
8889
</dependency>
90+
8991
<!-- Testing Dependencies -->
9092
<dependency>
9193
<groupId>org.springframework.boot</groupId>
@@ -104,6 +106,26 @@
104106
<version>${wiremock.version}</version>
105107
<scope>test</scope>
106108
</dependency>
109+
<dependency>
110+
<groupId>org.wiremock.integrations</groupId>
111+
<artifactId>wiremock-spring-boot</artifactId>
112+
<version>${wiremock-spring-boot.version}</version>
113+
<scope>test</scope>
114+
</dependency>
115+
<!-- Explicit HttpComponents (override transitive versions that may not support chunked correctly) -->
116+
<!-- <dependency>
117+
<groupId>org.apache.hc.client5</groupId>
118+
<artifactId>httpclient5</artifactId>
119+
<version>5.2.3</version>
120+
<scope>test</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.apache.hc.core5</groupId>
124+
<artifactId>httpcore5</artifactId>
125+
<version>5.2.3</version>
126+
<scope>test</scope>
127+
</dependency>
128+
-->
107129
<dependency>
108130
<groupId>org.pitest</groupId>
109131
<artifactId>pitest-junit5-plugin</artifactId>

spring/fluentforms-spring-boot-autoconfigure/src/main/java/com/_4point/aem/fluentforms/spring/AemProxyEndpoint.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ private static InputStream fixTogglesDotJsonLocation(InputStream is) {
190190
return new ReplacingInputStream(is, target, replacement);
191191
}
192192

193+
/**
194+
* This function acts as a reverse proxy for anything POSTed to the server. It just forwards
195+
* anything it receives on AEM and then returns the response. It logs slightly differently
196+
* if the request is a form submission.
197+
*
198+
* @param remainder
199+
* @param contentType
200+
* @param in
201+
* @return
202+
*/
193203
@PostMapping("/{*remainder}")
194204
public ResponseEntity<byte[]> proxyPost(@PathVariable("remainder") String remainder, @RequestHeader(value = "Content-Type", required = false) String contentType, byte[] in) {
195205
logger.atDebug().log("Proxying POST request. remainder={}", remainder);
@@ -223,8 +233,10 @@ public ResponseEntity<byte[]> proxyPost(@PathVariable("remainder") String remain
223233
.log("Returning POST response from target '{}'.");
224234
}
225235

226-
return response;
227-
}
236+
return ResponseEntity.status(response.getStatusCode())
237+
.headers(removeChunkedTransferEncoding(response.getHeaders()))
238+
.body(response.getBody());
239+
}
228240

229241
private static byte[] debugInput(byte[] inputBytes, String target) {
230242
logger.atDebug()

spring/fluentforms-spring-boot-autoconfigure/src/test/java/com/_4point/aem/fluentforms/spring/AemProxyEndpointTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@
2323
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
2424
import org.springframework.boot.test.web.server.LocalServerPort;
2525
import org.springframework.web.client.RestClient;
26+
import org.wiremock.spring.ConfigureWireMock;
27+
import org.wiremock.spring.EnableWireMock;
2628

2729
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
2830
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
2931

30-
@WireMockTest(httpPort = AemProxyEndpointTest.WIREMOCK_PORT)
32+
@WireMockTest()
3133
@SpringBootTest(classes = {com._4point.aem.fluentforms.spring.AemProxyEndpointTest.TestApplication.class},
3234
webEnvironment = WebEnvironment.RANDOM_PORT,
3335
properties = {
3436
"fluentforms.aem.servername=localhost",
35-
"fluentforms.aem.port=" + AemProxyEndpointTest.WIREMOCK_PORT,
3637
"fluentforms.aem.user=ENC(7FgD3ZsSExfUGRYlXNc++6C1upPBURNKq6HouzagnNZW4FsBwFs5+crawv+djhw6)",
3738
"fluentforms.aem.password=ENC(QmQ6iTm/+TOO8U3dDuBzJWH129vReWgYNdgqQwWhjWaQy6j8sMnk2/Auhehmlh3v)",
3839
//"fluentforms.aem.useSsl=true",
@@ -43,6 +44,10 @@
4344
"jasypt.encryptor.salt-generator-classname=org.jasypt.salt.RandomSaltGenerator",
4445
"logging.level.com._4point.aem.fluentforms.spring.AemProxyEndpoint=DEBUG"
4546
})
47+
@EnableWireMock(@ConfigureWireMock(
48+
portProperties = "fluentforms.aem.port"
49+
)
50+
)
4651
@Timeout(value = 5, unit = TimeUnit.MINUTES) // Fail tests that take longer than this to prevent hanging.
4752
class AemProxyEndpointTest {
4853
private final static Logger logger = LoggerFactory.getLogger(AemProxyEndpointTest.class);

0 commit comments

Comments
 (0)