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

The following examples show how to use javax.ws.rs.core.Link#valueOf() . 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: ResponseImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
public boolean hasLink(String relation) {
    List<Object> linkValues = metadata.get(HttpHeaders.LINK);
    if (linkValues != null) {
        for (Object o : linkValues) {
            if (o instanceof Link && relation.equals(((Link)o).getRel())) {
                return true;
            }

            String[] links = LINK_DELIMITER.split(o.toString());
            for (String splitLink : links) {
                Link link = Link.valueOf(splitLink);
                if (relation.equals(link.getRel())) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
Example 2
Source File: TrellisHttpFilter.java    From trellis with Apache License 2.0 5 votes vote down vote up
private void validateLink(final ContainerRequestContext ctx) {
    final String link = ctx.getHeaderString(LINK);
    if (link != null) {
        try {
            Link.valueOf(link);
        } catch (final IllegalArgumentException ex) {
            ctx.abortWith(status(BAD_REQUEST).build());
        }
    }
}
 
Example 3
Source File: TrellisRequest.java    From trellis with Apache License 2.0 5 votes vote down vote up
/**
 * Get the Link header.
 *
 * @return the Link header
 */
public Link getLink() {
    final String link = headers.getFirst(LINK);
    if (link != null) {
        return Link.valueOf(link);
    }
    return null;
}
 
Example 4
Source File: InteractionModelUtils.java    From ldp4j with Apache License 2.0 5 votes vote down vote up
static InteractionModel fromLink(String strLink) {
	InteractionModel result=null;
	try {
		Link link = Link.valueOf(strLink);
		if(link.getRel().equals(INTERACTION_MODEL_LINK_REL)) {
			result=toInteractionModel(link.getUri());
		}
	} catch (IllegalArgumentException e) {
		LOGGER.trace("Could not parse link '"+strLink+"'",e);
	}
	return result;
}
 
Example 5
Source File: ResponseImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private List<Link> parseLink(Object o) {
    if (o instanceof Link) {
        return Collections.singletonList(makeAbsoluteLink((Link) o));
    }

    List<Link> links = new ArrayList<>();
    String[] linkArray = LINK_DELIMITER.split(o.toString());

    for (String textLink : linkArray) {
        Link link = Link.valueOf(textLink);
        links.add(makeAbsoluteLink(link));
    }

    return Collections.unmodifiableList(links);
}
 
Example 6
Source File: LinkHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testFromComplexString() {
    Link l = Link.valueOf("<http://bar>;rel=next;title=\"Next Link\";type=text/xml;method=get");
    assertEquals("http://bar", l.getUri().toString());
    String rel = l.getRel();
    assertEquals("next", rel);
    assertEquals("Next Link", l.getTitle());
    assertEquals("text/xml", l.getType());
    assertEquals("get", l.getParams().get("method"));
}
 
Example 7
Source File: LinkHeaderProviderTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testToString() {
    String headerValue = "<http://bar>;rel=next;title=\"Next Link\";type=text/xml;method=get";
    String expected = "<http://bar>;rel=\"next\";title=\"Next Link\";type=\"text/xml\";method=\"get\"";
    Link l = Link.valueOf(headerValue);
    String result = l.toString();
    assertEquals(expected, result);
}
 
Example 8
Source File: LinkHeaderProviderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testFromSimpleString() {
    Link l = Link.valueOf("<http://bar>");
    assertEquals("http://bar", l.getUri().toString());
}
 
Example 9
Source File: LinkHeaderProviderTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testFromSimpleString2() {
    Link l = Link.valueOf("</>");
    assertEquals("/", l.getUri().toString());
}