Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
20230403
Commits
212d5073
Commit
212d5073
authored
May 26, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RestEasy - pierwszy klient (byte[])
parent
b7f3dc4b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
pom.xml
PC34-RestKlient/pom.xml
+5
-0
P05_RestClient.java
...lient/src/main/java/sklep/klient_rest/P05_RestClient.java
+42
-0
No files found.
PC34-RestKlient/pom.xml
View file @
212d5073
...
@@ -33,5 +33,10 @@
...
@@ -33,5 +33,10 @@
<artifactId>
jakarta.json
</artifactId>
<artifactId>
jakarta.json
</artifactId>
<version>
2.0.1
</version>
<version>
2.0.1
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.jboss.resteasy
</groupId>
<artifactId>
resteasy-client
</artifactId>
<version>
6.2.4.Final
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
PC34-RestKlient/src/main/java/sklep/klient_rest/P05_RestClient.java
0 → 100644
View file @
212d5073
package
sklep
.
klient_rest
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
jakarta.ws.rs.client.Client
;
import
jakarta.ws.rs.client.ClientBuilder
;
import
jakarta.ws.rs.client.Invocation
;
import
jakarta.ws.rs.client.WebTarget
;
import
jakarta.ws.rs.core.Response
;
public
class
P05_RestClient
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Startujemy"
);
Client
client
=
ClientBuilder
.
newClient
();
System
.
out
.
println
(
"Przygotowuję zapytanie"
);
WebTarget
target
=
client
.
target
(
Ustawienia
.
ADRES_USLUGI
).
path
(
"products.json"
);
Invocation
invocation
=
target
.
request
().
buildGet
();
System
.
out
.
println
(
"Wysyłam zapytanie"
);
Response
response
=
invocation
.
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
());
byte
[]
dane
=
response
.
readEntity
(
byte
[].
class
);
System
.
out
.
println
(
"Dane mają "
+
dane
.
length
+
" bajtów."
);
try
{
Files
.
write
(
Paths
.
get
(
"wynik05.json"
),
dane
);
System
.
out
.
println
(
"Zapisałem w pliku"
);
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
e
);
}
System
.
out
.
println
(
"Koniec"
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment