Drools integrated in a web application - java

I'm just new with drools and web development, I'm just wondering if how can i integrate Drools in a Web Application, I'm using JSP and Servlet technology if I'm not mistaken with the term. I'm also planning of using MVC pattern not SpringMVC.
What I already done is:
Downloaded Drools and jBPM as plug-in in eclipse ( Able to create a Drools Project as a proof)
Already create a Dynamic Web Project, running and using Tomcat as a server
My question is where should i put Drool library for me to use the rules depends on the user's input in a JSP? Or if i missing something kindly tell me.

In general, libraries (jar files) should be put in the WEB-INF/lib folder of your web application, which can then be packaged as a whole in a .war file. Tomcat (or whichever servlet container you decide to use) will then load them in the classpath as part of its webapp initialisation. Drools might require specific configuration to tell it where it will find the rule files to load them, check the Drools documentation for that.
I can assure you it works from within a web app and also within an application using the Spring framework. I've seen it work with web services using JAX-WS (Apache CXF) with Spring on Tomcat exposing web services which use Drools to determine what business logic to apply.

Related

How can we use Struts-1 and Spring-Boot together in an application?

I'm working in an old web application which is using Struts-1 with Hibernate. There we're using full-fledged functionality of struts1 with ActionServlet as the front controller, struts-config.xml as configuration file etc. We are using tomcat-9 for deploying and running the war file. Now there's a requirement to use Rest-API in the application for which I need to introduce Spring Boot in the application for the first time.
I'm little confused, is it really possible to correlate Springboot with Struts1 ??
If yes, then How can I achieve that? Can anyone help me what will be the possible configuration changes, which new files I need create and How they both can work in the application??
Springboot has embedded tomcat right? then, how these two different technologies will work together? I need an overall idea for this. Please help.

Is there a way to deploy/update Spring Batch Jobs seperately?

We're running a Spring Batch Web-Application for Importing CSV Files into a Database. This Web-Application is currently evolving and is constantly extended by new jobs.
the current update procedure looks like this:
1. Write new Code
2. Build a war file
3. Deploy the newly build war file and replace the whole Web Application on the Tomcat Webserver
This might bring us into trouble, when the running system is currently importing / writing Files to the Database.
I wanted to know if there is a smart way to maybe upgrade the spring batch jobs seperately ?
I already thought about splitting the Project into many different Web-Applications but this might be a lot of overhead with all the libraries bundled into the war file(s).
Are there any best practices for building that sort of Application ?
Thanks for your Help !
This packaging model is known to cause a lot of issues like the one you are facing. I recommend to package your jobs as separate jars and make your application launch those jobs in separate processes. With this model, you can deploy/upgrade jobs without impacting the web application used to launch them.
For the record, Spring Batch Admin suffered from this packaging model (as described here) and the recommended replacement is Spring Cloud Data Flow (which uses the model I described previously)

Spring boot + Hibernate - technical questions

I have some questions about Spring Boot and Hibernate.
I discussed with one developer and he said me he compile his Rest Api, developed with Spring Boot, in Jar and used the tomcat server provided by Spring Boot and deploy the jar on the server. But in my case, i use the war packaging and i deploy on my tomcat server but he said it’s less performing.
I don’t know why and i asking me if you developed in microservices your Resp Api with Spring boot and you use his solution, do you create multiple tomcat instance ?
About hibernate, i used HQL for some queries and he said me it’s bad way because it’s dangerous with Sql injection, it’s true ?
I need some answers of people who can advice me.
Sorry if my english, it’s not great and thank you very much, in advance, for your answer.
In the Java Cloud space there are 2 major directions:
Java EE:
Create a Docker base image which includes a Java EE application/ web server such (e.g. Tomcat, WildFly, GlassFish,...)
Create a (thin) WAR file
Create a Docker image based on your base image which deploys the WAR file to the application server
Spring Boot:
Create a single JAR file using the Spring Boot Maven Plugin
Create a Docker image which executes the JAR file
I guess you could also mix the two approaches (create a Spring Boot WAR file), but the single JAR file approach is much more common with Spring Boot (I'm currently using this approach).
Some Java EE experts such as Adam Bien promote the first approach (less dependencies, smaller WAR files, smaller Docker images, more standard APIs (though what "standard" means is currently changing with the transition from Java EE to Jakarta EE)).
I can't tell you which one has a higher performance. Either way there will be one server started per Docker image.
Regarding Hibernate and SQL injection:
I'm not using HQL but JPQL, but in the end it's more or less the same as with JDBC: Don't string concatenate queries with input from the user. Always use some kind of prepared statements with variables to format the user input.
If you are using spring boot you implement more or less a standalone application (even if it´s a webapplication), therefore yes there will be an own embedded tomcat, jetty, whatever instance for each spring boot application.
SQL injection has nothing to do with the way how you deploy an application, it´s only a question how you create your HQL queries.
However, that´s an interesting discussion. In our company we are quite old fashioned and create an WAR file of our webapplication, and deploy it on our Glassfish server where serveral other web applications are running under the same instance.
Florian

Hot plug for web applications modules

I have a web application running in a servlet container (Tomcat). My plan is to use hot plug in order to add and remove additional modules to the running web application.
These additional modules just contain some business logic but not any web related stuff like servlets, JSP pages or HTML files.
What is the best way to do this?
I thought about switching from Tomcat to Glassfish in order to use OSGi.
I also thought about using Apache Felix with Tomcat.
What are the alternatives?
OSGi is definitely the right technology if you want to create a modular application that can be updated quickly without downtime.
You have a couple of choices:
You can start with an OSGi container like Apache Felix, and deploy bundles into that container for both your application and a webserver (most of them are based on Jetty). That way, everything is a bundle and can be updated if needed. If you're starting from scratch and have no constraints on existing servlet containers that you must use, this is the way to go.
If you have to keep working with your existing servlet container, you can deploy a WAR that embeds an OSGi container and the OSGi container will load all the bundles that make up your application. In this case, you can deploy a special "bridge" bundle that will register Servlets and Filters with the "host" servlet container.
Starting with Glassfish is a bit like the first option, since Glassfish itself is built on Felix. You just get a lot of "extra" bundles pre-installed in your application. If you use 80% of those anyway, that is probably worth it. If you hardly use any of Glassfish's (JavaEE) features in your application, you're probably better off starting with just Felix and selecting components there.

Use jsf as template engine on EAR

Thinking about html e-mails for our e-commerce site I thought about reusing jsf and other 3rd party libraries as a template engine to create the e-mails on our application server (Glassfish 3, EAR).
Is it possible to manually run jsf with a local file and initialize the necessary bean to capture the html output to be saved in a String?
Why have a look at other template frameworks if jsf provides much flexibility and could do the job.
I am currently using JSF on glassfish for generating emails inside of a EJB. I based my work on the following blog post:
https://rogerkeays.com/how-to-create-email-from-jsf-templates
Basically it works when the JSF is rendered in a request that was made from the web.
I currently try to also use JSF in unit tests and scheduled executions but I currently have trouble to start JSF.
The following class is doing the initialization of Faces:
com.sun.faces.config.FacesInitializer
Unfortunately it requires a complete implementation of the Servlet 3.0 implementation. In my cases starting the servlet engine also requires an JMX server.
From my current experience I would recommend to use a template engine with less dependencies e.g.
Velocity http://velocity.apache.org/
Freemarker http://freemarker.org/

Categories

Resources