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

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

发布时间:2020-12-16 22:34:32 所属栏目:安全 来源:网络整理
导读:接下来我们试试用规则引擎做截取,赋值,取值等等一系列操作。 还是接上上次的项目,这次传入的不是简单的 name 或者 pass 。 接口类:TypeService package com.service; import javax.jws.WebService; @WebServicepublic interface TypeService { //登录pub

接下来我们试试用规则引擎做截取,赋值,取值等等一系列操作。

还是接上上次的项目,这次传入的不是简单的 name 或者 pass 。

接口类:TypeService

package com.service;
 
import javax.jws.WebService;
 
@WebService
public interface TypeService {
 
	//登录
	public String call(String USERNAME,String PASSWORD);

	
	//xml格式的验证
	public String StringCall(String xml);
}

再用一个类去实现这个接口: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{
 
	//规则引擎配置
	RuleEngine engie = RuleEngineFactory.newInstance().getRuleEngine();
	public String call(String USERNAME,String PASSWORD) {
	
		//对应规则引擎配置里面的 name , pass  
		engie.put("type","getCall");
		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");
	}
 
	public String StringCall(String xml) {
		engie.put("type","getXml");
		engie.put("StringXml",xml);
		try {
			engie.excute("login.rsc");
			return engie.getString("ResultXml");
		} catch (RuleEngineException e) { 
			e.printStackTrace();
		}
		return engie.getString("ResultXml");
	}

}

这次多加了一个属性,“type” 用于判断传入的时候判断执行哪个方法。

applicationContext.xml, web.xml? 不变

对象库中添加六条数据,等等一系列的操作……

StringXml 项目要求传过来的是 xml 格式的数据,我当然就用规则引擎做起,操作简单,省去很多手打代码。最后返回的也是 xml 格式,只是从查询中返回的内容变了。

到此操作就结束了!!!

(编辑:李大同)

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

    推荐文章
      热点阅读