Commit 41a0b40d by Patryk Czarnik

Klient REST JAXB

parent 99310bb9
......@@ -38,5 +38,10 @@
<artifactId>resteasy-client</artifactId>
<version>6.2.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>6.2.4.Final</version>
</dependency>
</dependencies>
</project>
package sklep.klient_rest;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.core.Response;
import sklep.model.Product;
import sklep.model.ProductList;
public class P07_RestClient_JAXB {
public static void main(String[] args) {
Client client = ClientBuilder.newClient();
Response response = client.target(Ustawienia.ADRES_USLUGI)
.path("products.xml")
.request().buildGet()
.invoke();
System.out.println("Mam odpowiedź: " + response);
System.out.println("Status: " + response.getStatus());
System.out.println("C-Type: " + response.getMediaType());
System.out.println("Length: " + response.getLength());
ProductList products = response.readEntity(ProductList.class);
System.out.println("Otrzymane dane:");
for (Product product : products.getProducts()) {
System.out.println(product);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment