Calling self's API on application Restart(Grails 3.3.9) (Tomcat Restart) - gradle

While building a grails 3.3.9 application, I've encountered a scenario where I need to call its own API on application restart (for a specific purpose). I long as I know we can't make an API calls via boostrap.groovy, So an alternate option I found the Application.main method from where I can make own API calls.
But this is only working on Grails - run mode. I need to make this working on Grails - war mode-as I have to deploy the war in the production environment once it verified in QC.
I can have the cron setup to do this but I am looking for the grails inbuilt function.
Others information:
Grails:3.3.9
Gradle:4.10.3
Tomcat 8.5.50

Related

Update for JavaEE application

Our application are built on Spring boot, the app will be packaged to a war file and ran with java -jar xx.war -Dspring.profile=xxx. Generally the latest war package will served by a static web server like nginx.
Now we want to know if we can add auto-update for the application.
I have googled, and people suggested to use the Application server which support hot deployment, however we use spring boot as shown above.
I have thought to start a new thread once my application started, then check update and download the latest package. But I have to terminate the current application to start the new one since they use the same port, and if close the current app, the update thread will be terminated too.
So how to you handle this problem?
In my opinion that should be managed by some higher order dev-ops level orchestration system not by either the app nor its container. The decision to replace an app should not be at the dev-ops level and not the app level
One major advantage of spring-boot is the inversion of the traditional application-web-container to web-app model. As such the web container is usually (and best practice with Spring boot) built within the app itself. Hence it is fully self contained and crucially immutable. It therefore should not be the role of the app-web-container/web-app to replace either part-of or all-of itself.
Of course you can do whatever you like but you might find that the solution is not easy because it is not convention to do it in this way.

Spring-Boot Vaadin deploy project on jetty

How to deploy a Spring boot vaadin project on jetty using intellij, the Idea behind that is to refresh the project after each changes without restarting the server.
I don't really understand the people who downvote a question without answering it. however here is the answer:
in Spring framework using spring-dev-tools, you have the option to deploy the project whenever the class path changes( in intellij the class path change event is triggered when we rebuild the project, in eclipse class path change event is triggered as soon as we hit the save file of any class). Server will restart (tomcat or jetty) and load the project (Restart method).
we could overcome this expensive approach using third party plug-ins such as JRebel. JRebel will only deploy the class that has been changed.
consider developing a web app and consider making about 100 runs a day, everytime the server restarts it consumes 3 seconds. do the math

How to load a WAR module into Spring's built-in Tomcat running in a standalone?

I am having three modules in my Maven project:
parent
rest-api # Spring REST API
web-client # AngularJS web client
application # Project to bundle it all up for a standalone
I am not sure if I have here an "elegant" solution so please hit me with a stick if that is complete garbage, but this is how it works - or how it's supposed to work:
rest-api
Module rest-api does simply offer the REST API and other core functionality - basically it is pure server code. It is a jar artifact.
web-client
To separate client and server code I am having the module web-client. It is a war project that hold the client webapp.
application
This module is supposed to glue it all up. It depends on rest-api and web-client. It does two important things:
It's pom.xml uses the spring-boot-maven-plugin to build a standalone runnable jar - my ultimate goal
It provides the main(String args[]) method that starts the #SpringBootApplication with SpringApplication.run(EasyModelAccessServer.class, args);
What I am currently able to is tell Eclipse to run this in a servlet container. The server boots up and I my two resources, the rest-api and the web-client working. Everything is fine so far.
The issue
What is not fully working is the standalone. If I package up the whole thing and run the server:
$ path/to/application: mvn clean package
$ path/to/application: java -jar target/application.jar
Only the REST API will work. The reason is because the web-client is not added or introduced as a web app to the Spring built-in Tomcat.
The question
is how I can make this work. There are two options which come to my mind:
Somehow sneak in the web-client.war file into the application.jar such that it is available as a resource and programmatically call tomcat.addWebapp("/web-client", "path/to/web-client.war") (or something like that) to load the additional service
Hope that the spring-boot-maven-plugin or another Spring Maven plug-in can do that for me and find somebody that links me to an example.
I've tried it with 1. but I didn't succeed to move web-client.war into application.jar but I am also not sure if I should actually do that.
FAQ
Q: "Why do you separate everything instead of merge all those modules into a server module where the Spring Maven plug-in would do everything for you out of the box?"
A: I really want to separate the client code from the server code. I could however merge web-client into application but last time I tried that I had 10 other issues why this did not work out so I decided to keep it that way and that it actually shouldn't be so hard to load an additional server resource.
Q: "Can I take a look at the project?"
A: Yes, you can. Just take a look: https://github.com/silentsnooc/easy-model-access Please forgive me that I am currently using tabs instead of whitespaces - I am going to change that as soon as I got everything up and running.

Using Google App Engine modules for multi-thread backend update of a Cloud endpoints project

I'm building "read-only" webservice (Google Cloud Endpoints as backend for an Android App) so I created a project using maven:
mvn archetype:generate -Dappengine-version=1.9.10 -Dfilter=com.google.appengine.archetypes:
and selecting archetype hello-endpoints-archetype to have some sample code to work on.
This works well and my app is correctly calling the service as expected (and the service is correctly supplying the data in return).
Now I have to implement an "update" service to periodically (4 to 6 times a dya) update the data supplied to the app. So I added a servlet to my project to be called by cron. Trouble is: one of the library used during this update uses multi-threads which cause an AccessControlException to be thrown because apparently multi-thread is only allowed in backend modules...
But after having read dozens of pages on google app engine, I still don't know how to "break" my application into modules so that particular servlet would be run as a backend module while the already existing servlet keep working as they do. So far, all I got was that I should use an EAR application composed of several WAR modules, but I don't even know if my current application is an EAR or not...
I'm using Eclipse Luna, maven 3.2.1 (embeded with Eclipse), google app engine 1.9.10, writing in Java
Could anyone please help me by explaining the directory structure and/or configuration files I have to look at, modify and/or add?
Thanks for any help provided!
You can find an example of multi-modules project here.
However, note that even in backend modules the threading is limited to 50 threads, as stated here.

tomcat: guvnor & webservice load order

I have guvnor deployed on tomcat 7. Now need to deploy a wrapper webservice around the BRMS. The webservice is a spring-ws and uses #Autowired kbase dependency injection. kbase is configured in spring-context XML as (not literal):
<drools:resource id="xxx" source="http://localhost:8080/guvnor/.../<package>/LATEST
Now the problem is tomcat first loads the webservice which fails to initialize as the guvnor URL is not up yet.
I can work around this by first starting only guvnor along with tomcat startup and then copy the WS war to the webapps folder. This works but is painful to do everytime.
What is the best approach?
I have seen this thread, but not sure if it will work in this context: Is there a way to enforce a deployment order in tomcat6?
Tried the following ways to address this:
Tomcat brings up both services on starup. The initialization of webservice fails but bring up the webservice manually through tomcate admin interface.
Use a script to do the same as above to bring up the webservice after a delay.
Change the drools package initialization to load through drools API instead of through config files along with a retry logic.
All of these work, but retaining the last option in the production code.

Resources