一、hessian的maven信息:

  1. <dependency>
  2. <groupId>com.caucho</groupId>
  3. <artifactId>hessian</artifactId>
  4. <version>4.0.38</version>
  5. </dependency>

二、入门示例,以web方式提供对外接口

(1)服务接口:

  1. package com.tianjunwei.hessian.server;
  2. public interface HelloService {
  3. public String helloWorld(String message);
  4. }

(2)接口实现:

  1. package com.tianjunwei.hessian.server;
  2. public class HelloServiceImpl implements HelloService{
  3. @Override
  4. public String helloWorld(String message) {
  5. return "hello," + message;
  6. }
  7. }

(3)web.xml的配置:

  1. <web-app>
  2. <servlet>
  3. <servlet-name>hessian-service</servlet-name>
  4. <servlet-class>
  5. com.caucho.hessian.server.HessianServlet
  6. </servlet-class>
  7. <init-param>
  8. <param-name>home-class</param-name>
  9. <param-value>
  10. <!-- 服务实现类 -->
  11. com.tianjunwei.hessian.server.HelloServiceImpl
  12. </param-value>
  13. </init-param>
  14. <init-param>
  15. <param-name>home-api</param-name>
  16. <!-- 服务接口 -->
  17. <param-value>com.tianjunwei.hessian.server.HelloService</param-value>
  18. </init-param>
  19. </servlet>
  20. <servlet-mapping>
  21. <servlet-name>hessian-service</servlet-name>
  22. <url-pattern>/hessian</url-pattern>
  23. </servlet-mapping>
  24. </web-app>

(4)客户端调用:

第(3)步中,通过配置servlet,这样就可以通过发布的http进行访问,根据Hessian提供的机制,这样就可以通过url进行服务调用。

  1. package com.tianjunwei.hessian.client;
  2. import java.net.MalformedURLException;
  3. import com.caucho.hessian.client.HessianProxyFactory;
  4. import com.tianjunwei.hessian.server.HelloService;
  5. public class HelloServiceMain {
  6. public static void main(String [] args) throws MalformedURLException{
  7. String url = "http://localhost:8080/hessian";
  8. System.out.println(url);
  9. HessianProxyFactory factory = new HessianProxyFactory();
  10. HelloService helloService = (HelloService) factory.create(HelloService.class, url);
  11. System.out.println(helloService.helloWorld("jimmy"));
  12. }
  13. }

运行结果:

http://localhost:8080/hessian

hello,jimmy

Hessian探究(一)Hessian入门示例的更多相关文章

  1. Hessian探究(一)Hessian与springMVC结合

    上一篇博客Hessian探究(一)Hessian入门示例我们初步简单的介绍了一下Hessian的使用入门示例,我们是通过Servlet来暴露Hessian的对外服务的,接下来我们介绍一下通过Sprin ...

  2. Hessian探究(一)Hessian与Spring结合

    上一篇博客Hessian探究(一)Hessian入门示例我们初步简单的介绍了一下Hessian的使用入门示例,由于Spring现在使用的实在是太广泛了,接下来我们介绍一下Hessian和Spring一 ...

  3. 【RPC】使用Hessian构建RPC的简单示例

    服务接口和实现 public interface HelloService { // 服务方法 String sayHello(String name); } public class HelloSe ...

  4. [WCF编程]1.WCF入门示例

    一.WCF是什么? Windows Communication Foundation(WCF)是由微软开发的一系列支持数据通信的应用程序框架,整合了原有的windows通讯的 .net Remotin ...

  5. Maven入门示例(3):自动部署至外部Tomcat

    Maven入门示例(3):自动部署至外部Tomcat 博客分类:  maven 2012原创   Maven入门示例(3):自动部署至外部Tomcat 上一篇,介绍了如何创建Maven项目以及如何在内 ...

  6. 1.【转】spring MVC入门示例(hello world demo)

    1. Spring MVC介绍 Spring Web MVC是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于 ...

  7. 【java开发系列】—— spring简单入门示例

    1 JDK安装 2 Struts2简单入门示例 前言 作为入门级的记录帖,没有过多的技术含量,简单的搭建配置框架而已.这次讲到spring,这个应该是SSH中的重量级框架,它主要包含两个内容:控制反转 ...

  8. Spring MVC 入门示例讲解

    在本例中,我们将使用Spring MVC框架构建一个入门级web应用程序.Spring MVC 是Spring框架最重要的的模块之一.它以强大的Spring IoC容器为基础,并充分利用容器的特性来简 ...

  9. Couchbase之个人描述及入门示例

    本文不打算抄袭官方或者引用他人对Couchbase的各种描述,仅仅是自己对它的一点理解(错误之处,敬请指出),并附上一个入门示例. ASP.NET Web项目(其他web开发平台也一样)应用规模小的时 ...

随机推荐

  1. java判断A字符串是否包含B字符串

    public static void main(String[] args) { String str="ABC_001"; if(str.indexOf("ABC&qu ...

  2. Tomcat出现validateJarFile-jar not loaded问题

    tomcat启动时问题: validateJarFile(...\WEB-INF\lib\servlet-api.jar)-jar not loaded. See Servlet Spec 2.3, ...

  3. .9-浅析express源码之请求处理流程(2)

    上节漏了几个地方没有讲. 1.process_params 2.trim_prefix 3.done 分别是动态路由,深层路由与最终回调. 这节就只讲这三个地方,案例还是express-generat ...

  4. 女儿开始bababababa的发声了

    女儿八个半月,开始bababababa的发声了,而不是像以前总啊啊啊的.

  5. 前端性能优化之-dns预解析

    预解析的实现: 1. 用meta信息来告知浏览器, 当前页面要做DNS预解析:<meta http-equiv="x-dns-prefetch-control" conten ...

  6. 解决问题redis问题:ERR Client sent AUTH, but no password is set

    是的,这又是一个坑爹的问题. 明明在redis.conf中设置了密码,而且redis还启动了,为什么说没有密码呢? 大家都知道linux下启动redis有很多种方法, 其中有 ./redis-serv ...

  7. delphi 给EXE文件增加区段

    学习 PE 可执行文件格式,用 delphi 实现给 EXE 文件增加区段 源码下载(StudyPE.zip) unit uStudyPE; interface uses Classes, SysUt ...

  8. Rails rspec测试报patch user_path(user) param not found: user的解决

    其实道理很简单,就是在User控制器的update方法中有一个验证: def user_params params.require(:user).permit(:name,:email,:passwo ...

  9. vuejs关于函数式组件的探究

    所以,在控制台里app1.exist 或app2.exist都可以控制是否显示字母. <!DOCTYPE html> <html lang='zh'> <head> ...

  10. lua 序列化函数

    local function f( ... ) print('hello') end local x = string.dump(f, true) loadstring(x)()