Java Code Examples for javax.ws.rs.core.Link#fromUri()

The following examples show how to use javax.ws.rs.core.Link#fromUri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonHyperSchema.java    From rest-schemagen with Apache License 2.0 6 votes vote down vote up
@Override
public Link unmarshal(JsonLink v) {
	Link.Builder lb = Link.fromUri(v.getHref());
	if (v.getMap() != null) {
		for (Entry<String, String> en : v.getMap().entrySet()) {
			lb.param(en.getKey(), en.getValue());
		}
	}
	if (v.getSchema() != null) {
		lb.param(LinkCreator.SCHEMA_PARAM_KEY, v.getSchema().toString());
	}

	if (v.getTargetSchema() != null) {
		lb.param(LinkCreator.TARGET_SCHEMA_PARAM_KEY, v.getTargetSchema().toString());
	}
	return lb.build();
}
 
Example 2
Source File: LinkBuilderImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testBuildObjects() throws Exception {
    StringBuilder path1 = new StringBuilder().append("p1");
    ByteArrayInputStream path2 = new ByteArrayInputStream("p2".getBytes()) {
        @Override
        public String toString() {
            return "p2";
        }
    };
    URI path3 = new URI("p3");

    String expected = "<" + "http://host.com:888/" + "p1/p2/p3" + ">";
    Link.Builder builder = Link.fromUri("http://host.com:888/" + "{x1}/{x2}/{x3}");
    Link link = builder.build(path1, path2, path3);
    assertNotNull(link);
    assertEquals(link.toString(), expected);
}
 
Example 3
Source File: LinkAdapter.java    From nifi-registry with Apache License 2.0 5 votes vote down vote up
/**
 * Convert a {@link JaxbLink} into a {@link Link}.
 *
 * @param v instance of type {@link JaxbLink}.
 * @return mapped instance of type {@link Link.JaxbLink}
 */
@Override
public Link unmarshal(JaxbLink v) {
    if (v == null) {
        return null;
    }

    Link.Builder lb = Link.fromUri(v.getUri());
    if (v.getParams() != null) {
        for (Map.Entry<String,String> e : v.getParams().entrySet()) {
            lb.param(e.getKey(), e.getValue());
        }
    }
    return lb.build();
}
 
Example 4
Source File: MementoResource.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * Filter link parameters from a provided Link object, if configured to do so.
 * @param link the link
 * @param filter whether to filter the memento parameters
 * @return a Link without Memento parameters, if desired; otherwise, the original link
 */
public static Link filterLinkParams(final Link link, final boolean filter) {
    // from and until parameters can cause problems with downstream applications because they contain commas. This
    // method makes it possible to filter out those params, if desired. By default, they are not filtered out.
    if (filter) {
        if (TIMEMAP.equals(link.getRel())) {
            return Link.fromUri(link.getUri()).rel(TIMEMAP).type(APPLICATION_LINK_FORMAT).build();
        } else if (link.getRels().contains(MEMENTO)) {
            final Link.Builder builder = Link.fromUri(link.getUri());
            link.getRels().forEach(builder::rel);
            return builder.build();
        }
    }
    return link;
}
 
Example 5
Source File: LinkBuilderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelativeLink() throws Exception {
    Link.Builder linkBuilder = Link.fromUri("relative");
    linkBuilder.baseUri("http://localhost:8080/base/path");
    Link link = linkBuilder.rel("next").build();
    assertEquals("<http://localhost:8080/base/relative>;rel=\"next\"", link.toString());
}
 
Example 6
Source File: LinkBuilderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testRelativeLink2() throws Exception {
    Link.Builder linkBuilder = Link.fromUri("/relative");
    linkBuilder.baseUri("http://localhost:8080/base/path");
    Link link = linkBuilder.rel("next").build();
    assertEquals("<http://localhost:8080/relative>;rel=\"next\"", link.toString());
}
 
Example 7
Source File: LinkBuilderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("to be fixed for TCK")
public void testNoArgsThrowsUriBuilderExceptionTest() {
    Link.Builder builder = Link.fromUri("http://:@");
    try {
        Link link = builder.build();
        fail("No exception has been thrown for link " + link);
    } catch (UriBuilderException e) {
        //expected
    }
}