Spring对RMI支持的实际应用实例

OMAS系统中提供给业务系统的RMI客户反馈服务的实现服务暴露是通过Resource/modules/interfaces/spring-conf/serviceContext.xml配置文件实现的,而远程接口的实现类必须序列化(即实现Serializable接口)。

Resource/modules/interfaces/spring-conf/serviceContext.xml的内容如下:

<? xml version="1.0" encoding="UTF-8" ?>

<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" >

< beans  default-autowire ="byName"  default-lazy-init ="false" >

<!--  service实现类的配置  -->

< bean  id ="fbWebService"  class ="com.ce.omas.interfaces.service.impl.FeedbackWebServiceImpl"   />

< bean  class ="org.springframework.remoting.rmi.RmiServiceExporter" >

<!--  does not necessarily have to be the same name as the bean to be exported  -->

< property  name ="serviceName"  value ="FeedbackRMIService"   />

< property  name ="service"  ref ="fbWebService"   />

< property  name ="serviceInterface"  value ="com.ce.omas.interfaces.service.IFeedbackWebService"   />

<!--  <property name="registryHost" value="rmi://192.168.100.7"/>  -->

<!--  defaults to 1099  -->

< property  name ="registryPort"  value ="1199"   />

</ bean >

</ beans >


对应的暴露的服务接口如下:

public   interface  IFeedbackWebService {

/**

 * <b>方法用途和描述:</b> 客户反馈RMI服务端接口方法<br>

 * <b>方法的实现逻辑描述:</b> 通过RMI提供服务,Spring支持的RMI远程调用

 * 
@param  systemID : 业务系统的唯一标识

 * 
@param  feedbackType :用户反馈的类型(1-系统BUG、2-系统易用性、3-客服人员态度、4-运维人员态度、5-其他)

 * 
@param  feedbackContent :用户反馈的正文内容

 * 
@return  反馈是否成功 true | false

 
*/

public   boolean  setFeedback(String systemID, FeedbackType feedbackType,

String feedbackContent) 
throws  OMASServiceException ;

}


暴露的服务接口实现如下:

public   class  FeedbackWebServiceImpl  implements  IFeedbackWebService,  Serializable {

private   static  Log _log  =  LogFactory.getLog(FeedbackWebServiceImpl. class );

private   static   final   long  serialVersionUID  =   - 5532505108644974594L ;

/**

 * 客户反馈服务接口

 
*/

private  IFeedbackOperationService feedbackService;

/**

* 方法用途和描述: 注入运营模块的添加客户反馈的服务

@param  feedbackWebService 运营模块服务

 
*/

public   void  setFeedbackService(IFeedbackOperationService feedbackWebService) {

_log.info(
" 注入运营模块的添加客户反馈的服务 " );

this .feedbackService  =  feedbackWebService;

}

/**

* 方法用途和描述: 外部接口子系统中添加客户反馈的方法

@param  systemID :业务系统ID

@param  feedbackType :反馈类型

@param  feedbackContent :反馈内容

@return  操作是否成功 ture or false

 * 
@throws  ServiceException 

 
*/

public   boolean  setFeedback(String systemID, FeedbackType feedbackType, String feedbackContent)  throws  OMASServiceException {

_log.info(
" 进入到外部接口的添加客户反馈的方法 " );

if  (BlankUtil.isBlank(systemID)  ||  BlankUtil.isBlank(feedbackType)

||  BlankUtil.isBlank(feedbackContent)) {

_log.error(
" 添加客户反馈的接口参数为空! " );

throw   new  OMASServiceException( " omas.interfaces.001 " ); // 添加客户反馈的接口参数为空

}

WebServiceFeedbackVO vo 
=   new  WebServiceFeedbackVO();

vo.setFeedbackType(String.valueOf(feedbackType.getValue()));

vo.setFeedbackContent(feedbackContent);

vo.setSystemID(systemID);

_log.info(
" 调用运营子系统的添加客户反馈的方法开始! " );

try  {

if  (feedbackService  ==   null ) {

_log.error(
" 运营模块服务为空 " );

throw   new  OMASServiceException( " omas.interfaces.002 " ); // 运营模块服务为空

}

feedbackService.addFeedbackOperation(vo);

catch  (ServiceException e) {

_log.error(
" 调用运营子系统的添加客户反馈出现异常: " + e.getMessage());

if (ExceptionConstants.EXCEPTION_OMAS_FEEDBACK_VO.equals(e.getMsgKey())){ // 客户调用接口的对像为空

throw   new  OMASServiceException( " omas.interfaces.003 " );

if (ExceptionConstants.EXCEPTION_OMAS_FEEDBACK_SYSTEMID.equals(e.getMsgKey())){ // 业务系统标识ID为空

throw   new  OMASServiceException( " omas.omasservice.010 " );

if (ExceptionConstants.EXCEPTION_OMAS_FEEDBACK_SIZE.equals(e.getMsgKey())){ // 非法的业务系统唯一标识

throw   new  OMASServiceException( " omas.interfaces.004 " );

if (ExceptionConstants.EXCEPTION_OMAS_FEEDBACK_BASE.equals(e.getMsgKey())){ // 数据库访问出了一点小问题!

throw   new  OMASServiceException( " omas.interfaces.005 " );

}

throw   new  OMASServiceException( " omas.omasservice.000 " ); // 未捕获到的异常信息!

}

return   true ;

}

}

接口方法setFeedbackString, FeedbackType, String)的实现大家不用关心,其与RMI并无关系,只是一些纯业务处理逻辑而已,要注意的是接口实现类必须实现 IfeedbackWebServiceSerializable接口。

在客户本地的omasservice.jar包中客户反馈的RMI客户端的配置如下:

Resource/config/omasrmi-client.xml

<? xml version="1.0" encoding="UTF-8" ?>

<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd" >

< beans  default-autowire ="byName"  default-lazy-init ="true" >

< bean  id ="fbWebServiceProxy"

class
="org.springframework.remoting.rmi.RmiProxyFactoryBean" >

< property  name ="serviceUrl" >

< value > rmi://127.0.0.1:1199/FeedbackRMIService </ value >

</ property >

< property  name ="serviceInterface" >

< value > com.ce.omas.interfaces.service.IFeedbackWebService </ value >

</ property >

</ bean >

< bean  class ="com.ce.omas.omasservice.service.impl.FeedbackRMIClientImpl" >

< property  name ="feedbackWebService"  ref ="fbWebServiceProxy"   />

</ bean >

</ beans >


客户端调用RMI服务的方法如下所示:

/**

* 方法用途和描述: 客户反馈:通过RMI方法与OMAS通讯

* 方法的实现逻辑描述:

@param  feedbackType

@param  feedbackContent

@return

@throws  OMASServiceException

*/

public   static   boolean  setFeedback_RMIClient(String systemID, FeedbackType feedbackType, String feedbackContent)  throws  OMASServiceException {

if  (systemID  ==   null   ||   "" .equals(systemID)) {

_log.error(
" 业务系统标识<SystemID>为空或不是对象 " );

throw   new  OMASServiceException( " omas.omasservice.010 " );

}

String rmiClientConfigFilePath 
=  PropertyReader .getValue(ConfigConstants.OMASSERVICE_CONFIG_PATH, ConfigConstants.RMI_CLIENT_CONFIG_FILEPATH);

if  (rmiClientConfigFilePath  ==   null   ||   "" .equals(rmiClientConfigFilePath)) {

_log.error(
" 配置文件错误:Key<rmiClientConfigFile>为空或不存在 " );

throw   new  OMASServiceException( " omas.omasservice.006 " );

}

_log.info(
" rmiClientConfigPath =  "   +  rmiClientConfigFilePath);

ApplicationContext context 
=   null ;

try  {

context = new ClassPathXmlApplicationContext(rmiClientConfigFilePath);


catch  (Exception e) {

_log.error(
" 客户反馈:解析rmi-config.xml文件时出现异常: "   +  e);

_log.info(
" rmi-config.xml文件路径: " + rmiClientConfigFilePath);

throw   new  OMASServiceException( " omas.omasservice.007 " );

}

IFeedbackWebService service 
=   null ;

try  {

service = (IFeedbackWebService) context .getBean("fbWebServiceProxy");


catch  (Exception e) {

_log.error(
" 从Spring的RMI客户端Bean配置文件获取服务对象时出现异常: "   +  e);

throw   new  OMASServiceException( " omas.omasservice.009 " );

}

boolean  bln  =  service.setFeedback(systemID, feedbackType, feedbackContent);

_log.info(
" 反馈操作是否成功[true|false]: "   +  bln);

return  bln;

}


转载自:http://www.blogjava.net/zhenyu33154/articles/320245.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值