Why am I getting 400 from <https://examples.wiremo...
# help
v
Why am I getting 400 from https://examples.wiremockapi.cloud/recordables/123 when using wiremock recording. Very strange. Pasting code and logs on this thread. Thanks.
package com.example.wiremockjunitstandalone; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.WireMockServer; import com.github.tomakehurst.wiremock.admin.model.ListStubMappingsResult; import com.github.tomakehurst.wiremock.recording.SnapshotRecordResult; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.test.annotation.DirtiesContext; @AutoConfigureWireMock(port = 9999) //from org.springframework.cloudspring cloud contract wiremock3.1.3 @DirtiesContext @Slf4j @SpringBootTest(classes = {WiremockJunitStandaloneApplication.class}) public class Recorder { @Autowired WireMockServer wireMockServer; @Autowired ObjectMapper objectMapper; @BeforeEach void setupRec() { wireMockServer.startRecording("https://examples.wiremockapi.cloud"); } @Test @SneakyThrows void startRec() { ListStubMappingsResult stubslist = wireMockServer.listAllStubMappings(); System.err.println("stubslist.getMappings().size(): " + stubslist.getMappings().size()); System.err.println("stubslist.getMappings(): " + stubslist.getMappings()); HttpRequest request; HttpResponse<String> response; request = HttpRequest._newBuilder_() .uri(new URI("http://localhost:9999/recordables/123")) // port is assigned to 9999 using @AutoConfigureWireMock(port = 9999) .version(HttpClient.Version._HTTP_2_) .GET() .build(); response = HttpClient._newHttpClient_() .send(request, HttpResponse.BodyHandlers._ofString_()); Assertions._assertTrue_( response.statusCode() < 300 ); SnapshotRecordResult recordedMappings = wireMockServer.snapshotRecord(); System.err.println("\n\nrecordedMappings: " + recordedMappings); System.err.println("\n\nrecordedMappings.getStubMappings(): " + recordedMappings.getStubMappings()); } }
/\\ / ___'_ __ _ ()_ _ _ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ _)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.7.14) 2023-07-30 233328.202 INFO 24540 --- [ Test worker] c.e.wiremockjunitstandalone.Recorder : Starting Recorder using Java 11.0.2 on CTXPOFFASA0877 with PID 24540 (started by vs980o in C:\Users\vs980o\v\dwa\exp\wiremock-junit-standalone) 2023-07-30 233328.204 INFO 24540 --- [ Test worker] c.e.wiremockjunitstandalone.Recorder : No active profile set, falling back to 1 default profile: "default" 2023-07-30 233329.163 INFO 24540 --- [ Test worker] wiremock.org.eclipse.jetty.util.log : Logging initialized @2622ms to wiremock.org.eclipse.jetty.util.log.Slf4jLog 2023-07-30 233329.441 INFO 24540 --- [ Test worker] w.org.eclipse.jetty.server.Server : jetty-9.4.46.v20220331; built: 2022-03-31T163808.030Z; git: bc17a0369a11ecf40bb92c839b9ef0a8ac50ea18; jvm 11.0.2+9 2023-07-30 233329.457 INFO 24540 --- [ Test worker] w.o.e.j.server.handler.ContextHandler : Started w.o.e.j.s.ServletContextHandler@5b29ab61{/__admin,null,AVAILABLE} 2023-07-30 233329.467 INFO 24540 --- [ Test worker] w.o.e.j.s.handler.ContextHandler.ROOT : RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler. Normalized mapped under returned 'null' 2023-07-30 233329.467 INFO 24540 --- [ Test worker] w.o.e.j.server.handler.ContextHandler : Started w.o.e.j.s.ServletContextHandler@501957bf{/,null,AVAILABLE} 2023-07-30 233329.477 INFO 24540 --- [ Test worker] w.o.e.jetty.server.AbstractConnector : Started NetworkTrafficServerConnector@5c134052{HTTP/1.1, (http/1.1, h2c)}{0.0.0.0:9999} 2023-07-30 233329.482 INFO 24540 --- [ Test worker] w.o.e.jetty.util.ssl.SslContextFactory : x509=X509@34045582(wiremock,h=[tom akehurst],a=[],w=[]) for Server@8c43966[provider=null,keyStore=null,trustStore=null] 2023-07-30 233329.502 INFO 24540 --- [ Test worker] w.o.e.jetty.server.AbstractConnector : Started NetworkTrafficServerConnector@47829d6d{SSL, (ssl, alpn, h2, http/1.1)}{0.0.0.0:14495} 2023-07-30 233329.503 INFO 24540 --- [ Test worker] w.org.eclipse.jetty.server.Server : Started @2962ms 2023-07-30 233329.695 INFO 24540 --- [ Test worker] c.e.wiremockjunitstandalone.Recorder : Started Recorder in 1.797 seconds (JVM running for 3.154) stubslist.getMappings().size(): 1 stubslist.getMappings(): [{ "id" : "f23eb0d5-a864-4e5c-9dd2-2c5a7a11d9ac", "request" : { "method" : "ANY" }, "response" : { "status" : 200, "proxyBaseUrl" : "https://examples.wiremockapi.cloud" }, "uuid" : "f23eb0d5-a864-4e5c-9dd2-2c5a7a11d9ac" }] 2023-07-30 233330.258 INFO 24540 --- [ient-1-Worker-0] jdk.httpclient.HttpClient : REQUEST: http://localhost:9999/recordables/123 GET 2023-07-30 233330.391 INFO 24540 --- [qtp400593724-36] WireMock : Proxying: GET https://examples.wiremockapi.cloud/recordables/123 2023-07-30 233331.320 INFO 24540 --- [qtp400593724-36] WireMock : Request received: 127.0.0.1 - GET /recordables/123 Connection: [Upgrade, HTTP2-Settings] Content-Length: [0] Host: [localhost:9999] HTTP2-Settings: [AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA] Upgrade: [h2c] User-Agent: [Java-http-client/11.0.2] Matched response definition: { "status" : 200, "proxyBaseUrl" : "https://examples.wiremockapi.cloud" } Response: HTTP/1.1 400 Content-Type: [text/html;charset=iso-8859-1] Content-Length: [54] 2023-07-30 233331.325 INFO 24540 --- [ient-1-Worker-0] jdk.httpclient.HttpClient : RESPONSE: (GET http://localhost:9999/recordables/123) 400 HTTP_2 Local port: 53889 expected: <true> but was: <false> Expected :true Actual :false <Click to see difference>
log to notice in above - 2023-07-30 233330.391 INFO 24540 --- [qtp400593724-36] WireMock : Proxying: GET https://examples.wiremockapi.cloud/recordables/123
this seems to be it and it's perfect and the url works.. then still why 400