首先添加 Restlet 需要的Maven Dependency:
<dependency> <groupId>org.restlet.jse</groupId> <artifactId>org.restlet</artifactId> <version>${restlet-version}</version> </dependency> <dependency> <groupId>org.restlet.jee</groupId> <artifactId>org.restlet.ext.servlet</artifactId> <version>${restlet-version}</version> </dependency>
Restlet的version:
<restlet-version>2.3.1</restlet-version>
还有tomcat的plugin:
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <!-- http port --> <port>8080</port> <!-- application path always starts with / --> <path>/</path> </configuration> </plugin>
web.xml中配置Restlet的 servlet:
<servlet> <servlet-name>RestletServlet</servlet-name> <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class> <init-param> <!-- Application class name --> <param-name>org.restlet.application</param-name> <param-value>com.tch.test.restlet.HelloApplication</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>RestletServlet</servlet-name> <url-pattern>/restlet/*</url-pattern> </servlet-mapping>
Application实现类:
package com.tch.test.restlet; import org.restlet.Application; import org.restlet.Restlet; import org.restlet.routing.Router; import com.tch.test.restlet.restprovider.DreamoftchServerResource; import com.tch.test.restlet.restprovider.HelloWorldServerResource; public class HelloApplication extends Application { @Override public Restlet createInboundRoot() { Router router = new Router(getContext()); router.attach("/hello", HelloWorldServerResource.class); return router; } }
Restful 服务provider:
package com.tch.test.restlet.restprovider; import org.restlet.resource.Get; import org.restlet.resource.ServerResource; public class HelloWorldServerResource extends ServerResource{ @Get public String getHello() { return "Hello World, this is hello world server resource ..."; } }
OK
启动tomcat: mvn tomcat7:run
浏览器访问:
http://localhost:8080/restlet/hello
http://localhost:8080/restlet/dreamoftch
就可以看到结果了。
或者通过 Restlet的 ClientResource类:
package com.tch.test.restlet; import java.io.IOException; import org.restlet.resource.ClientResource; import org.restlet.resource.ResourceException; public class RestletTest { public static void main(String[] args) throws ResourceException, IOException { new ClientResource("http://localhost:8080/restlet/hello").get().write(System.out); } }
从控制台输出可以看到结果。
OK, Finish ...
相关推荐
restlet restful,web工程,可直接运行。启动后,main方法作为client运行调用服务端。服务器数据之间沟通利器,绝对不坑。
使用restlet实现了最简单的restful webservice,可以直接部署运行。可以作为restful webservice开发的基础环境。
演示如何使用 Restlet 框架轻松编写 Restful API。 本项目以restlet为核心,ormlite为数据层。 该资源已被抽象出来,以便轻松编写 API。 将添加对 oauth 和 odata 的支持,以编写成熟的生产级 API。
Restlet in Action Developing RESTful web APIs in Java 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自...
一个简单的Restlet开发框架的Basic认证的例子
Restlet, a RESTful Web framework for Java ========================================= http://www.restlet.org ----------------------------------------- Native REST support * Core REST concepts have ...
restful_webservice构建小例子(restlet)
restful webservice构建小例子(restlet).pdfrestful webservice构建小例子(restlet).pdf
Restlet2.0用户指南
Restlet Client插件是一款可以运行在chrome内核浏览器上的Web服务测试插件,不仅可以模拟创建和运行单个HTTP请求也可以模拟复杂的Web场景
·包含RESTful Web services的真实案例,如Amazon的简单存储服务与Atom发布协议等 ·探讨各种流行编程语言的Web services客户端 ·展示如何用三种流行框架实现RESTful services —— Ruby on Rails、Restlet(基于...
Restlet Client是一个调试restful接口工具,类似postman
用于 Eclipse 的 RESTful 插件帮助用户一键创建 RESTful ... 1) Spring RESTful Webservice 2) Jersey RESTful Webservice 3) RESTEasy RESTful Webservice 4) Restlet RESTful Webservice URL:http://oneclicklabs.io
technology stack together with any of the frameworks Jersey's JAX-RS, Restlet's Lightweight REST, JBoss's JAX-RS RESTEasy, and Struts 2 with the REST plugin. You don't need to know REST, as we cover ...
restlet client 接口测试引用,最好用的应用,分享给大家。想选择免费的,居然选不了。。。
在Spring框架支持REST之前,人们会使用其他几种实现技术来创建Java RESTful Web Services,如Restlet、RestEasy和Jersey。Jersey是其中最值得注意的,它是JAX-RS(JSR 311)的参考实现。 Spring是一个得到广泛...
n cas-server-3.4.2\modules\cas-server-support-jdbc-3.4.2.jar 、 cas-server-integration-restlet-3.4.2.jar 拷贝到 D:\server\apache-tomcat-6.0.18\webapps\cas\WEB-INF\lib 目录下。 n 数据库驱动 jar 拷贝...
restful接口开源框架
restlet_client插件,不需要按照postman就可以实现restful api 调试。 支持浏览器:360浏览器、360极速浏览器、谷歌浏览器等使用谷歌内核的浏览器。
浏览器请求测试插件restlet client(chrome) + http requester(火狐),用于测试restful风格的请求,测试接口数据