Hessian Simple Use Summary

Source: Internet
Author: User

Hessian Introduction: Is a lightweight remoting onhttp tool that provides RMI functionality using a simple method. Simpler and faster than Webservice,hessian. The binary RPC protocol is used because the binary protocol is used, so it is good for sending binary data

1. Development environment MAVEN----SPRINGMVC

2.hessian need a customer service side of a server-side customer service and servers need to have Hessian jar using MAVEN directly add

<dependency>
<groupId>com.caucho</groupId>
<artifactId>hessian</artifactId>
<version>4.0.7</version>
</dependency>

The customer service side provides the final logic processing service side responsible for invoking the processing results of customer service

3. The customer terminal first defines an interface

Package com.test.hessian.images;

Public interface UserService {
public void AddUser ();

public void UpdateUser ();

public void Deluser ();

public string Finduser (string username);

}

Then implement this interface

Package com.test.hessian.images;


public class Userserviceimpl implements UserService {

public void AddUser () {
System.out.println ("-------------invoke AddUser ()---------------");
}

public void UpdateUser () {
System.out.println ("-------------invoke UpdateUser ()---------------");
}

public void Deluser () {
System.out.println ("-------------invoke Deluser ()---------------");
}

public string Finduser (string username) {
System.out.println ("-------------invoke Finduser---------------");
Return "return:" + username;
}

}

Then integrate the Hessian in the spring configuration file

<!--The bean mappings provided by the SPRINGMVC can also be used without--
<bean class= "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<!--defines the interface implementation class for processing logic--
<bean id= "UserService" class= "Com.test.hessian.images.UserServiceImpl"/>
<!--name= "/userservice" is the access address of the service-side call (which is understood for the time being)---the specific class of service--processing logic-the interface of the Serviceinterface processing logic class ( The server side must also have this interface and the path and class name of the interface should be kept one at a time)-->
<bean name= "/userservice"
class= "Org.springframework.remoting.caucho.HessianServiceExporter" >
<property name= "service" ref= "UserService"/>
<property name= "Serviceinterface" value= "Com.test.hessian.images.UserService"/>
</bean>

4 service end (i.e., call side)

First define the same interface as the customer service side

Package com.test.hessian.images;

Public interface UserService {
public void AddUser ();

public void UpdateUser ();

public void Deluser ();

public string Finduser (string username);

}

Then configure the call in the SPRINGMVC configuration file

<bean id= "Userservicetoo"
class= "Org.springframework.remoting.caucho.HessianProxyFactoryBean" >
<property name= "serviceurl"
Value= "Http://127.0.0.1:8080/ldimages/userService"/>
<property name= "Serviceinterface" value= "Com.test.hessian.images.UserService"/>
</bean>

After these hessian are basically set up below is the test class

@RequestMapping ("/hessian/test/")
@Controller

public class Test {
@Autowired
@Qualifier ("Userservicetoo")
Private UserService UserService;


@RequestMapping ("index")
public void Main () {
Userservice.adduser ();
Userservice.updateuser ();
Userservice.deluser ();
String user = Userservice.finduser ("Zhangsan");
System.out.println ("Test.main ()----------" +user);
System.out.println ("---------------------------------finished----------------------------------");
}
}

Simple Hessain configuration success with this image server architecture is very good

Hessian Simple Use Summary

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.