Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why can't Windows make requests to my Karate mock if I use JavaScript mocks?

I have a mock server defined in Karate using a feature file, but I wanted to add more logic. I discovered there’s now support for defining mocks using Java Script, which looked like it could be a lot of help for some of my requirements. But I’ve run into a snag regarding how to make requests to the mock 🙁

I’m using the karate-1.4.1 jarfile. I’m using Windows 11 and Ubuntu in wsl2. I run the mock in Ubuntu. I want to make requests to it from Windows.

When I start the mock using the .js definition, I can’t make calls to the mock from Windows (I CAN make calls from Ubuntu, though – it’s running and working). This is not an issue when starting the mock using the .feature definition. Using the .feature definition, I can happily make requests to the mock from Windows.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When starting the mock, I notice a difference in where the server is set up (Serving HTTP at ...).

Run using a .feature file:

java -cp karate-1.4.1.jar:. com.intuit.karate.Main -m mock.feature

Here’s the output when I run the mock using a .feature file:

08:20:38.582 [armeria-boss-http-*:8080] INFO com.linecorp.armeria.server.Server - Serving HTTP at /0:0:0:0:0:0:0:0%0:8080 - http://127.0.0.1:8080/

Run using a .js file:

java -cp karate-1.4.1.jar:. com.intuit.karate.Main -m mock.js

And here’s the output when I run the mock using a .js file:

08:21:18.010 [armeria-boss-http-127.0.0.1:8080] INFO com.linecorp.armeria.server.Server - Serving HTTP at /127.0.0.1:8080 - http://127.0.0.1:8080/

I suspect there’s something I might be able to configure in Windows 11 to fix this issue (any help here would be appreciated), but I’m not sure why things would work so smoothly when starting the mock with a .feature file, but work differently when starting the mock with a .js file.

>Solution :

I just realized that the JS option is designed to allow only connections from localhost by default. Just made a commit to fix this, that could be self-explanatory.

Now most teams start the JS mocks from Java code (and are on Mac / Linux) I guess. Yes, I think some windows setting can work, maybe you can search for how to edit the etc.conf file, not sure.

Since a new release may take time, do you think you could use the Java API to start a mock? It would be something like this: MockRunner.java – and you can call the local(false) builder method in addition.

Actually you should be able to easily build your own karate.jar file following the instructions here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading