Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sample-jaxrs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Emmanuel Bruno
sample-jaxrs
Commits
e69b65d9
Commit
e69b65d9
authored
4 years ago
by
Emmanuel Bruno
Browse files
Options
Downloads
Patches
Plain Diff
fixes client with the new API.
parent
5d4ea926
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/univtln/bruno/samples/jaxrs/client/BiblioClient.java
+16
-12
16 additions, 12 deletions
...a/fr/univtln/bruno/samples/jaxrs/client/BiblioClient.java
with
16 additions
and
12 deletions
src/main/java/fr/univtln/bruno/samples/jaxrs/client/BiblioClient.java
+
16
−
12
View file @
e69b65d9
...
@@ -7,29 +7,33 @@ import jakarta.ws.rs.client.ClientBuilder;
...
@@ -7,29 +7,33 @@ import jakarta.ws.rs.client.ClientBuilder;
import
jakarta.ws.rs.client.Entity
;
import
jakarta.ws.rs.client.Entity
;
import
jakarta.ws.rs.client.WebTarget
;
import
jakarta.ws.rs.client.WebTarget
;
import
jakarta.ws.rs.core.MediaType
;
import
jakarta.ws.rs.core.MediaType
;
import
lombok.extern.java.Log
;
/**
/**
* Created by bruno on 04/11/14.
* Created by bruno on 04/11/14.
*/
*/
@Log
public
class
BiblioClient
{
public
class
BiblioClient
{
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
// create the client
// create the client
Client
client
=
ClientBuilder
.
newClient
();
Client
client
=
ClientBuilder
.
newClient
();
WebTarget
webResource
=
client
.
target
(
BiblioServer
.
BASE_URI
);
WebTarget
webResource
=
client
.
target
(
"http://localhost:9998/myapp"
);
//Send a get with a String as response
//Send a put with a String as response
String
responseAuteursAsJson
=
webResource
.
path
(
"biblio/auteurs"
).
request
().
get
(
String
.
class
);
String
responseInitAsString
=
webResource
.
path
(
"biblio/init"
)
System
.
out
.
println
(
responseAuteursAsJson
);
.
request
().
put
(
Entity
.
entity
(
""
,
MediaType
.
TEXT_PLAIN
),
String
.
class
);
log
.
info
(
responseInitAsString
);
//Idem but the result is deserialised to an instance of Auteur
//Send a get and parse the response as a String
Auteur
auteur
=
webResource
.
path
(
"biblio/auteur/1"
).
request
().
get
(
Auteur
.
class
);
String
responseAuteursAsJsonString
=
webResource
.
path
(
"biblio/auteurs"
)
System
.
out
.
println
(
auteur
);
.
request
().
get
(
String
.
class
);
log
.
info
(
responseAuteursAsJsonString
);
webResource
.
path
(
"biblio/a
uteur
"
)
//Idem but the result is deserialised to an instance of A
uteur
.
queryParam
(
"nom"
,
"John"
).
queryParam
(
"prenom"
,
"Smith
"
)
Auteur
auteur
=
webResource
.
path
(
"biblio/auteurs/1
"
)
.
request
()
.
put
(
Entity
.
entity
(
Auteur
.
builder
().
prenom
(
"John"
).
nom
(
"Smith"
).
build
(),
.
request
()
MediaType
.
APPLICATION_JSON
)
);
.
get
(
Auteur
.
class
);
System
.
out
.
println
(
webResource
.
path
(
"biblio/auteurs"
).
request
().
get
(
String
.
class
));
log
.
info
(
auteur
.
toString
(
));
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment