Forum Discussion

Lavalyte's avatar
Lavalyte
Occasional Contributor
8 years ago

Deployed mock server startup script

Is it possible to include a groovy script to run when the generated war for a mock server is started up on a tomcat server?

I would like to set some global constants and datasets.

 

 

11 Replies

    • Lavalyte's avatar
      Lavalyte
      Occasional Contributor

       

      I know you can put groovy scripts in to be called at various points, but what I would like to be able to do is write some overarching code so I can do things like keep an object in memory across multiple web method calls.

       

      In my use case I have have several web methods that build up a request into an external system. I want to be able to store objects in memory to represent these requests, and would rather have code external to the web method hooks to represent the structure and storage of the requests.

       

      For example, I would like to instantiate the map that stores the requests here, and just let the scripts look up the map to get the request to work with it.

       

      Further, this would be the cleanest place if I want to instantiate globally available stuff like lists of mock customer names or street names or similar and don't want to push that stuff into a database table.

       

       

       

  • KarelHusa's avatar
    KarelHusa
    Champion Level 3

    I would suggest to try the following -- choose one of the mock services and utilize it's start script. The script can do the setup for all mock services included within WAR. The start script is executed when a mock service is started, so should be executed just once as you need.

     

    I use dynamic mock services with Groovy scripts deployed as WAR, but not the start scripts in particular.

     

    I am not aware of another of-the-shelf functionality you could use. If this won't work, you will probably need to customize the WAR.

     

    Karel

     

    • Lavalyte's avatar
      Lavalyte
      Occasional Contributor

       

      Yeah, that was my fallback.

      It's a shame because I would love to have somewhere I could dump all the class definition code I'm going to have to write and keep the scriptlets relatively clean.

       

       

       

      • Lavalyte's avatar
        Lavalyte
        Occasional Contributor

        I think this is a difference between open source and NG Pro.