zoukankan      html  css  js  c++  java
  • REST架构之Apache Wink

    Apache Wink是一个使用简单,稳定的Java框架,用于创建RESTful web services应用程序。Wink包括了一个服务器端模块和一个客户端模块,用于帮助开发者快速高效的开发RESTful Web services应用。

    首先,需要在web.xml里面配置一下,把REST的访问都安排给Wink来处理。代码如下:

      <servlet>
        <servlet-name>restSdkService</servlet-name>
        <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
      </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
            classpath:conf/spring-bean.xml
    classpath:conf/spring-dataSource.xml
    </param-value>
    </context-param>

    其中wink-core-context.xml是wink-spring-support模块里面的一个Spring配置文件,spring-bean.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="userRest" />
                    <ref local="noticeRest" />
                    <ref local="searchRest" />
                    <ref local="voteRest" />
                    <ref local="resourceRest" />
                    <ref local="sysManageRest" />
                </set>
            </property>
        </bean>
    
        <bean id="userRest" class="rest.UserRest">
        </bean>

    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("/user")  
    public class UserRest{  
      
        @GET  
        public String login() {  
            return "ok";  
        }  
    }

    以前,是用的cfx方式发布的restful服务。

  • 相关阅读:
    POJ 1321 棋盘问题
    POJ3468 A Simple Problem with Integers(区间更新+区间查询+差分)
    洛谷P3374【模板】树状数组 1(单点更新+区间求和)
    Lake Counting
    柱状图统计
    数据库读取
    c作图-正弦函数图像
    Fence Repair
    Stall Reservations(贪心+优先队列)
    Table Tennis Game 2
  • 原文地址:https://www.cnblogs.com/ld-swust/p/6117760.html
Copyright © 2011-2022 走看看