Skip to content
Snippets Groups Projects
Commit 522e22d6 authored by Emmanuel Bruno's avatar Emmanuel Bruno
Browse files

fixes client to english API.3

parent ff688d22
Branches
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ biblio-demo-header-1: myvalue ...@@ -87,7 +87,7 @@ biblio-demo-header-1: myvalue
biblio-demo-header-2: anothervalue biblio-demo-header-2: anothervalue
### Authorization by token, part 1. Retrieve and save token with Basic Authentication ### Authorization by token, part 1. Retrieve and save token with Basic Authentication
# TOKEN=$(curl -v --user "john.doe@nowhere.com:admin" "http://localhost:9998/myapp/biblio/login") # TOKEN=$(curl -v --user "john.doe@nowhere.com:admin" "http://localhost:9998/mylibrary/setup/login")
GET http://localhost:9998/mylibrary/setup/login GET http://localhost:9998/mylibrary/setup/login
Authorization: Basic john.doe@nowhere.com admin Authorization: Basic john.doe@nowhere.com admin
......
...@@ -17,20 +17,20 @@ public class BiblioClient { ...@@ -17,20 +17,20 @@ public class BiblioClient {
public static void main(String[] args) { public static void main(String[] args) {
// create the rest client // create the rest client
Client client = ClientBuilder.newClient(); Client client = ClientBuilder.newClient();
WebTarget webResource = client.target("http://localhost:9998/myapp"); WebTarget webResource = client.target("http://localhost:9998/mylibrary");
//Send a put with a String as response //Send a put with a String as response
String responseInitAsString = webResource.path("biblio/init") String responseInitAsString = webResource.path("library/init")
.request().put(Entity.entity("", MediaType.TEXT_PLAIN), String.class); .request().put(Entity.entity("", MediaType.TEXT_PLAIN), String.class);
log.info(responseInitAsString); log.info(responseInitAsString);
//Send a get and parse the response as a String //Send a get and parse the response as a String
String responseAuteursAsJsonString = webResource.path("biblio/authors") String responseAuteursAsJsonString = webResource.path("authors")
.request().get(String.class); .request().get(String.class);
log.info(responseAuteursAsJsonString); log.info(responseAuteursAsJsonString);
//Idem but the result is deserialised to an instance of Auteur //Idem but the result is deserialised to an instance of Auteur
Author author = webResource.path("biblio/authors/1") Author author = webResource.path("authors/1")
.request() .request()
.get(Author.class); .get(Author.class);
log.info(author.toString()); log.info(author.toString());
...@@ -38,7 +38,7 @@ public class BiblioClient { ...@@ -38,7 +38,7 @@ public class BiblioClient {
//Log in to get the token with basci authentication //Log in to get the token with basci authentication
String email = "john.doe@nowhere.com"; String email = "john.doe@nowhere.com";
String passwd = "admin"; String passwd = "admin";
String token = webResource.path("biblio/login") String token = webResource.path("setup/login")
.request() .request()
.accept(MediaType.TEXT_PLAIN) .accept(MediaType.TEXT_PLAIN)
.header("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString((email + ":" + passwd).getBytes())) .header("Authorization", "Basic " + java.util.Base64.getEncoder().encodeToString((email + ":" + passwd).getBytes()))
...@@ -46,7 +46,7 @@ public class BiblioClient { ...@@ -46,7 +46,7 @@ public class BiblioClient {
if (!token.isBlank()) { if (!token.isBlank()) {
log.info("token received."); log.info("token received.");
//We access a JWT protected URL with the token //We access a JWT protected URL with the token
String result = webResource.path("biblio/secured") String result = webResource.path("setup/secured")
.request() .request()
.header("Authorization", "Bearer " + token) .header("Authorization", "Bearer " + token)
.get(String.class); .get(String.class);
......
...@@ -240,7 +240,7 @@ public class Library { ...@@ -240,7 +240,7 @@ public class Library {
//Because getter are generated by lombok //Because getter are generated by lombok
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString @ToString(exclude = "books")
public static class Author implements Serializable { public static class Author implements Serializable {
@EqualsAndHashCode.Include @EqualsAndHashCode.Include
@XmlTransient @XmlTransient
...@@ -279,7 +279,7 @@ public class Library { ...@@ -279,7 +279,7 @@ public class Library {
@XmlAccessorType(XmlAccessType.FIELD) @XmlAccessorType(XmlAccessType.FIELD)
@EqualsAndHashCode(onlyExplicitlyIncluded = true) @EqualsAndHashCode(onlyExplicitlyIncluded = true)
@ToString @ToString(exclude = "authors")
public static class Book implements Serializable { public static class Book implements Serializable {
@EqualsAndHashCode.Include @EqualsAndHashCode.Include
@XmlTransient @XmlTransient
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment