URL Templates With JAX-RS

JAX-RS WebTarget comes with template mechanism to substitute placeholders in URIs:


import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;

public class JAXRSTemplates {

    private Client client;
    private WebTarget tut;

    @Before
    public void initClient() {
        this.client = ClientBuilder.newClient();
        this.tut = this.client.target("https://en.wikipedia.org/wiki/{keyword}");
    }

    @Test
    public void contentContainsKeyword() {
        String keyword = "Java";
        String content = this.tut.resolveTemplate("keyword", keyword).
                request().
                get(String.class);
        assertThat(content, containsString(keyword));
    }
}

See you at Java EE Workshops at Munich Airport, Terminal 2 or Virtual Dedicated Workshops / consulting. Is Munich's airport too far? Learn from home: airhacks.io.


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License