用户工具

站点工具


分享:技术:hessian:spring整合hessian

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

后一修订版
前一修订版
分享:技术:hessian:spring整合hessian [2015/08/03 00:29]
gxx 创建
分享:技术:hessian:spring整合hessian [2015/08/03 00:56] (当前版本)
gxx
行 242: 行 242:
 } }
 </​code>​ </​code>​
 +===== RmiServiceTest.java(测试单元调用) =====
 +<code java RmiServiceTest.java>​
 +package com.gxx.record.rmi;​
 +
 +import junit.framework.TestCase;​
 +
 +import com.caucho.hessian.client.HessianProxyFactory;​
 +import com.gxx.record.dto.RmiRequest;​
 +import com.gxx.record.dto.RmiResponse;​
 +import com.gxx.record.service.RmiService;​
 +
 +/**
 + ​* ​
 + * <dl>
 + ​* ​   <​dt><​b>​Title:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   远程调用测试类
 + ​* ​   </dd>
 + ​* ​   <​dt><​b>​Description:</​b></​dt>​
 + ​* ​   <dd>
 + ​* ​   <​p>​none
 + ​* ​   </dd>
 + * </dl>
 + *
 + * @author Administrator
 + * @version 1.0, 2015年8月2日
 + * @since record
 + *
 + */
 +public class RmiServiceTest extends TestCase {
 + /**
 + * 测试RMI
 + * @throws Exception
 + */
 + public void testRmi() throws Exception{
 + String url = "​http://​localhost/​record/​hessian/​rmi";​
 + HessianProxyFactory factory = new HessianProxyFactory();​
 + RmiService service =  (RmiService)factory.create(RmiService.class,​ url);
 + RmiRequest request = new RmiRequest();​
 + request.setBusinessCode("​CHECK_USER_PASSWORD"​);​
 + request.setName("​gxx"​);​
 + request.setPassword("​123456"​);​
 + RmiResponse response =  service.process(request);​
 + System.out.println("​结果:"​ + response.isSuccess() + ",​信息:"​ + response.getMessage());​
 + }
 +}
 +</​code>​
 +===== application-hessian-client.xml(spring注入调用) =====
 +<code xml application-hessian-client.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:​aop="​http://​www.springframework.org/​schema/​aop"​
 + xsi:​schemaLocation="​
 + http://​www.springframework.org/​schema/​beans ​
 + http://​www.springframework.org/​schema/​beans/​spring-beans-4.0.xsd">​
 +
 + <bean id="​rmiService"​ class="​org.springframework.remoting.caucho.HessianProxyFactoryBean">​
 + <​property name="​serviceUrl"​ value="​http://​localhost/​record/​hessian/​rmi"/> ​
 + <​property name="​serviceInterface"​ value="​com.gxx.record.service.RmiService"/> ​
 + </​bean>​
 +
 +</​beans>​
 +</​code>​
 +===== RmiController.java =====
 +<code java RmiController.java>​
 +package com.gxx.record.web.rmi;​
 +
 +import javax.servlet.http.HttpServletRequest;​
 +
 +import org.apache.log4j.Logger;​
 +import org.springframework.beans.factory.annotation.Autowired;​
 +import org.springframework.stereotype.Controller;​
 +import org.springframework.web.bind.annotation.RequestMapping;​
 +import org.springframework.web.bind.annotation.RequestMethod;​
 +import org.springframework.web.bind.annotation.ResponseBody;​
 +
 +import com.gxx.record.dto.RmiRequest;​
 +import com.gxx.record.dto.RmiResponse;​
 +import com.gxx.record.service.RmiService;​
 +
 +/**
 + * RmiController
 + ​* ​
 + * @author gxx
 + */
 +@Controller
 +@RequestMapping("/​rmi/"​)
 +public class RmiController {
 + /**
 + * 日志处理器
 + */
 + private final Logger logger = Logger.getLogger(RmiController.class);​
 +
 + @Autowired
 + private RmiService rmiService;
 +
 + @RequestMapping(value = "/​preRmiFtl",​ method = RequestMethod.GET)
 + public String preRmiFtl() {
 + return "​rmi/​preRmiFtl";​
 + }
 +
 + /**
 + * 远程调用
 + * @param request
 + * @param rmiRequest
 + * @return
 + */
 + @RequestMapping(value = "/​process",​produces="​application/​json"​)
 + public @ResponseBody RmiResponse process(HttpServletRequest request, RmiRequest rmiRequest) throws Exception {
 + logger.info("​远程调用:功能号=["​ + rmiRequest.getBusinessCode() + "​],用户名=["​ + rmiRequest.getName() + "​],"​
 + + "​密码=["​ + rmiRequest.getPassword() + "​]"​);​
 + return rmiService.process(rmiRequest);​
 + }
 +}
 +</​code>​
 +===== preRmiFtl.ftl =====
 +<code html preRmiFtl.ftl>​
 +<​!DOCTYPE html PUBLIC "​-//​W3C//​DTD XHTML 1.0 Transitional//​EN"​ "​http://​www.w3.org/​TR/​xhtml1/​DTD/​xhtml1-transitional.dtd">​
 +<html xmlns="​http://​www.w3.org/​1999/​xhtml">​
 + <​head>​
 + <meta http-equiv="​Content-Type"​ content="​text/​html;​ charset=utf-8"​ />
 + <​title>​rmi页面</​title>​
 + </​head>​
 + <​body>​
 + <form action="/​record/​rmi/​process.htm"​ method="​post">​
 + <​table border="​1">​
 + <​tr><​td>​功能号:</​td><​td><​input type="​text"​ name="​businessCode"​ value="​CHECK_USER_PASSWORD"/></​td></​tr>​
 + <​tr><​td>​姓名:</​td><​td><​input type="​text"​ name="​name"​ value="​gxx"/></​td></​tr>​
 + <​tr><​td>​密码:</​td><​td><​input type="​text"​ name="​password"​ value="​123456"/></​td></​tr>​
 + <​tr><​td colspan="​2"​ align="​center"><​input type="​submit"​ value="​校验用户名"/></​td></​tr>​
 + </​table>​
 + </​form>​
 + </​body>​
 +</​html>​
 +</​code>​
 +===== 演示 =====
 +{{ :​分享:​技术:​hessian:​hessian_1.png?​300 |}}
 +{{ :​分享:​技术:​hessian:​hessian_2.png?​500 |}}
 +{{ :​分享:​技术:​hessian:​hessian_3.png?​300 |}}
 +{{ :​分享:​技术:​hessian:​hessian_4.png?​500 |}}
分享/技术/hessian/spring整合hessian.1438532945.txt.gz · 最后更改: 2015/08/03 00:29 由 gxx