Commit 300f2911 by Patryk Czarnik

Projekt RestKlient i pierwsze zapytanie

parent bb251f10
/.classpath
/.project
/.settings/
/target/
/produkt1.txt
/wynik?.*
/*.pdf
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>pl.alx.kjava</groupId>
<artifactId>PC36-RestKlient</artifactId>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<resteasy.version>5.0.4.Final</resteasy.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>${resteasy.version}</version>
</dependency>
</dependencies>
</project>
package sklep.klient;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
public class PrzykladoweZapytanie {
// To pisaliśmy na żywo w tracie zajęć.
public static void main(String[] args) {
System.out.println("Buduję klienta");
Client client = ClientBuilder.newClient();
System.out.println("Wysyłam zapytanie...");
Response response = client.target("http://localhost:8080/PC35-RestSerwer-1.0/products.json/1")
.request().buildGet().invoke();
System.out.println("Mam odpowiedź: " + response);
System.out.println("Kod: " + response.getStatus());
System.out.println("Content-type: " + response.getMediaType());
String trescOdpowiedzi = response.readEntity(String.class);
System.out.println("Treść odpowiedzi:");
System.out.println(trescOdpowiedzi);
}
}
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