Hessian之简单使用
生活随笔
收集整理的這篇文章主要介紹了
Hessian之简单使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
以下是簡單的hessian服務(wù)代碼:
?
1.導(dǎo)包
<dependency><groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.38</version>
</dependency>
2.編寫HessianServerProxyExporter類,實現(xiàn)驗證
*** 自定義hessian服務(wù)發(fā)布,可用于自定義驗證服務(wù)
*
* @author smiledada
*
*/
public class HessianServerProxyExporter extends HessianServiceExporter {
@Value("${server.userName}")
private String userName;
@Value("${server.passWord}")
private String passWord;
private static final Logger log = LoggerFactory.getLogger(HessianServerProxyExporter.class);
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String authorization = request.getHeader("Authorization");
HessianContext.setRequest(request); //保存Request到Hessian線程上下文
if (StringUtils.isEmpty(authorization)) {
throw new NestedServletException("Auth Is Empty!");
}
String[] authArr = authorization.trim().split(" ");
String auth = authArr[1];
auth = new String(Base64.getDecoder().decode(auth));
String[] namePwdArr = auth.split(":");
String pwd = namePwdArr[1];
String name = namePwdArr[0];
// 驗證IP地址
String ipAddress=NetUtils.getIpAddress(request);
log.info(ipAddress+"進(jìn)入到本系統(tǒng)。。。。。。。。。。");
if (ipAddress.equals("127.0.0.1")){
// 驗證密碼
if (!passWord.equals(pwd)) {
throw new NestedServletException("密碼錯誤");
}
if (!userName.equals(name)) {
throw new NestedServletException("用戶名錯誤");
}
super.handleRequest(request, response);
}else { System.out.println("ip驗證失敗"); }
}
}
3.編寫Hessian服務(wù)api
public interface TestApi {/**
* 測試
*
* @return
*/
public Map<String, String> testt();
}
4.發(fā)布Hessian服務(wù)
//發(fā)布服務(wù)@Bean(name = "/testApi")
public HessianServiceExporter accountService() {
HessianServerProxyExporter exporter = new HessianServerProxyExporter();
exporter.setService(testApi);
exporter.setServiceInterface(TestApi.class);
return exporter;
}
轉(zhuǎn)載于:https://www.cnblogs.com/smiledada/p/10608510.html
總結(jié)
以上是生活随笔為你收集整理的Hessian之简单使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何保证消息不被重复消费~~~~~(如何
- 下一篇: 洛天依-元宵吃货节歌词