REST架构之Apache Wink介绍
来源:互联网 发布:域名top 编辑:程序博客网 时间:2024/06/06 20:31
REST(Representational State Transfer) based Web Service是相对于传统的Web Service(SOAP+WSDL+UDDI)而提出的。传统的Web Service可以很好的解决异构系统之间的通信问题,但是需要首先定义好XML格式的合同(WSDL),client和server都必须严格遵守协议,不容易升级以及集群伸缩。REST Web Service不需要事先定义格式,传输的内容也可以依据不同的client变化(json,xml,html等),最重要的是使用源URL来唯一定位资源,对资源的增删改查映射为HTTP的四个方法,无状态传输,具有非常好的伸缩性。
Apache Wink就是一个纯Java的REST框架。它完整的实现了JSR 311并扩展了部分功能,此外还提供了良好的扩展性,难能可贵的是还可以与流行的Java框架Spring无缝集成。目前该项目还在开发中。所谓框架无非就是定义好格式,提供一些工具和钩子,让开发人员可以专注于业务逻辑的开发。本文将试图简单的介绍一下Wink。
Web Service当然是Web程序了,所以入口就是一个Servlet,在web.xml里面配置一下,把REST的访问都安排给Wink来处理。代码如下:
<servlet><servlet-name>restSdkService</servlet-name><servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class><load-on-startup>0</load-on-startup></servlet><servlet-mapping><servlet-name>restSdkService</servlet-name><url-pattern>/rest/*</url-pattern></servlet-mapping>
与Spring的集成,需要一个集成模块wink-spring-support,配置如下:
<context-param><param-name>contextConfigLocation</param-name><param-value>classpath:META-INF/server/wink-core-context.xml,/WEB-INF/spring/app-context.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>
其中wink-core-context.xml是wink-spring-support模块里面的一个Spring配置文件,app-context.xml配置如下:
<bean class="org.apache.wink.spring.Registrar"><property name="classes"><set value-type="java.lang.Class"></set></property><property name="instances"><set><ref local="helloWorldResource" /></set></property></bean><!-- Resources --><bean id="helloWorldResource" class="HelloWorldResource" />
HelloWorldResource是一个REST里面的Resource,用Annotation配置路径等信息:
import javax.ws.rs.GET;import javax.ws.rs.Path;import org.apache.wink.common.annotations.Workspace;@Workspace(workspaceTitle = "Workspace Title", collectionTitle = "Collection Title")@Path("/helloworld")public class HelloWorldResource {@GETpublic String getMessage() {return "HelloWorld";}}这样启动web服务器,输入http://localhost:8080/weat/rest/即可看到web service信息。服务列表里面可以看到HelloWorldResource服务。
- REST架构之Apache Wink介绍
- REST架构之Apache Wink介绍
- REST架构之Apache Wink介绍
- REST架构之Apache Wink介绍【做了这么长时间REST,应该对架构深入理解】
- apache wink集成spring开发rest服务
- RESTful Web 服务和 Apache Wink,第 1 部分: 构建 Apache Wink REST 服务
- Spring中应用Apache Wink创建REST服务
- Apache Wink 创建RESTfull
- apache wink client
- about apache wink
- rest架构介绍
- REST架构及其介绍
- SOAP REST网络架构介绍
- Apache ODE架构介绍
- Apache Shiro架构介绍
- Apache Sentry架构介绍
- 全新Web开发风格-REST架构介绍
- 全新Web开发风格-REST架构介绍
- MyEclipse内存溢出问题
- Vim配置
- PHP学习之一:PHP脚本、类型和变量
- UVa10026 - Shoemaker's Problem
- VC++图形平移功能的实现
- REST架构之Apache Wink介绍
- 随机函数
- PHP提取emule下载ed2k链接
- 地图符号化-柱状图
- 黑马程序员——Java的基本构成元素
- Perl 引用变量传入函数中的行为
- C#调用C/C++ 动态链接库DLL(三)
- 检测两个整数相乘是否会产生溢出
- sizeof(五)