Hello Everyone, i am trying to integrate Wiremock...
# help
a
Hello Everyone, i am trying to integrate Wiremock with Spring boot by using org.wiremock.integrationswiremock spring boot3.6.0, i am using java 21 and spring boot 3.4.2 i am using below config to start wiremock and spring boot parellel
Copy code
@EventListener(ApplicationReadyEvent.class)
public void startWireMockServer(){

    wireMockServer = new WireMockServer(
          WireMockConfiguration.wireMockConfig()
                .port(Integer.parseInt(wiremockPort))
                .usingFilesUnderDirectory(mappingsDirectory)
                .withRootDirectory(filesDirectory)
                .notifier(new ConsoleNotifier(true))
                .enableBrowserProxying(true)

    );

    wireMockServer.start();
}

@EventListener(ContextClosedEvent.class)
public void stopWireMockServer() {
    if(null != wireMockServer){
       wireMockServer.stop();
    }
}
Above logic placed in spring boot main application file Problem: When i am trying to access http://localhost:8082/__admin/swagger-ui/, it showing blank screen and in console showing below 2025-01-28T004326.602+05:30 WARN 21208 --- [Wiremock-poc] [p1281205497-144] o.e.jetty.ee10.servlet.ResourceServlet : Deprecated resourceBase used instead of baseResource 2025-01-28T004326.691+05:30 WARN 21208 --- [Wiremock-poc] [p1281205497-131] o.e.jetty.ee10.servlet.DefaultServlet : Incorrect mapping for DefaultServlet at /swagger-ui/*. Use ResourceServlet Please guide to the solution please, also i am unable to see recorder web UI also
t
Sounds like this particular feature might not work well with Jetty 12. You could run the standalone JAR as a recorder as a workaround for now, then read the resulting stub mapping files from the WireMock instance you’re running in your code.
a
is it possible to run wiremock standalone server inside spring boot application and accessing stubs through configuration that i did above
t
Yes, you can change the artifact ID in your dependencies to
wiremock-standalone
and otherwise use it the same way
a
Example: wiremock standalone server inside spring boot app with port 9091 Spring boot with port 8080 connecting to 9091 with my configuration in main application class file
in above way, do i get swagger and wiremock web ui of recorder
t
I would expect that to work, yes
a
let me try and get back to you please
what is the group id for this - wiremock-standalone
t
Same
a
Copy code
<dependency>
    <groupId>org.wiremock.integrations</groupId>
    <artifactId>wiremock-spring-boot</artifactId>
    <version>3.6.0</version>
</dependency>
i used this in my current configuration
t
Ah OK, I assumed you were using the WireMock dependency directly since you were newing up the the server yourself
Try this one:
Copy code
<dependency>
    <groupId>org.wiremock</groupId>
    <artifactId>wiremock-standalone</artifactId>
    <version>3.10.0</version>
</dependency>
a
so the same configuration will work ?
t
Assuming you’re not also using the Spring Boot integration classes elsewhere, it should work the same
a
Yes, let me try
now i can see swagger-ui but http://localhost:8082/__admin/recorder/ showing blank screen, instead of web UI do i need to enable anything for that ?
8082 is wiremock port
t
It should work by default. Did you say the WireMock port was 9091?
a
i changed to 8082 because of conflict
i am able to record using
Copy code
WireMock.startRecording(targetUrl);
but after record stop using
Copy code
WireMock.stopRecording();
mappings are not stored in mappings folder can you help me how those will save into mappings folder
t
Are the mappings present in memory at the end? If you call
WireMock.listAllStubMappings()
do you get your recorded stubs back?
a
it is showing in http://localhost:8082/__admin/mappings if i access while recording, once recording stopped, all are removed and not saved into mappings folder i want those to be saved into mappings folder like other stubs
t
That’s very strange. They should only show up there after recording is complete.
Can you share the complete code you’re using for this? Seems like there’s something we’re missing here.
a
do you need entire project ?
t
A repro project would be ideal
a
Sure
this is ZIP file entire maven project
👀 1
it is working now i called
Copy code
WireMock.saveAllMappings();
before stop recording
Great Library. Great work.
i will get back to you if anything is needed Thank you so much for support
t
Glad you solved it. Was going to suggest that, but you’ve beaten me to it.
a
😄 now i will try come up with more tricky problems
t
There’s always more!
a
Great Attitude, Thank you so much 👍
t
No problem
a
Hello @Tom Recording with external service is not happening i am calling rest service of Spring boot where Wiremock also running along with spring boot on 8090, wiremock on 8082
Copy code
@GetMapping("/startRecord")
public String startRecord(){
    wireMockService.startRecording("<http://localhost:9099>");
    return "Recording started";
}

@GetMapping("/stopRecord")
public String stopRecord(){
    wireMockService.stopRecording();
    return "Recording Stopped";
}
http://localhost:9099 - is my another spring boot application after calling /startRecord API, i will call multiple API of http://localhost:9099 from browser wireMockService is
Copy code
@Service
public class WireMockService {

    public void startRecording(String targetUrl) {
        WireMock.startRecording(targetUrl);
        System.out.println("Started Recording");
    }

    public void stopRecording() {
        WireMock.saveAllMappings();
        WireMock.stopRecording();
        System.out.println("Stopped Recording");
    }
}
is there anything i am missing, can you please help me
It is working, i am calling all External Services API's with Wiremock url as proxy, it is recording and saving all
Thank you
👍 1