当前位置:首页 > 开发 > 互联网 > 正文

Hessian 简单例子

发表于: 2015-03-12   作者:antlove   来源:转载   浏览:
摘要: hello.hessian.MyCar.java package hessian.pojo; import java.io.Serializable; public class MyCar implements Serializable { private static final long serialVersionUID = 473690540190845543

hello.hessian.MyCar.java

package hessian.pojo;

import java.io.Serializable;


public class MyCar implements Serializable {

    private static final long serialVersionUID = 4736905401908455439L;

    private String carName;

    private String carModel;

    public String getCarName() {
        return carName;
    }

    public String getCarModel() {
        return carModel;
    }

    public void setCarName(String pCarName) {
        carName = pCarName;
    }

    public void setCarModel(String pCarModel) {
        carModel = pCarModel;
    }

    @Override
    public String toString() {
        return "my car name:[" + this.carName + "] model:[" + this.carModel
                + "].";
    }
}

 

 

hessian.service.HelloHessian.java

package hessian.service;

import hessian.pojo.MyCar;

import java.util.List;
import java.util.Map;

public interface HelloHessian {
    String sayHello();

    MyCar getMyCar();

    List myLoveFruit();

    Map myBabays();
}

 

hessian.service.impl.HelloHessianImpl.java

package hessian.service.impl;

import com.caucho.hessian.server.HessianServlet;
import hessian.pojo.MyCar;
import hessian.service.HelloHessian;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class HelloHessianImpl extends HessianServlet implements HelloHessian {

    public MyCar getMyCar() {
        MyCar car = new MyCar();
        car.setCarName("阿斯顿·马丁");
        car.setCarModel("One-77");
        return car;
    }

    public Map myBabays() {
        Map map = new HashMap();
        map.put("son", "孙吴空");
        map.put("daughter", "孙小美");
        return map;
    }

    public List myLoveFruit() {
        List list = new ArrayList();
        list.add("apple");
        list.add("kiwi");
        list.add("orange");
        return list;
    }

    public String sayHello() {
        return "welcom to Hessian";
    }

}

 

hessian.Main.java

package hessian;

import com.caucho.hessian.client.HessianProxyFactory;
import hessian.service.HelloHessian;

public class Main {

    public static String url = "http://localhost:8888/InfoWeb/Hello";

    public static void  main(String[] args)throws Exception{
        HessianProxyFactory factory = new HessianProxyFactory();

        HelloHessian helloHession = (HelloHessian) factory.create(HelloHessian.class, url);

        System.out.println(helloHession.sayHello());
        System.out.println(helloHession.getMyCar());
        System.out.println(helloHession.myBabays());
        System.out.println(helloHession.myLoveFruit());
    }
}

 

web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
	
	<servlet>
		<servlet-name>Hello</servlet-name>
		<servlet-class>com.caucho.hessian.server.HessianServlet</servlet-class>
		<init-param>
			<param-name>home-class</param-name>
			<param-value>hession.service.impl.HelloHessianImpl</param-value>
		</init-param>
		<init-param>
			<param-name>home-api</param-name>
			<param-value>hession.service.HelloHessian</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>Hello</servlet-name>
		<url-pattern>/Hello</url-pattern>
	</servlet-mapping>
</web-app>

 

pom.xml

    <dependencies>
        <!--=========================== hession =========================== -->
        <dependency>
            <groupId>com.caucho</groupId>
            <artifactId>hessian</artifactId>
            <version>4.0.33</version>
        </dependency>

        <!--=========================== Servlet Api ===========================-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

 

Hessian 简单例子

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
项目结构如下: pom.xml 内容: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi
官网:Hessian 百科:Hessian Hessian是一个轻量级的remoting onhttp工具,使用简单的方法提供了RMI
一、简介 Hessian是由caucho提供的一个基于binary-RPC实现的远程通讯library。   1、是基于什么协
通过Hessian对外提供服务 服务器端目录结构: 服务器端接口代码: package com.demo.hessian.servic
通过Hessian对外提供服务 服务器端目录结构: 服务器端接口代码: package com.demo.hessian.servic
Handlebars官网链接:http://handlebarsjs.com/,下面是一个简单的例子,欢迎吐槽. <!DOCTYPE htm
登陆数据库: mysql -u用户名 -p密码 -P端口 -h数据库地址 ‍‍‍‍‍‍修改mysql提示符:(仅本次
ps: 在我自己写的例子中,代码完全正确,却调不出结果。后来发现,原来是返回的json串太大太长。 本
下面是效果介绍: 项目目录截图: 代码介绍 1、Index.jsp <%@ page language="java" import="java
我们按照 TDD的1个准备步骤+关键5步来看做一个小例子。 需求: 假设我有一个叫Dollar的class, 那它
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号