Hello wm folks, I am trying to load the stubs usin...
# general
k
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
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
@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
@Kumaresan Sithambaram are you setting the persistent boolean flag in your POST body?
j
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
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
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
Great catch, @Joao Victor F. Carvalho. I missed that this was running on a container ecosystem.
k
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
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
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
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
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
that might not be the issue, but try to get 3.3.1
k
j
yes, in the botton:
k
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
great 😉
k
Thank you for the all great help today.
🙌 1
134 Views