https://linen.dev logo
#general
Title
# general
k

Kumaresan Sithambaram

01/10/2024, 1:05 AM
Hello wm folks, I am trying to load the stubs using wiremock admin API POST http://localhost:8080/__admin/mappings. It creates the stubs on wiremock instance and able to access it by url specified in the stub. But, if i restart the wiremock servere and try again, the created stubs not found (404). How can I persist the created stubs even after the restart using wiremock admin API. I know if upload the stubs in mapping folder, it will stay. But, my case I supposed create stubs through admin APIs as wiremock is running in container platform.
d

Dan Perovich

01/10/2024, 3:02 PM
Hi, @Kumaresan Sithambaram. Give me a minute to get you the answer.
Are you setting the persistent flag during your post to create the stubs? https://wiremock.org/docs/standalone/admin-api-reference/#tag/Stub-Mappings/paths/~1__admin~1mappings/post
k

Kumaresan Sithambaram

01/10/2024, 4:44 PM
@Dan Perovich - Thank you for the reply!! you are right this is admin API I am also referring. I am using POST /__admin/mappings API using for create the stubs in Wiremock. It is created and acccessible & works perfect. But, If restarts the wiremock server, the created stubs using //__admin/mappings API are flush out. Seems like stubs are stored in session and flushed out after restart. which admin API i supposed to use for create stubs permanently?
d

Dan Perovich

01/10/2024, 6:03 PM
@Kumaresan Sithambaram are you setting the persistent boolean flag in your POST body?
image.png
j

Joao Victor F. Carvalho

01/10/2024, 6:21 PM
what Dan mentioned, should fix, it worked in my case, + if you're in docker, make sure to have /home/wiremock inside a PVC
k

Kumaresan Sithambaram

01/10/2024, 6:40 PM
That is correct. I have 'persistent' Boolean header set to true. But, after restart of the wiremock, the previously created stubs are lost.
I am using wiremock-standalone-3.0.0-beta-12 version.
j

Joao Victor F. Carvalho

01/10/2024, 6:43 PM
as you said it's running on a container: 1-do you have the mocks going to the folder configured for then before you restart? 2-is this same folder in a persistent volume? E.g.: if you create a file with -> touch file.test, will it remain after the container restarts?
d

Dan Perovich

01/10/2024, 6:44 PM
Great catch, @Joao Victor F. Carvalho. I missed that this was running on a container ecosystem.
k

Kumaresan Sithambaram

01/10/2024, 6:50 PM
Sorry @Joao Victor F. Carvalho for haven't answer your last question. This tryout using admin API against to my VM based instance. So, everything is static. Currently I am uploading stub mappings & files as JSON. But, going forward i wanted manage the stubs through the wiremock admin service as this will be soon rolling to container platform. Even I enabled the persitent flag, the mappings /__files folder did not create any stub file through the create mapping wm admin servie.
j

Joao Victor F. Carvalho

01/10/2024, 7:11 PM
It helps if you share here your mock creation payload, you can try with following one, I tested and its persisting. { "request": { "method": "GET", "url": "/test" }, "response": { "status": 200, "headers": { "Content-Type": "application/json" }, "jsonBody": {"status": "UP"} }, "persistent": true }
you should have something like this:
k

Kumaresan Sithambaram

01/10/2024, 7:18 PM
Let me try that. Giv me few minutes.
Sorry for the delay. I tried above sample. If I add persistent flag in request body, the physical file created in the mappings folder without .json extension which is different than your screenshot. So, if restart wiremock without .json extension of the file, it still 404 issue. I renamed the file with extenstion, it works fine even after restart. So, Now last one is, why service doesn't create with .json extenstion. Previously, I added the persistent flag in header. that is my bad.
$ pwd /opt/wiremock/mappings $ ls -ltr get-test-fe622ec1-27d9-43aa-81db-0272c1de2fec -rw-rw-r-- 1 myuser myuser 372 Jan 10 13:48 get-test-fe622ec1-27d9-43aa-81db-0272c1de2fec
j

Joao Victor F. Carvalho

01/10/2024, 8:06 PM
you will need the persistent property if you want save on file, else it will disappear, did you try with your own mock? The reason for not persisting with the json extension, I don't know, anyways how did you start your wiremock? I'm running for this test with: /C/java/rh-openjdk-11.0.20.8-1/bin/java -jar wiremock-standalone-3.3.1.jar
k

Kumaresan Sithambaram

01/10/2024, 8:11 PM
I got you. Yes. I did try with my own mock as well and it creates file in mappings folder without JSON extension. This is command i use to start the wiremock server.
nohup /opt/jdk-11.0.20/bin/java -Xms6144m -Xmx6144m -jar /opt/wiremock/wiremock-standalone-3.0.0-beta-12.jar --port 8080 --local-response-templating &
👍 1
j

Joao Victor F. Carvalho

01/10/2024, 8:13 PM
that might not be the issue, but try to get 3.3.1
k

Kumaresan Sithambaram

01/10/2024, 8:14 PM
j

Joao Victor F. Carvalho

01/10/2024, 8:15 PM
yes, in the botton:
k

Kumaresan Sithambaram

01/10/2024, 8:16 PM
Got you. Let me try and will return with result.
Hi @Joao Victor F. Carvalho -- The JSON extension is created on 3.3.1. seem like bug or configuration gap in 3.0.0.
j

Joao Victor F. Carvalho

01/10/2024, 11:06 PM
great 😉
k

Kumaresan Sithambaram

01/10/2024, 11:06 PM
Thank you for the all great help today.
🙌 1
2 Views