dreamhead / moco

Easy Setup Stub Server
MIT License
4.36k stars 1.08k forks source link

[Feature Request] Moco Servlet #106

Open liweinan0423 opened 9 years ago

liweinan0423 commented 9 years ago

Is it supported that get Moco running in a servlet environment? For example, we configure a servlet in web.xml like

<servlet>
  <servlet-name>MocoServlet</servlet>
  <servlet-class>com.github.dreamhead.moco.MocoServlet</servlet-class>
  <init-param>
    <param-name>responseFile</param-name>
    <param-value>response.json</param-value>
  </init-param>
</servlet>

So that, we can deploy our mocked services as a war file in tomcat server.

The reason I am proposing this feature is that we want to integrate the mocked services into Go Server, we want to start the mocked server at the start of a job and stop it when the job is completed. But if we start moco as standalone server by java -jar mock-jar *****, it will block the job to run the following tasks.

I am also diving deeper with Moco and going to try to implement this feature myself, so please provide any feedback that would help.

Thanks!

dreamhead commented 9 years ago

Before Moco, I used to use servlet in my project to do stub work. It took us a lot of time to setup infrastructure. That is why I designed Moco.

For your case, if I were you, I would run Moco as background process. You can specify a shutdown port to shutdown Moco if required.

From my perspective, your suggestion is still a good idea to improve Moco which can extend Moco scenario. From current implementation, you need to adapt HttpRequest and HttpResponse.

Anyway, your moco-servlet implementation is welcome.