spring integration之http-rest例子解析(一)

2014-11-24 10:09:05 · 作者: · 浏览: 0

spring integration例子代码下载地址,以及如何导入eclipse并使用maven构建等请参看上一篇:

Spring Integration实例代码分析之basic--http

先看一下http-rest例子的readme
This sample demonstrates how you can send an HTTP request to a Spring Integration's HTTP service while utilizing Spring Integration's new HTTP Path usage;
This sample also uses Spring Security for HTTP Basic authentication. With HTTP Path facility, the client program can send requests with URL Variables.
It consists of two parts - Client and Server.
The following client program can be used to test the HTTP Path usage.
1. RestHttpClientTest. It uses Spring's RestTemplate to assemble and send HTTP request
Server is Spring Integration's HTTP endpoint configuration.

此示例演示了如何发送一个HTTP请求到一个Spring集成的HTTP服务,同时利用Spring Integration的新的HTTP Path;
此示例还使用了Spring HTTP基本身份验证安全性。 HTTP Path,客户端程序可以发送请求的URL变量。
它由两部分组成 - 客户端和服务器。
客户端程序,可以用来测试使用HTTP path。RestHttpClientTest。它使用Spring的RestTemplate的组装和发送HTTP请求
服务端是Spring集成的HTTP端点配置。
代码结构

仍然先看web.xml
先是配置几个变量,指定spring配置路径和log4j的配置路径
[html]

contextConfigLocation


/WEB-INF/config/web-application-config.xml





webAppRootKey
rest-http.root




log4jConfigLocation
/WEB-INF/classes/log4j.properties

然后配置spring的listener,用于启动WebApplicationContext
[html]

org.springframework.web.util.Log4jConfigListener




org.springframework.web.context.ContextLoaderListener

接着是filter,包含指定字符的,和security的,用于认证。
[html]

charEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter

encoding
UTF-8


forceEncoding
true



charEncodingFilter
/*


springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy


springSecurityFilterChain
/*

最后才是用于spring mvc的DispatcherServlet,指定配置文件为contextConfigLocation的 /WEB-INF/config/web-application-config.xml
[html]

Spring Integration Rest HTTP Path Usage
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation


2


Spring Integration Rest HTTP