- 浏览: 782491 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (386)
- Linux (36)
- Tomcat (6)
- windows (8)
- Apache (10)
- Java (25)
- jquery (7)
- Jquery 插件 (3)
- Oracle (5)
- Oracle SQL (68)
- Spring (15)
- 开发工具 (6)
- Struts (20)
- js (14)
- Project Code (2)
- Project Code Tomcat (1)
- libset (1)
- JSP (8)
- arithmetic (2)
- 浏览器 (1)
- extjs (3)
- 学习网站 (5)
- 生活情感 (0)
- 电话号码算法 (3)
- 快捷键 (1)
- 转载 (1)
- Dos命令 (2)
- services (1)
- Resources (1)
- 行业积累 (3)
- 项目积累 (3)
- Web (3)
- 文档 (1)
- JavaEE (2)
- JSF (3)
- http (3)
- JS窗口 (1)
- Html (4)
- Flex (1)
- 资讯 (2)
- 项目规范 (1)
- Struts s:property textarea中默认值用 (1)
- Quartz 2.0.2 (12)
- 1天有多少毫秒 (1)
- 专题 (1)
- intellij idea 10 CD-KEY (1)
- restlet (4)
- Mail (1)
- Excel (3)
- Menu (1)
- Big Data技术综述 (1)
- Quart 1 (1)
- nosql (1)
- linux远程 (1)
- jdk (5)
- wind7 (1)
- 虚拟人 (0)
- 虚拟机 (1)
- 终端 (1)
- Ubuntu (16)
- Myeclipse (2)
- Wmware (1)
- eclipse (2)
- css (2)
- csv (1)
- 开源 (1)
- plsql (2)
- cassandra (4)
- maven (1)
- hadoop (2)
- mysql (1)
- spring security (1)
- tools (1)
- jdbc (2)
- exception (2)
- 硬盘数据备份 (1)
- dwr (1)
- svn (1)
- PowerDesigner15使用时的十五个问题 (1)
- tomcat 项目发部路径 (1)
- js 暂停执行 (1)
- jquery jqgrid 格式化数据显示 (1)
- js 代码模板 (1)
- strutss2 直接跳转到jsp页面 (1)
- servlet (1)
- jdbc spring (1)
- js学习网站 (1)
- 自学考试 (2)
- hibernate (2)
- eos (1)
- c (4)
- 黑马 (2)
- 大数据 (2)
- 实战云大数据案例分享 (0)
- Spark (2)
- Flink (1)
最新评论
-
coosummer:
推荐使用http://buttoncssgenerator.c ...
jquery button 漂亮 -
thinktothings:
Array_06 写道你好,我是一名刚毕业学生,我以后就是做J ...
如何转型架构师 -
thinktothings:
软考,考有职业资格证,有系统的知识体系学习
如何转型架构师 -
Array_06:
你好,我是一名刚毕业学生,我以后就是做Java的架构师,那请问 ...
如何转型架构师 -
beykery:
你这也太复杂了。。。。jsf2不应该是这样的。。。。
JSF2.0的一个简单Demo
一、实体
Contact
package com.tht.common; import java.io.Serializable; public class Contact implements Serializable { private int id; private static final long serialVersionUID = 1L; private int age; private String firstName; private Address homeAddress; private String lastName; public Contact() { } public Contact(String firstName, String lastName, Address homeAddress, int age) { super(); this.firstName = firstName; this.lastName = lastName; this.homeAddress = homeAddress; this.age = age; } public Contact(int id,String firstName, String lastName, Address homeAddress, int age) { super(); this.id=id; this.firstName = firstName; this.lastName = lastName; this.homeAddress = homeAddress; this.age = age; } public int getAge() { return age; } public String getFirstName() { return firstName; } public Address getHomeAddress() { return homeAddress; } public String getLastName() { return lastName; } public void setAge(int age) { this.age = age; } public void setFirstName(String firstName) { this.firstName = firstName; } public void setHomeAddress(Address homeAddress) { this.homeAddress = homeAddress; } public void setLastName(String lastName) { this.lastName = lastName; } public int getId() { return id; } public void setId(int id) { this.id = id; } @Override public boolean equals(Object obj) { return super.equals(obj); } }
二、实体 Address
package com.tht.common; import java.io.Serializable; public class Address implements Serializable { private static final long serialVersionUID = 1L; private String line1; private String line2; private String zipCode; private String city; private String country; public Address() { } public Address(String line1, String line2, String zipCode, String city, String country) { super(); this.line1 = line1; this.line2 = line2; this.zipCode = zipCode; this.city = city; this.country = country; } public String getCity() { return city; } public String getCountry() { return country; } public String getLine1() { return line1; } public String getLine2() { return line2; } public String getZipCode() { return zipCode; } public void setCity(String city) { this.city = city; } public void setCountry(String country) { this.country = country; } public void setLine1(String line1) { this.line1 = line1; } public void setLine2(String line2) { this.line2 = line2; } public void setZipCode(String zipCode) { this.zipCode = zipCode; } }
三、服务资源
package firstSteps; import org.restlet.Application; import org.restlet.Component; import org.restlet.Restlet; import org.restlet.data.Protocol; import org.restlet.routing.Router; import com.tht.resource.ContactServerResource; public class FirstStepsApplication extends Application { /** * Creates a root Restlet that will receive all incoming calls. */ @Override public synchronized Restlet createInboundRoot() { // Create a router Restlet that routes each call to a new instance of HelloWorldResource. Router router = new Router(getContext()); // Defines only one route router.attach("/hello", ContactServerResource.class); return router; } /* public static void main(String[] args) throws Exception { // Create a new Component. Component component = new Component(); // Add a new HTTP server listening on port 8182. component.getServers().add(Protocol.HTTP, 8182); // Attach the sample application. component.getDefaultHost().attach("/firstSteps", new FirstStepsApplication()); // Start the component. component.start(); } */ }
package com.tht.resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.restlet.resource.ServerResource; import com.tht.common.Address; import com.tht.common.Contact; import com.tht.common.ContactResource; public class ContactServerResource extends ServerResource implements ContactResource { public ContactServerResource(){ } private static Contact contact = new Contact("firstName1", "lastName1", new Address("Address1", "Address2", "20010", "city1", "country1"), 10); @Override public void remove(String key) { contact=null; } @Override public Contact retrieve() { return contact; } @Override public void store(Contact contact) { this.contact=contact; } }
三启动服务
import org.restlet.Component; import org.restlet.data.Protocol; import firstSteps.FirstStepsApplication; /** * 启动程序 开起服务http://localhost:8182/firstSteps * *可以访问请求路径: http://localhost:8182/firstSteps/hello * @author think * */ public class Run { public static void main(String[] args) throws Exception { // Create a new Component. Component component = new Component(); // Add a new HTTP server listening on port 8182. component.getServers().add(Protocol.HTTP, 8182); // Attach the sample application. component.getDefaultHost().attach("/firstSteps", new FirstStepsApplication()); // Start the component. component.start(); } }
四、启动客户端
package com.tht.client; import com.tht.common.Contact; import com.tht.common.ContactResource; import java.io.IOException; import java.util.List; import java.util.Map; import org.restlet.data.MediaType; import org.restlet.resource.ClientResource; import org.restlet.resource.ResourceException; public class GetRequest { public static void main(String[] args) throws ResourceException, IOException { ClientResource cr = new ClientResource( "http://localhost:8182/firstSteps/hello"); // Get the Contact object ContactResource resource = cr.wrap(ContactResource.class); Contact contact = resource.retrieve(); if (contact != null) { System.out.println("firstname: " + contact.getFirstName()); System.out.println(" lastname: " + contact.getLastName()); System.out.println(" age: " + contact.getAge()); } /* * Map<String, Contact> contacts = resource.retrieve(); Contact * contact=null; for(Object key : contacts.keySet()){ * System.out.println("key:"+key); * * contact=contacts.get(key); System.out.println("value:"+contact); if * (contact != null) { System.out.println("firstname: " + * contact.getFirstName()); System.out.println(" lastname: " + * contact.getLastName()); System.out.println(" age: " + * contact.getAge()); } * * } */ // In case the Contact object is not available // Get a JSON representation of the contact // System.out.println("\nJSON representation"); // cr.get(MediaType.APPLICATION_JSON).write(System.out); } }
delete
package com.tht.client; import com.tht.common.Address; import com.tht.common.Contact; import com.tht.common.ContactResource; import java.io.IOException; import org.restlet.data.MediaType; import org.restlet.resource.ClientResource; import org.restlet.resource.ResourceException; public class DeleteRequest { public static void main(String[] args) throws ResourceException, IOException { ClientResource cr = new ClientResource( "http://localhost:8182/firstSteps/hello"); // Get the Contact object ContactResource resource = cr.wrap(ContactResource.class); Contact contact = new Contact("firstName1", "lastName1", new Address("Address1", "Address2", "20010", "city1", "country1"), 10); resource.store(contact); } }
put
package com.tht.client; import com.tht.common.Address; import com.tht.common.Contact; import com.tht.common.ContactResource; import java.io.IOException; import org.restlet.data.MediaType; import org.restlet.resource.ClientResource; import org.restlet.resource.ResourceException; public class PutRequest { public static void main(String[] args) throws ResourceException, IOException { ClientResource cr = new ClientResource( "http://localhost:8182/firstSteps/hello"); // Get the Contact object ContactResource resource = cr.wrap(ContactResource.class); Contact contact = new Contact("firstName1", "lastName1", new Address("Address1", "Address2", "20010", "city1", "country1"), 10); resource.store(contact); } }
- restlet-jse.zip (624.7 KB)
- 下载次数: 35
相关推荐
在"restlet-jse-2.2.1.zip"这个压缩包中,我们可以期待找到以下内容: 1. **库文件**:包括JAR文件,如`restlet-api.jar`、`restlet-engine.jar`等,这些是Restlet框架的核心组件,提供了处理HTTP请求、响应、资源...
在"restlet-jse-2.1.2"这个压缩包中,我们主要关注的是Restlet框架针对Java标准版(Java SE)的实现。版本号"2.1.2"表明这是一个特定的稳定版本,可能包含了之前版本的改进和修复。 Restlet框架的核心组件包括以下...
Restlet项目为“建立REST概念与Java类之间的映射”提供了一个轻量级而全面的框架。它可用于实现任何种类的REST式系统,而不仅仅是REST式Web服务;而且,事实证明它自从2005年诞生之时起,就是一个可靠的软件。 ...
总的来说,`restlet.jar` 和 `restlet-jse-2.1.4` 是用于构建RESTful服务的重要工具,为Java开发者提供了一套强大且灵活的框架,以遵循REST原则来设计和实现Web服务。通过深入理解和使用Restlet,开发者能够构建高效...
org.restlet.jar
2. **JSE模块**:restlet-jse-2.0.9是针对Java SE环境的实现,它提供了一个纯Java的REST客户端和服务器端实现。这个模块包含了一系列类库,使得开发者可以在Java应用中直接使用RESTful API。 3. **API友好**:...
<groupId>org.restlet.jse <artifactId>org.restlet.junit <version>YOUR_VERSION <scope>test ``` 请替换`YOUR_VERSION`为当前的Restlet JUnit工具版本号。 然后,你可以开始编写测试用例。"restlet-junit-...
<groupId>org.restlet.jse <artifactId>org.restlet <version>2.4.0 ``` 接下来是基本的配置步骤,这通常涉及到创建一个`Application`子类并定义路由规则。 ### 创建简单的“Hello World”示例 #### 步骤1:...
<groupId>org.restlet.jse <artifactId>restlet-engine <version>2.4.5 <groupId>org.springframework <artifactId>spring-webmvc <version>5.3.18 ``` 步骤二:配置Spring 创建Spring的配置文件(如:...