Jersey Restlet and Apache CXF

Jersey  Restlet  and  Apache CXF 都是現了RESTFUL 的支持.

Jersey 實現了jsr 311繼續使用 jax-ws式樣的使用annotation 完成對url 的控制。
下面的code很熟悉吧
@HttpMethod("GET")
@UriTemplate("{userId}.txt")
@ProduceMime("text/plain")
public String sayHello(@UriParam("userId") String userId) {
return "Hello " + userId;
}
Restlet使用的要自己使用code把消息dispach的相應的restlet上。
public class RestletMapper {
private Map restMap = new HashMap< String , Restlet>();

public void init( Router router){
for( Object key : restMap.keySet() ){
router.attach( (String)key , (Restlet) restMap.get(key));
}
}

public void setRestMap( HashMap< String , Restlet> map){
this.restMap = map;
}
}
Router
相比之下,感覺jersey的實現更加簡潔, Restlet的控制能力更強。
Apache CXF  對 REST的sytle支持的比較全面,不過現在
  1. JAX-RS (JSR-311): CXF has an initial implementation of JAX-RS (JSR-311): Java API for RESTfulWeb Services. This provides a more standard way to build RESTful services in JAVA.
  2. HTTP Binding: The HTTP binding provides a flexible way of creating resources and mapping them to operations in your service. This can currently be done via annatotations or a convention based mapping.
  3. JAX-WS Provider and Dispatch: It is possible to create simple RESTful services with the JAX-WS Provider and Dispatch APIs. It is not as flexible as the HTTP binding, but does use standard APIs.

可惜,還沒有真正去用一下。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章