Java javax.ws.rs.core.UriInfo 代码实例

・4 分钟阅读

以下是展示如何使用javax.ws.rs.core.UriInfo的最佳示例。 我们使用了代码质量辨别算法从开源项目中提取出了最佳的优秀示例。

实例 1


@Override
public Response head(UriInfo uriInfo)
{
   UriBuilder absolute = uriInfo.getBaseUriBuilder();
   String customerUrl = absolute.clone().path("customers").build().toString();
   String orderUrl = absolute.clone().path("orders").build().toString();
   String productUrl = absolute.clone().path("products").build().toString();
   Response.ResponseBuilder builder = Response.ok();
   builder.header("Link", new Link("customers", customerUrl, "application/xml"));
   builder.header("Link", new Link("orders", orderUrl, "application/xml"));
   builder.header("Link", new Link("products", productUrl, "application/xml"));
   return builder.build();
}
 

实例 2


/**
 * @param uriInfo UriInfo
 * @return Cell ?????? ????Cell?????????null
 */
public static Cell load(final UriInfo uriInfo) {
    URI reqUri = uriInfo.getRequestUri();
    URI baseUri = uriInfo.getBaseUri();
    String rPath = reqUri.getPath();
    String bPath = baseUri.getPath();
    rPath = rPath.substring(bPath.length());
    String[] paths = StringUtils.split(rPath, "/");
    return findCell("s.Name.untouched", paths[0], uriInfo);
}
 

实例 3


/**
 * Creates the URL for an upload operation (create or append).
 *
 * @param uriInfo uri info of the request.
 * @param uploadOperation operation for the upload URL.
 *
 * @return the URI for uploading data.
 */
protected URI createUploadRedirectionURL(UriInfo uriInfo, Enum<?> uploadOperation) {
  UriBuilder uriBuilder = uriInfo.getRequestUriBuilder();
  uriBuilder = uriBuilder.replaceQueryParam(OperationParam.NAME, uploadOperation).
    queryParam(DataParam.NAME, Boolean.TRUE);
  return uriBuilder.build(null);
}
 

实例 4


@GET
public String doGet(@Context UriInfo uriInfo) {
    URI baseUri = uriInfo.getBaseUri();
    URI uri = uriInfo.getAbsolutePath();
    assertEquals(BASE_URI, baseUri);
    assertEquals(UriBuilder.fromUri(BASE_URI).path("a/b").build(), uri);
    return "GET";
}
 

实例 5


private String getResourcePath(UriInfo uriInfo) {
    String path = uriInfo.getPath();
    StringBuilder sb = new StringBuilder();
    sb.append("/realms/");
    sb.append(realm.getName());
    sb.append("/");
    String realmRelative = sb.toString();
    return path.substring(path.indexOf(realmRelative) + realmRelative.length());
}
 

实例 6


public void testGeneral() throws Exception {
    WebApplicationImpl wai = new WebApplicationImpl();
    ContainerRequest r = new TestHttpRequestContext(wai,
            "GET", null,
            "/context/p1;x=1;y=1/p2;x=2;y=2/p3;x=3;y=3", "/context/");
    UriInfo ui = new WebApplicationContext(wai, r, null);
    List<PathSegment> segments = ui.getPathSegments();
    assertEquals(3, segments.size());
    PathSegment segment = segments.get(0);
    assertEquals("p1", segment.getPath());
    MultivaluedMap<String, String> m = segment.getMatrixParameters();        
    assertEquals("1", m.getFirst("x"));
    assertEquals("1", m.getFirst("y"));
    segment = segments.get(1);
    assertEquals("p2", segment.getPath());
    m = segment.getMatrixParameters();        
    assertEquals("2", m.getFirst("x"));
    assertEquals("2", m.getFirst("y"));
    segment = segments.get(2);
    assertEquals("p3", segment.getPath());
    m = segment.getMatrixParameters();        
    assertEquals("3", m.getFirst("x"));
    assertEquals("3", m.getFirst("y"));
}
 
讨论
淘淘あ西西 profile image