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

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.

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.

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.

Dart with Maven (in Spring Boot App)

I like Dart, I have been playing with it for a while. I'd like to integrate with my Maven web app project based on Spring Boot.
I suppose the correct way is to use dart-maven-plugin. But I'm not sure how to properly glue it in place. Spring Boot has its own structure, Maven as well and Dart makes that none the better.
I will need probably the entry point for Dart part, means Spring Boot templates folder needs to include the html resources from Dart.
I would appreciate any idea, best practices.
PS: the aforementioned dart-maven-plugin is not really vivid, should I be afraid using it at all, as I don't see any progress there, compared to Dart itself.
UPDATE
So this can be solution(note I have only one so called "entry point"- .dart file so far)
normal Dart structure in src/main/dart
user dart-maven-plugin's pub build command into ${project.build.directory}/dart
maven-resources-plugin:copy-resources from ${project.build.directory}/dart/web to ${project.build.directory}/classes/public/
make war
I'm still able to use Intellij's Dart integration from src/main/dart.
The Spring Boot maps classes/public/ folder to / so the dart file and html files are loaded properly.
It's not ideal, but it works so far. Please fell free to write down any comments.
I have tried a few times to use dart in a maven project myself and always ran into some problems. Right now I'm developing my dart apps in a separate module that I build with pub which connects to the maven based java backends with rest.
This has several advantages for me, for example:
I can use pub and avoid problems with outdated maven plugins
I use the serving mechanism that fits best for the static dart code and assets (in my case a docker image with nginx)
I have a clean separation of backend and frontend code with a tailored REST API
As I like the microservice approach I also use spring session together with zuul (via spring-cloud).
If you want to combine dart with generated html from for example JSPs or another templating engine, then this isn't a good approach for you. But IMHO dart is not yet very well suited for these kind of architectures.

How to run a project containg drools in Tomcat7?

I have created a Dynamic web project which also uses drools for providing some functionality. When i put the WAR file in Tomcat7 and the server, the drools part does not work.
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
After this line which is first line relating to drools, nothing happens.
Is some configuration required to run my project containing drools 5.5.0 Final in the Tomcat7.
Please help me. I am badly stuck and I am new to drools.
You'll have to add some facts to the working memory and execute(fire) the rules. Check out these examples on GitHub
P.S. Probably not related to Tomcat in any way. Might be worth while to try getting the rules executed from command line app first.
You need to check all the dependencies that are added to your web application (WEB-INF/lib) make sure that drools has all the required deps there, because if not it will not be able to create the knowledge builder. Most of the time if it is failing is because that you forgot to add the deps in the web app.
The following project in GitHub is a web application, containing some REST-style endpoints for validating IBANs. It uses Drools 5.5 to perform that evaluation.
https://github.com/gratiartis/sctrcd-payment-validation-web/
It generates a .war which can be loaded into Tomcat, and could be a useful starting point. The knowledge base is wrapped within a Spring service:
https://github.com/gratiartis/sctrcd-payment-validation-web/blob/master/src/main/java/com/sctrcd/payments/validation/RuleBasedIbanValidator.java
Following through how that creates a knowledge base and session might help you see where your code is going wrong.
As a bonus, you can run it up in Tomcat using "mvn tomcat7:run" to test it out immediately.

xmlaccess deploy portlet with library reference

I have problem with deploying JSR168 portlet using xmlaccess. I have no problem with deploy and join to conrete page but I would like to add shared library reference automatically. Is it possible?? I added shared library named 'libshared' using IBM WS console. Can I add this reference in input xml using by xmlaccess?
I don't think you can do this in xmlaccess. But you may try putting a reference to the library under the Manifest.MF file of the META-INF directory of your portlet's war file.
Or could just put the shared jar file under your /shared/ext directory. Or you could put it inside your wps.ear file. Mind you, either of these two solutions would share your library with the entire portal installation, rather than just select portlets.
You can deploy the application using wsadmin or similar and use that to update the classpath (i.e. for the shared library), you can then use xmlaccess to deploy the portlets and reference the previously deployed application - although I think this may only work in WebSphere Portal 6.1.
Give me a shout if you need further details.
I encountered this as well, a while ago... and researched it to the max, including spending some time chatting with IBM's support in various levels.
The XMLAccess protocol doesn't provide for such "system-level" configuration alongside Portlet application deployment; it can only be used to install, customize and uninstall Portlet applications and related artifacts.
If your deployment strategy involves deploying WAR files directly through XMLAccess, then you will have to manually add the shared-library to the application through the WAS admin console; this will have to be done manually because, when deploying WAR files through XMLAccess, an EAR with some random name is being created by WebSphere Portal to "host" your WAR file; hence you can't script the attachment of a shared library.
(alternatively, you may wish to add the shared library to the server's (WebSphere_Portal) classpath)
If your deployment strategy, instead, involves deploying Portlet applications packaged as EARs, then you're in a better position; you could automate the shared-library attachment as part of your EAR deployment process, then use XMLAccess to inform WebSphere Portal about the location, in the EAR, of your Portlet applications (which is what Michael mentioned above; it works in WebSphere Portal 6.0 as well).
Good luck.

Resources