I have a spring web application that I start local...
# general
I have a spring web application that I start locally with these java proxy properties:
Copy code
I am starting a local WireMock server with http port 1080. The spring application is definitely routing requests through the designated proxy, but my WireMock server is not forwarding these requests to their destination. My goal is to have WireMock return stubs if there is a mapping match, otherwise forward the request to its destination and log the forwarded request. Is WireMock able to act as a proxy server in this way? I am using
2.35.0. The WireMock Proxy docs mentions a WireMockServer option
(which it says defaults to “true”), which sounds exactly like what I want. But I don’t see this option available on this version of WireMock.
Hi @Steve Teplica, provided you start WireMock with browser proxying (which is just forward proxying) enabled, then it will behave in the way you’re asking for. To do this you either do
in the Java startup options, or
from the CLI.
👀 1
It looks like HTTP requests are working fine with this setup. Right now I’m floundering with getting HTTPS requests working. Changes to Spring Application: • I added these JVM proxy settings for HTTPS
Copy code
Changes to WireMock Server: • I configured WireMock’s HTTPS port to 1083 • I added a
to log info on incoming/outgoing network traffic. • These are the current relevent WireMock configurations:
Copy code
WireMockServer wireMockServer = new WireMockServer(WireMockConfiguration.options()
Observed behavior: • It looks like the initial HTTP CONNECT request (to open a tunnel to client’s request destination) is closing prematurely or failing:
Copy code
2023-03-29 16:25:53.924 Opened Socket[addr=/,port=53213,localport=1083]
2023-03-29 16:25:53.930 Incoming bytes: CONNECT <http://subdomain.domain.com:443|subdomain.domain.com:443> HTTP/1.1
Host: <http://subdomain.domain.com:443|subdomain.domain.com:443>
Proxy-Connection: Keep-Alive
User-Agent: okhttp/3.8.1

2023-03-29 16:25:53.938 Outgoing bytes: P
2023-03-29 16:25:53.943 Closed Socket[unconnected]
@Tom Do you have any advice for debugging this further? Or does this appear as an obvious symptom, to you, of something being misconfigured? Any help is greatly appreciated 😄
Extra context on the requested domain: I obfuscated it as
. This is an endpoint that can only be reached while on my corporate network (I’m VPN’d in). The spring application normally sends these requests directly to that endpoint. The spring application does have a keystore and a truststore. I’m not sure if/how those should be used from WireMock
I found this bit on WireMock’s proxying docs. Sounds like this is exactly what I need to do in my situation. Do you have an example of creating two separate HTTPS sessions for this configuration?
You’ll need to ensure that the Spring app trusts WireMock’s CA certificate otherwise it’ll (correctly) detect that it’s doing an MITM attack and refuse to send traffic.
Thanks Tom! The cause of these SSL problems for me was how I configured the java proxy ports. I stumbled across JvmProxyConfigurer in WireMock and saw that it sets
to the same port. So I did the same thing for my spring app, and then everything was working!
👍 1