加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Visual Rules规则引擎 + WebService简单的项目案例【连载一】

发布时间:2020-12-16 22:34:53 所属栏目:安全 来源:网络整理
导读:首先光看WebService 就看了好几天才看一点明白,网上的资料龙蛇混杂。经过自己一遍遍测试验证,途中各种报错,架包不兼容,各种百度,终于让我发现一个还是能看明白的,然后就套用在了最近的登录项目上,结合Visual Rules规则引擎简单实现操作下了。 先创建

首先光看WebService 就看了好几天才看一点明白,网上的资料龙蛇混杂。经过自己一遍遍测试验证,途中各种报错,架包不兼容,各种百度,终于让我发现一个还是能看明白的,然后就套用在了最近的登录项目上,结合Visual Rules规则引擎简单实现操作下了。

先创建一个接口类:TpyeService

@WebService
public interface TypeService { 

        //登录
	public String call(String USERNAME,String PASSWORD);


}

再用一个类去实现这个接口:TypeServiceImpl

package com.service;

import javax.jws.WebService;

import com.flagleader.engine.RuleEngine;
import com.flagleader.engine.RuleEngineException;
import com.flagleader.engine.RuleEngineFactory;

/**
?* endpointInterface??? 接口类的路径??????? serviceName??? 接口类名
?*/
@WebService(endpointInterface = "com.service.TypeService",serviceName = "TypeService")
public class TypeServiceImpl implements TypeService{
?
?? ?
?? ?public String call(String USERNAME,String PASSWORD) {
?? ??? ?//规则引擎配置
?? ??? ?RuleEngine engie = RuleEngineFactory.newInstance().getRuleEngine();
?? ??? ?//对应规则引擎配置里面的 name , pass ?
?? ??? ?engie.put("name",USERNAME);
?? ??? ?engie.put("pass",PASSWORD);
?? ??? ?try {
?? ??? ??? ?//实现规则引擎的规则包
?? ??? ??? ?engie.excute("login.rsc");
?? ??? ??? ?//返回结果
?? ??? ??? ?return engie.getString("res");
?? ??? ?} catch (RuleEngineException e) {
?? ??? ??? ?e.printStackTrace();
?? ??? ?}
?? ??? ?return engie.getString("res");
?? ?}

}

接下来配置applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xsi:schemaLocation="  
 http://www.springframework.org/schema/beans   
 http://www.springframework.org/schema/beans/spring-beans.xsd   
 http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

	<!-- implementor:为实现类的完整路径名 -->
	 
	<jaxws:endpoint id="TypeService" implementor="com.service.TypeServiceImpl" address="/typeS" />
	
	<!-- actory-bean="clientFactory"  一定要和下面的bean   id="clientFactory"    一样  
		暂时只能处理一个			
	-->
	 
	<bean id="xxx" class="com.service.TypeService" factory-bean="clientFactory"
		factory-method="create"/>
		
	<bean id="clientFactory" class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
		 <property name="serviceClass" value="com.service.TypeService" />
                 <property name="address" value="http://Admin-feng:8088/webService/Services/typeS" />
	</bean>
	  
</beans>
最后是配置 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>  
       <param-name>contextConfigLocation</param-name>  
        <param-value>classpath:applicationContext.xml</param-value>  
  </context-param>  
  <listener>      
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener>  
	<servlet>
		<servlet-name>CXFServlet</servlet-name>
		<servlet-class>
			org.apache.cxf.transport.servlet.CXFServlet
		</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>CXFServlet</servlet-name>
		<url-pattern>/Services/*</url-pattern>
	</servlet-mapping> 
</web-app>

接下来就是结合规则引擎开发如下:

对象库中添加三条数据



jy? 是数据库名? USERS 是表名 都是用规则引擎 数据库配置器 连接ORACLE 简单易懂好操作
自定义查询中勾选


最后让我们在规则引擎里测试下

到此操作就结束了!!!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读