Visual Rules Solution Java Integration Interface <5> - Java classes are invoked through Servlet - xml format

webrule is a web management platform provided by VisualRules. Here webrule is placed in the webapps directory under Tomcat under the VisualRules installation directory, such as D:\VisualRules\Tomcat\webapps. Start Apache Tomcat rules, as shown below:





Configure web.xml

Configure webrules Under the web.xml, both
D:\VisualRules\Tomcat\webapps\webrule\WEB-INF\web.xml.
Reference: webrule\WEB-INF\web.xml.
The configured web.xml should pay attention to the following information:
<servlet>
<description>
</description>
<display-name>RuleServlet</display-name>
<servlet-name>RuleServlet</servlet-name>
<servlet-class> com.flagleader.webrules.RuleServlet</servlet-clas>
<init-param>
<param-name>onlyregist</param-name>
<param-value>true</param-value>
</init-param>

<param-name>edition</param-name>
<param-value>stan</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>RuleServlet</servlet-name>
<url-pattern>/servlet/readrule.servlet</url-pattern>
</servlet-mapping> Only after
setting the above can it be called:
http:// localhost:8880/webrule/servlet/ruleservlet.servlet

configuration description:
The servlet description document webrule\WEB-INF\readme.txt in web.xml.
Parse web.xml:
..\webrule\WEB-INF\web.xml, "web.xml" parsing.txt is a one-by-one explanation of the servlets in web.xml, which can better determine the attributes that need to be configured, you can Streamlined web.xml file.

Compiled file storage directory:
put the compiled file in ..








Visit http://localhost:8880/webrule/server/, the default login username is admin, and the password is admin123, as shown in the figure below:






Add tasks and services on the webrule management platform:
After logging in, click the tab "Rule Execution Version" to see Go to the compiled file stored in the ..\webrule\WEB-INF\classes directory (that is, 4. The compiled file is stored in the directory), click the tab "rule execution version" - "public version", check the student entry student.add , click Add to Task, as shown in the figure below:






Click the tab "Rule Execution Version", click "Public Version" in the tree menu on the right, check the student entry student.add, and click Add to Service, as shown in the figure below:






View tasks and services:
Click the tab "Rule Execution Task" to view the student entry of the task, as shown in the figure below:






Click the tab "Rule Execution Service" to view the service student entry, the service needs to be started, as shown in the figure below:






Add a java test class
in the java project Add a java class named Test4.java, and its content is edited as follows:
package com.flagleader;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.flagleader.engine. RuleEngine;
import com.flagleader.engine.RuleEngineException;
import com.flagleader.engine.RuleEngineFactory;
import com.flagleader.engine.RuleEngineManager;
import com.flagleader.engine.RuleService;
import com.flagleader.engine.RuleServiceException;
import com.flagleader.engine.impl.LocalRuleServiceFactory;
import com. flagleader.engine.impl.RuleServerServletFactory;
/**
* Call the compiled file under the default file in the specified directory
* The interface used is RuleService, which can be used for local calls, as well as service calls
* servlet calls
* @author Administrator*
*/
public class Test4 {
public static void main(String[] args) {
try {
// Factory mode, this interface can be used for local calls and service calls
RuleService engine =new RuleServerServletFactory("http://localhost:8880/webrule/servlet/ruleservlet.servlet").getRuleService();
// Pass the rules in the form of dto
Student student = new Student(1, "Li Li" , 12, 'male', "sixth grade", "none");
// execute the rule, where "student.add" is the full name of the rule, and student is the incoming parameter
engine.executeBeans("student.add", student) ;
//Determine whether engine.get("studentList") is a collection type
if(engine.get("studentList").getClass().isAssignableFrom(java.util.ArrayList.class)){
//After executing the rules, To get data, "studentList" must be the same as the variable name of the memory table data in the rule
List list = (List) engine.get("studentList");
// Since the rule uses the list<list> type, it is necessary to do two Subconversion
List list1 = (List) list.get(0);
// The number of loops is the number of fields in the object
for (int i = 0; i < 6; i++) {
System.out.print(list1.get(i) + "\t");
}
}
} catch (RuleServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Execute java test class Click
After execution, you can see the following results:






it means that the student.add rule package has been called, and according to the passed parameters, the returned processing results are displayed in the form of list<list>.
Similarly, any other java class can complete the work of calling the rule package by adding the above code.



Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326752318&siteId=291194637