Hessian Introductory case

Source: Internet
Author: User

1.1. Hessian Introduction

Hessian:hessian is a lightweight remoting onhttp tool that provides RMI functionality in a simple way, simpler and faster than Webservice,hessian. The use of the binary RPC protocol, because the use of binary protocol, it is very suitable for sending binary data, Hessian mainly for object-oriented message communication.

1.2. Development step 1.2.1. Importing JAR Packages

Go to the official website to download http://hessian.caucho.com/

1.2.2. Writing a remote interface

Ihello.java

Package Cn.tempus.hessian;

Public interface Ihello {

Public String SayHello (string name);

}

1.2.3. Writing a remote interface implementation class

Helloimpl.java need to inherit Hessianservlet

Package Cn.tempus.hessian;

import Com.caucho.hessian.server.HessianServlet;

Public class Helloimpl extends hessianservlet implements Ihello {

private static final long serialversionuid =- 6448991611447150108L;

Public String SayHello (string name) {

return "Hello:"+name;

}

}

1.2.4 Configuring a servlet in a. web. xml file

Xml

<? XML version="1.0" encoding="UTF-8"?>

< web-app  < Span style= "Color:rgb (127,0,127)" >xmlns:xsi = "http://www.w3.org/ 2001/xmlschema-instance " xmlns = " Http://java.sun.com/xml/ns/javaee " xsi: schemalocation = "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "  id = "webapp_id"  version = "3.0" >

< Display-name > Hessiandemo</display-name>

< 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 >cn.tempus.hessian.HelloImpl</param-value>

</ Init-param >

< Init-param >

< Param-name >home-API</param-name>

< Param-value >cn.tempus.hessian.IHello</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 >

1.2.5. Writing a client

Client.java

Package Cn.tempus.hessian;

import java.net.MalformedURLException;

import com.caucho.hessian.client.HessianProxyFactory;

Public class Client {

Public static String URL = "Http://127.0.0.1:8080/HessianDemo/Hello";

Public static void main (string[] args) {

Hessianproxyfactory Factory = new hessianproxyfactory ();

Try {

Ihello Ihello = (Ihello) factory. Create (Ihello. Class, URL);

System. out. println (Ihello. SayHello ("Morris"));

} Catch (malformedurlexception e) {

e. Printstacktrace ();

}

}

}

1.2.6. Publish Project to Jetty

Jetty Background Printing

Running Jetty 6.1.26

2014-12-29 16:09:27.234:info::logging to STDERR via Org.mortbay.log.StdErrLog

Parentloaderpriority enabled

Context Path:/hessiandemo

Projectclassloader:entry=d:\morris\javaprj\hessiandemo\build\classes

Projectclassloader:entry=d:\morris\javaprj\hessiandemo\webcontent\web-inf\lib\hessian-4.0.37.jar

2014-12-29 16:09:27.500:info::jetty-6.1.26

2014-12-29 16:09:29.328:info::started [Email protected]:8080

1.2.7. Running the client

The results are as follows:

Hello:morris

Hessian Introductory case

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.