Data AccessCore JavaApp FrameworksViewTestingBuildingDeploymentDev ToolsSecurityOpinions

Saturday, November 6, 2010

JAX-RS @Path Precedence Rules

The other day I needed to figure out how the JAX-RS provider resolves ambiguous path expressions passed in the @javax.ws.rs.Path annotation. I learned about the provider's precedence rules and wanted to document them here with a short example.

For example, say we have the following @javax.ws.rs.Path expressions in the following class:

@Path("/users") 
public class UserResource {

  @GET
  @Path("{id : .+}")
  public String getUser(@PathParam("id") String id){
    ....
  }


  @GET
  @Path("{id : .+}/address")
  public String getAddress(@PathParam("id") String id){
    ....
  }
}

Note that .+ will match any stream of characters after "/users".
Now, suppose the following GET request was submitted.

GET /users/32/address

The request actually matches both expressions, but the request would be routed to the getAddress(@PathParam("id") String id) method. The JAX-RS provider determines which method to call based on a set of precedence rules. On deployment, the JAX-RS provider gathers and sorts all URI expressions contained within all known @Path annotations based on the following logic:

  1. The number of literal characters contained within the expression, sorted in descending order. In the example above, the getAddress(@PathParam("id") String id) method gets precedence over the getUser(@PathParam("id") String id) method. The getUser(@PathParam("id") String id) method contains 7 literal characters (/users/). The getAddress @PathParam("id") String id) method contains 14 literal characters (/users/ + address).
  2. The number of template expressions within the expression, sorted in descending order. For example, an expression containing {id}/{name} would get precedence over {id}.
  3. Finally, the number of regular expressions contained within the expression. For example, {id : .+} would get precedence over {id}.

In closing, the following URI expressions are sorted by the order of precedence above.

  1. /users/{id}/{name}/address
  2. /users/{id : .+}/address
  3. /users/{id}/address
  4. /users/{id : .+}

Any questions, leave a comment and I'll be sure to answer.

11 comments:

  1. Replies
    1. quay lại Đấu khí học viện. Tử Điện Mãng đưa cho Khiếu Thiên Hổ mấy viên đan dược, đây chính là Nhạc Thành lưu lại cho hắn.

      Tư Mã Yên Nhiên, Tô Hân Nhi, Đỗ Mật Nhi, Âu Dương Phiên Tình, bốn nười cũng bế quan trong phòng tu luyện bảy ngày, trong bốn nữ tử thì chỉ có Tư Mã Yên Nhiên vốn có thẻ linh nửa tháng, nhưng sau đó Nhạc Thành đã đưa cho bốn cô gái số thẻ linh gấp ba. đồng tâm
      game mu
      cho thuê phòng trọ
      cho thuê phòng trọ
      nhac san cuc manh
      tư vấn pháp luật qua điện thoại
      văn phòng luật
      số điện thoại tư vấn luật
      dịch vụ thành lập doanh nghiệp

      Nhìn thấy thực lực của Đỗ Mật Nhi, Âu Dương Phiên Tình, Tô Hân Nhi còn cao hơn cả mình, Tư Mã Yên Nhiên cũng ganh đua trong lòng.

      Danh khí của Phá Quân Bang hiện tại đã lên rất cao, một số tam tinh đấu vương, thậm chí là tứ tinh Đấu vương cũng gia nhập. Chỉ là Nhạc Thành đã để lại lời nói, muốn gia nhập Phá quân bang thì sau này rời khỏi đấu khí học viện vẫn phải là người của Phá Quân Bang, nếu không chịu thì sẽ không được gia nhập, điều này khiến cho rất nhiều người không muốn vào nữa, tuy nhiên hiện tai Phá Quân Bang cũng đã có hơn một trăm người.

      Mấy hôm trước, Âu Dương Phiên Tình, Đỗ Mật Nhi còn có Tư Mã Yên Nhiên luyện chế ra không ít đan dược bán cho Phá Quân Bang, những đan dược này đều là đan dược tứ phẩm, bán giá trị rất cao.

      Delete
  2. On the off chance that you don't have credit, or you have terrible credit, and you don't have the money, how is that bill paid? If not for payday advances, that bill wouldn't be paid.

    ReplyDelete
  3. So in the event that you require money quick, a bank advance is not for you. Bank credits work preferred for arranged costs over for unanticipated money related crises.

    ReplyDelete
  4. So what do you do? Given the innovative headway, you can essentially sign on to an online fund website that gives quick loans.

    ReplyDelete
  5. Once the business goes ahead, you can either apply for more advances online to use as extra financing or essentially pay off your obligation.

    ReplyDelete
  6. Thank you for sharing the post! This is what I need to find.
    instagram viewer

    ReplyDelete
  7. Banks have diverse arrangements as to credit loaning, so they won't not forward military payday advances to specific divisions of military. payday loans san diego

    ReplyDelete
  8. Fundamentally a vendor loan moneylender buys a little level of future Master Card and Visa deals, and the entrepreneur pays back this as an every day level of such deals.Cash Advances Chicago

    ReplyDelete