近期在看 ambari REST API ,與ambari server 互動的這個區塊。
很多設計都是基於原本framework所提供的特性去設計的。

在REST API 這層中, 大量的使用了,JAX-RS 來省掉一些複雜的過程。


  /**
   * Handles POST /clusters/{clusterID}/hosts/{hostID}
   * Create a specific host.
   *
   * @param body     http body
   * @param headers  http headers
   * @param ui       uri info
   * @param hostName host id
   *
   * @return host resource representation
   */
  @POST
  @Path("{hostName}")
  @Produces("text/plain")
  public Response createHost(String body, @Context HttpHeaders headers, @Context UriInfo ui,
                          @PathParam("hostName") String hostName) {

    return handleRequest(headers, body, ui, Request.Type.POST,
        createHostResource(m_clusterName, hostName, ui));
  }
 javax.ws.rs.core.Response createHost(java.lang.String body, javax.ws.rs.core.HttpHeaders headers, javax.ws.rs.core.UriInfo ui, java.lang.String hostName) 
          Handles POST /clusters/{clusterID}/hosts/{hostID} Create a specific host.以django , web.py來解釋的話,

可以透過這個機制去取得REST的參數,作為程式內部的變數。

如上是一個createHost的method,
(上面有包了一層取 cluseterID,先不看他。)


JAX-RS @PathParam example

http://www.mkyong.com/webservices/jax-rs/jax-rs-pathparam-example/



arrow
arrow
    文章標籤
    ambari jax-rs
    全站熱搜

    peicheng 發表在 痞客邦 留言(0) 人氣()