版本:Hessian 4.0.38
//客户端代码
String url = "http://192.168.2.88:8081/sh/orders";
HessianProxyFactory factory = new HessianProxyFactory();
factory.setUser("yaoxun"); //增加用户
factory.setPassword("123456"); //增加密码
OrdersService ordersService = (OrdersService) factory.create(OrdersService.class,url);
Order order = ordersService.getOrderByOrderCode("123456789");
System.out.println(order.getId());
服务器端代码
重写Hessian servlet的service方法,在该方法中验证
public class CustomHessianServlet extends HessianServlet {
private static final long serialVersionUID = 5652773984778690110L;
private String authPwd = "hessian";
@Override
public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
String auth = httpServletRequest.getHeader("Authorization");
System.out.println(auth);
super.service(request, response);
}
获取Authorization后需要进行base64解码