SPRINGMVC Integrated Hessian

Source: Internet
Author: User
Tags apache tomcat

SPRINGMVC Integrated Hessian

The first emphasis here is SPRINGMVC, not spring, both of which are different when integrating Hessian. Spring integration is relatively simple, just search the web on the line.

Springmvc a little trouble.

Note: If you do not know Hessian, you can see Hessian simple example

Pre-conditions

Let's say your SPRINGMVC environment is already configured.

The following configuration is primarily available in Web. xml:

<servlet>    <!-- 名字随便,和你springmvc的配置xml一致即可 -->    <servlet-name>sys</servlet-name>    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>    <load-on-startup>1</load-on-startup></servlet><servlet-mapping>   <!-- 你自己的映射配置 --></servlet-mapping>

In addition you have configured the corresponding sys-servlet.xml file ( sys name and your own consistency can be).

Integrated Hessian

In order to request for Hessian, the web.xml following mappings have been added:

<servlet-mapping>    <!-- 名字要保持一致 -->    <servlet-name>sys</servlet-name>    <url-pattern>*.hessian</url-pattern></servlet-mapping>

Then sys-servlet.xml add the following configuration in:

<!--hessian--><bean id="httpRequestHandlerAdapter" class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter"/><bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/><bean id="importService" class="com.xxx.pr.service.impl.ImportServiceImpl"/><bean name="/import.hessian" class="org.springframework.remoting.caucho.HessianServiceExporter">    <property name="service" ref="importService"/>    <property name="serviceInterface" value="com.xxx.pr.service.ImportService"/></bean>

HessianServiceExporteris an inherited HttpRequestHandler interface, so you need HttpRequestHandlerAdapter to handle this request.

BeanNameUrlHandlerMappingThe function is to <bean> name / map a URL request when the property starts with.

HessianServiceExporterThe two properties in the, one is service the ref implementation class that the property points to. One is serviceInterface , the point is the interface.

After the configuration is done, start the server.

Then visit Http://localhost:8080/myweb/import.hessian . The specific address according to their own to write.

When the browser opens, the following appears:

HTTP Status 405-hessianserviceexporter only supports POST requests

type Status Report

message Hessianserviceexporter only supports POST requests

Description The specified HTTP method isn't allowed for the requested resource.

Apache tomcat/7.0.56

If shown above, there is no problem with the instructions.

Call if called in spring, you can try the following configuration
<bean id="importBean"   class="org.springframework.remoting.caucho.HessianProxyFactoryBean">      <property name="serviceUrl"            value="http://localhost:8080/myweb/import.hessian"></property>      <property name="serviceInterface" value="com.xxx.pr.service.ImportService"></property>  
You can also call directly using Hessian
String url = "http://localhost:8080/myweb/import.hessian";HessianProxyFactory factory = new HessianProxyFactory();ImportService basic = (ImportService) factory.create(ImportService.class, url);

SPRINGMVC Integrated Hessian

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.