简体   繁体   中英

Suggestions on RESTful Java Web Services Framework…

I googled some information about web services, it seems like a enterprise level application. I found that RESTful design is very cool idea on this. I find that Apache CXF looks cool, it support RESTful design and Java. It is a good choice for beginner to start writing an application using Apache CXF? or any other framework is suggested?

我会选择JerseyJAX-RS的RI(JSR 311),RESTful Web Services的Java API(即标准)。

I recommend to use JAX-RS because IMHO it is the most neutral framework in terms of telling you how REST should be done. I have not used CXF, only Jersey. It is a very solid implementation and comes with a good client side connector, too (client side not part of JAX-RS yet).

Being neutral with regard to 'how to do REST' is important because there is not yet an acknowledged 'best' way to approach certain aspects (eg design of hypermedia).

Congrats to going the REST way - you won't regret it.

Jan

The much simpler implementation for a beginner would be spring 3.0 REST support. Spring MVC 3.0 has REST support and is very much simpler compared to Apache CXF.

Restlet在另一个用于Java的RESTful Web框架中: http//www.restlet.org/

I get started REST with RESTEasy and get it up in 30 minutes. You can use it as stand-alone lib in your favorite servlet container without all this JBoss stuff.

You should try PlayFramework. Just take a loot at a sample route file and you will know how easy it is to use play to implement RESTFul web app:

# ====== Order service =========================
GET /orders Orders.list
GET /orders/{<[0-9]+>id} Orders.show
PUT /orders/{<[0-9]+>id} Order.saveUpdate
POST /orders Orders.saveNew
# ==============================================

And corresponding controller methods:

public class Orders extends Controller {
   public static void list() {
      List<Order> orders = Order.all();
      render(orders);
   }
   public static void show(long id) {
      Order order = Order.findById(id);
      notFoundIfNull(order);
      render(order);
   }
   public static void saveUpdate(long id, Order update) {
      Order order = Order.findById(id);
      notFoundIfNull(order);
      order.update(update);
      show(id);
   }
   public static void saveNew(Order order) {
      order.save();
      show(order.getId());
   }
}

There are some utilities enable you to interact with other Web Services:

String url = "https://ajax.googleapis.com/ajax/services/search/web";
Map<String, Object> params = new HashMap<String, Object>();
params.put("v", "1.0");
params.put("q", searchStr);
params.put("key", Play.configuration.get("app.google.key"));
params.put("userip", myIpAddr);
HttpResponse resp = WS.url(url).params(params).get();
return resp.getString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM