Esta palestra é fruto da iniciativa de adoção da JSR 339 pelo Grupo de Usuários Java de SC. Foi apresentada no The Developers Conference 2014 (Florianópolis). Trata das novidades da JAX-RS 2 em relação a especificação anterior.
10. Interface Uniforme
Verbos HTTP Ação
POST Cria um novo recurso
PUT Atualiza um recurso
DELETE Remove um recurso
GET Retorna um recurso
11. JAX-RS 1.x
Final Release em 2008
Objetivos
Baseado em POJO
Centralizado em HTTP
Independência de formato
Independência de container
Inclusão no Java EE 6
22. JAX-RS 2.0
Final Release em Maio de 2013
Solicitações (JSR 339)
Client API
Asynchronous processing
Filters / Interceptors
Bean Validation
Hypermedia
MVC
30. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
31. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
32. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
33. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
34. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
35. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
36. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
GSON,
Jackson,
Jettison,
XStream
37. @Test
public void deveConterOLivro_javaee6() throws Exception {
URL url = new URL("http://localhost:8080/rest-example/resources/books/10");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
String result = IOUtils.toString(con.getInputStream(), "UTF-8");
con.disconnect();
Book book = new Gson().fromJson(result, Book.class);
assertThat(book, notNullValue());
}
148. Modifier and Type Constant Field Value
public static final int AUTHENTICATION 1000
public static final int AUTHORIZATION 2000
public static final int ENTITY_CODER 3000
public static final int HEADER_DECORATOR 4000
public static final int USER 5000
javax.ws.rs.Priorities
154. HATEOAS
Hipermídia como motor do estado do aplicativo
“If the engine of application is not being driven
by hypertext, then it cannot be RESTful and
cannot be a REST API” (Roy T. Fielding)