Use Hessian in SSH
17:10:13| Category:Remote Call
| Tag:SSH Hessian interceptor|Font SizeLargeMediumSmall Subscription
I personally feel that using Hessian can solve some network applications with relatively simple business logic and a small number of nodes that require remote calls. However, when the number increases and the logic is responsible, especially when each node can call each other, it is a little troublesome.
The Hessian version used in the SSH structure is preferably the built-in spring version, usually under the LIB/Caucho directory. First, assume that the service we want to remotely call is hello, which is located at Org. dreamfly. core. test. hello. its implementation class is helloimpl, located at Org. dreamfly. core. test. helloimpl. in the web. add <servlet> <servlet-Name> remote </servlet-Name> <servlet-class> Org. springframework. web. servlet. dispatcherservlet </servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-Name> remote </ servlet-Name> <URL-pattern>/remote/* </url-pattern> </servlet-m Apping> This section means that the remote servlet processes all URLs intercepted at any or below the remote/path. (This place has to note, will be written later) and then add the WEB-INF in the remote-servlet.xml directory. <? XML version = "1.0" encoding = "UTF-8"?> <Beans xmlns = "http://www.springframework.org/schema/beans" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns: AOP = "http://www.springframework.org/schema/aop" xmlns: Tx = "http://www.springframework.org/schema/tx" xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http: // www. Springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd "> <bean id =" hessianservice "class =" org. dreamfly. core. test. helloimpl "/> <bean name ="/Hessian "class =" org. springframework. remoting. caucho. hessianserviceexporter "> <property name =" service "> <ref bean =" hessianservice "> </Ref> </property> <property name =" Serviceinterface "> <value> Org. dreamfly. core. test. hello </value> </property> </bean> </beans> Add <bean id = "hessianproxy" class = "org. springframework. remoting. caucho. hessianproxyfactorybean "> <property name =" serviceurl "> <value> http: // localhost: 8080/shuzi/remote/Hessian </value> </property> <property name = "serviceinterface" value = "org. dreamfly. core. test. hessian "> </property> </bean> Note: Ht In TP: // localhost: 8080/shuzi/remote/Hessian, shuzi is the project name. In this way, you can remotely call the bean by injecting hessianproxy to any bean. It is worth mentioning that struts2 also uses an interceptor. In the first place, I allocated the struts2 Interceptor to/* For convenience, so that the Remote Call request was intercepted by struts2, the system will prompt that http: // localhost: 8080/shuzi/remote/Hessian is not found. The solution can be to refine the struts2 Interceptor to the namespace of struts2, in this way, only the namespace and web. if the interceptor in XML does not have a duplicate name, the problem will not occur.