Package javax.ws.rs.core

Examples of javax.ws.rs.core.Link


        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
        m.add("Link", Link.valueOf("<http://example.com/page1>;rel=\"previous\""));
        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
        Link.Builder linkBuilder = delegate.createLinkBuilder();
        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
        // Reset linkbuilder
        linkBuilder = delegate.createLinkBuilder();
        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
        Link[] links = new Link[2];
        links[0] = prevLink;
        links[1] = nextLink;
        checkBuild(Response.ok().links(links).build(), 200, null, m);
    }
View Full Code Here


        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
        m.add("Link", Link.valueOf("<http://example.com/page1>;rel=\"previous\""));
        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
        Link.Builder linkBuilder = delegate.createLinkBuilder();
        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
        linkBuilder = delegate.createLinkBuilder();
        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
        checkBuild(Response.ok().links(prevLink).links(nextLink).build(), 200, null, m);
    }
View Full Code Here

    public void testLinksWithReset() {
        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
        RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
        Link.Builder linkBuilder = delegate.createLinkBuilder();
        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
        linkBuilder = delegate.createLinkBuilder();
        Link nextLink = linkBuilder.uri("http://example.com/page3").rel("next").build();
        // CHECK: Should .links() do a reset? Undocumented feature; so we'll
        // test with the awkward <code>(Link[])null</code> instead..
        // Note: .cookie() has same behavior.
        checkBuild(Response.ok().links(prevLink).links((Link[])null).links(nextLink).build(), 200, null, m);
    }
View Full Code Here

       
        meta.add(HttpHeaders.LINK, "<http://next>;rel=next");
        meta.add(HttpHeaders.LINK, "<http://prev>;rel=prev");
       
        assertTrue(ri.hasLink("next"));
        Link next = ri.getLink("next");
        assertNotNull(next);
        assertTrue(ri.hasLink("prev"));
        Link prev = ri.getLink("prev");
        assertNotNull(prev);
       
        Set<Link> links = ri.getLinks();
        assertTrue(links.contains(next));
        assertTrue(links.contains(prev));
       
        assertEquals("http://next", next.getUri().toString());
        assertEquals("next", next.getRel());
        assertEquals("http://prev", prev.getUri().toString());
        assertEquals("prev", prev.getRel());
    }
View Full Code Here

        }
       
        @Override
        public boolean equals(Object o) {
            if (o instanceof Link) {
                Link other = (Link)o;
                return uri.equals(other.getUri())
                    && getParams().equals(other.getParams());
            } else {
                return false;
            }
        }
View Full Code Here

   
    public boolean hasLink(String relation) {
        List<Object> linkValues = metadata.get(HttpHeaders.LINK);
        if (linkValues != null) {
            for (Object o : linkValues) {
                Link link = o instanceof Link ? (Link)o : Link.valueOf(o.toString());
                if (relation.equals(link.getRel())) {
                    return true;
                }
            }
        }
        return false;
View Full Code Here

        }
        return null;
    }

    public Link.Builder getLinkBuilder(String relation) {
        Link link = getLink(relation);
        return link == null ? null : Link.fromLink(link);
    }
View Full Code Here

        if (linkValues == null) {
            return Collections.emptyMap();
        } else {
            Map<String, Link> links = new LinkedHashMap<String, Link>();
            for (Object o : linkValues) {
                Link link = o instanceof Link ? (Link)o : Link.valueOf(o.toString());
                if (!link.getUri().isAbsolute()) {
                    URI requestURI = URI.create((String)outMessage.get(Message.REQUEST_URI));
                    link = Link.fromLink(link).baseUri(requestURI).build();
                }
                links.put(link.getRel(), link);
            }
            return links;
        }
    }
View Full Code Here

   

    @Test
    public void testBuild() throws Exception {
        Link.Builder linkBuilder = new LinkBuilderImpl();
        Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
        assertEquals("<http://example.com/page1>;rel=\"previous\"", prevLink.toString());
    }
View Full Code Here

        };
        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);
    }
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.Link

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.