Search in sources :

Example 26 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class BuilderClientIT method linksTest.

/*
   * @testName: linksTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:882;
   * 
   * @test_Strategy: Add one or more link headers.
   */
@Test
public void linksTest() throws Fault {
    String rel = "REL";
    Link link1 = Link.fromUri(URL).rel(rel + "1").build();
    Link link11 = Link.fromUri(URL).rel(rel + "11").build();
    Link link2 = Link.fromUri(URL + "/link2").rel(rel + "2").build();
    Response response = Response.ok().links(link1, link11, link2).build();
    Link link = response.getLink(rel + "1");
    assertTrue(link != null, "link is null");
    assertTrue(link.toString().contains(URL), "link" + link + "does not contain expected" + URL);
    link = response.getLink(rel + "11");
    assertTrue(link != null, "link is null");
    assertTrue(link.toString().contains(URL), "link" + link + "does not contain expected" + URL);
    link = response.getLink(rel + "2");
    assertTrue(link != null, "link is null");
    assertTrue(link.toString().contains(URL + "/link2"), "link" + link + "does not contain expected" + URL + "/link2");
    logMsg("Found expected links");
}
Also used : Response(jakarta.ws.rs.core.Response) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 27 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class BuilderClientIT method linkUriStringTest.

/*
   * @testName: linkUriStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:880;
   * 
   * @test_Strategy: Add a link header.
   */
@Test
public void linkUriStringTest() throws Fault {
    URI uri = null;
    try {
        uri = new URI(URL);
    } catch (URISyntaxException e) {
        fail(e.getMessage());
    }
    String rel = "REL";
    Response response = Response.ok().link(uri, rel).build();
    Link link = response.getLink(rel);
    assertTrue(link != null, "link is null");
    assertTrue(link.toString().contains(URL), "link" + link + "does not contain expected" + URL);
    logMsg("Found expected link", link);
}
Also used : Response(jakarta.ws.rs.core.Response) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) Link(jakarta.ws.rs.core.Link) Test(org.junit.jupiter.api.Test)

Example 28 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class Resource method getLinks.

@POST
@Path("getlinks")
public Response getLinks(String uris) {
    ResponseBuilder builder = createResponseWithHeader();
    if (uris != null && uris.length() != 0) {
        String[] tokens = uris.split(";");
        Link[] links = new Link[tokens.length];
        for (int i = 0; i != tokens.length; i++) links[i] = Link.fromUri(tokens[i]).build();
        builder = builder.links(links);
    }
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Link(jakarta.ws.rs.core.Link) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 29 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class LinkExamples method example1.

/**
 * 3-step process: Build URI, build Link and build Response.
 *
 * @return response.
 */
public Response example1() {
    URI uri = UriBuilder.fromUri("http://foo.bar/employee/john").build();
    Link link = Link.fromUri(uri).rel("emp").title("employee").build();
    return Response.ok().links(link).build();
}
Also used : URI(java.net.URI) Link(jakarta.ws.rs.core.Link)

Example 30 with Link

use of jakarta.ws.rs.core.Link in project jaxrs-api by eclipse-ee4j.

the class ResourceExample method getIt.

@GET
@Produces({ "application/json" })
public MyModel getIt() {
    Link self = Link.fromMethod(getClass(), "getIt").baseUri(uriInfo.getBaseUri()).rel("self").buildRelativized(uriInfo.getRequestUri());
    MyModel m = new MyModel();
    m.setLink(self);
    m.setAtomLink(self);
    return m;
}
Also used : Link(jakarta.ws.rs.core.Link) Produces(jakarta.ws.rs.Produces) GET(jakarta.ws.rs.GET)

Aggregations

Link (jakarta.ws.rs.core.Link)84 Test (org.junit.jupiter.api.Test)69 Builder (jakarta.ws.rs.core.Link.Builder)37 UriBuilder (jakarta.ws.rs.core.UriBuilder)27 Response (jakarta.ws.rs.core.Response)23 URI (java.net.URI)19 ClientBuilder (jakarta.ws.rs.client.ClientBuilder)14 URISyntaxException (java.net.URISyntaxException)7 Path (jakarta.ws.rs.Path)4 POST (jakarta.ws.rs.POST)3 Client (jakarta.ws.rs.client.Client)3 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)3 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)3 UriBuilderException (jakarta.ws.rs.core.UriBuilderException)3 GET (jakarta.ws.rs.GET)2 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)2 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 Marshaller (jakarta.xml.bind.Marshaller)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2