【发布时间】:2010-12-02 12:30:54
【问题描述】:
在 Java 中实现客户端和服务器 REST 框架的最佳框架是什么?我一直在努力寻找一个易于使用的解决方案。
更新:Jersey 和 Restlet 似乎都是不错的选择。我们可能会使用 Restlet,但我们会同时尝试两者。
【问题讨论】:
标签: java web-services rest jersey restlet
在 Java 中实现客户端和服务器 REST 框架的最佳框架是什么?我一直在努力寻找一个易于使用的解决方案。
更新:Jersey 和 Restlet 似乎都是不错的选择。我们可能会使用 Restlet,但我们会同时尝试两者。
【问题讨论】:
标签: java web-services rest jersey restlet
也看看dropwizard。
【讨论】:
更新:不再维护 Xydra Restless +++ 如果您在 Goolge AppEngine 发布“保留实例”功能之前使用它们,您可能会考虑 Xydra Restless,它的功能很少但加载速度很快。
【讨论】:
您可以查看 CXF JAX-RS 实现。有关其功能的完整列表,请查看CXF web site for JAX-RS。 该项目背后的社区似乎非常活跃(2013 年 7 月)。 CXF mailing lists 中每天的消息数量表明了这一点。
【讨论】:
我可以推荐 Apache wink,一个仍处于孵化模式的新框架,但非常成熟和高质量。
http://incubator.apache.org/wink/
它实现了 JAX-RS 规范,它具有用于 REST 开发的客户端和服务器框架。 Apache 支持这个项目——这总是一个好兆头(和一个好的许可证 :-))
我最喜欢这个框架的地方在于它与 Spring 的直观集成,如果您希望框架易于配置和扩展,它非常有用。
【讨论】:
Restlet 听起来它应该提供您正在寻找的东西:
【讨论】:
我没有亲自使用过它,但我与之合作的一些团队正在使用 Spring 3 MVC。 REST in Spring 3: @MVC 看起来是一篇不错的博客文章概述。 RESTful 功能包括“URI 模板”、“内容协商”、“HTTP 方法转换”、“ETag 支持”等。
编辑:另外,请参阅此问题:Can anyone recommend a Java web framework that is based on MVC and supports REST ?
【讨论】:
有 JBoss 的新 RESTEasy 库。自首次推出以来,它似乎正在快速发展。我不知道这是否有好处;它在我的“检查”列表中。
【讨论】:
Restlet 在其 2.0 版本中也支持客户端和服务器端的注解。 JAX-RS API 也支持作为扩展。
这是一个简单的服务器端示例:
public class HelloWorldResource extends ServerResource {
@Get
public String represent() {
return "hello, world";
}
}
在客户端:
// Outputting the content of a Web page
new ClientResource("http://www.restlet.org").get().write(System.out);
如需更多文档,请check this page。
【讨论】:
Jersey 对双方来说都很容易。要编写 Web 服务,请使用注解:
@Path("/helloworld")
public class HelloWorldResource {
// The Java method will process HTTP GET requests
@GET
// The Java method will produce content identified by the MIME Media
// type "text/plain"
@Produces("text/plain")
public String helloWorld() {
// Return some cliched textual content
return "Hello World";
}
}
对于客户:
Client client = Client.create();
WebResource webResource = client.resource("http://localhost:8080/helloworld");
String s = webResource.get(String.class);
System.out.println(s); // prints Hello World
【讨论】: