Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
Web Client
Project
Project
Details
Activity
Releases
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
Task Manager
Web Client
Commits
7dc9adcc
Commit
7dc9adcc
authored
Apr 05, 2023
by
Lokesh Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
animal
model class and service, controller deleted
parent
348282f6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
0 additions
and
147 deletions
+0
-147
AnimalController.java
...lokesh/webclientconsumer/controller/AnimalController.java
+0
-39
Animal.java
src/main/java/com/lokesh/webclientconsumer/model/Animal.java
+0
-21
GetAllAnimalRunner.java
...m/lokesh/webclientconsumer/runner/GetAllAnimalRunner.java
+0
-24
AnimalService.java
...a/com/lokesh/webclientconsumer/service/AnimalService.java
+0
-13
AnimalServiceImpl.java
...esh/webclientconsumer/service/impl/AnimalServiceImpl.java
+0
-50
No files found.
src/main/java/com/lokesh/webclientconsumer/controller/AnimalController.java
deleted
100644 → 0
View file @
348282f6
package
com
.
lokesh
.
webclientconsumer
.
controller
;
import
com.lokesh.webclientconsumer.model.Animal
;
import
com.lokesh.webclientconsumer.service.AnimalService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.HttpStatus
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.*
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
@Slf4j
@RestController
@RequestMapping
(
value
=
"/animal"
)
public
class
AnimalController
{
@Autowired
private
AnimalService
animalService
;
@GetMapping
(
produces
=
MediaType
.
TEXT_EVENT_STREAM_VALUE
)
@ResponseStatus
(
HttpStatus
.
OK
)
public
Flux
<
Animal
>
getAnimal
()
{
return
animalService
.
getAnimals
();
}
@GetMapping
(
value
=
"/{id}"
)
public
Mono
<
Animal
>
findById
(
@PathVariable
(
"id"
)
String
id
)
{
try
{
return
animalService
.
findById
(
id
);
}
catch
(
Exception
e
)
{
log
.
error
(
"Exception find in findById() method."
);
throw
e
;
}
}
@PostMapping
(
MediaType
.
APPLICATION_JSON_VALUE
)
public
Mono
<
Animal
>
postAnimal
(
@RequestBody
Animal
animal
)
{
return
this
.
animalService
.
save
(
animal
);
}
}
src/main/java/com/lokesh/webclientconsumer/model/Animal.java
deleted
100644 → 0
View file @
348282f6
package
com
.
lokesh
.
webclientconsumer
.
model
;
import
lombok.*
;
import
org.springframework.data.annotation.Id
;
import
org.springframework.data.mongodb.core.mapping.Document
;
@Data
@Builder
@Document
@ToString
@NoArgsConstructor
@AllArgsConstructor
public
class
Animal
{
@Id
private
String
id
;
private
String
name
;
private
String
kingdom
;
}
src/main/java/com/lokesh/webclientconsumer/runner/GetAllAnimalRunner.java
deleted
100644 → 0
View file @
348282f6
package
com
.
lokesh
.
webclientconsumer
.
runner
;
import
com.lokesh.webclientconsumer.model.Animal
;
import
org.springframework.boot.CommandLineRunner
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
reactor.core.publisher.Flux
;
@Component
public
class
GetAllAnimalRunner
implements
CommandLineRunner
{
private
static
final
String
baseUrl
=
"http://localhost:8081/api/v1/"
;
@Override
public
void
run
(
String
...
args
)
throws
Exception
{
WebClient
client
=
WebClient
.
create
(
baseUrl
);
Flux
<
Animal
>
animalFlux
=
client
.
get
()
.
uri
(
"/animal"
)
.
retrieve
()
.
bodyToFlux
(
Animal
.
class
);
animalFlux
.
doOnNext
(
System
.
out
::
println
).
blockLast
();
}
}
src/main/java/com/lokesh/webclientconsumer/service/AnimalService.java
deleted
100644 → 0
View file @
348282f6
package
com
.
lokesh
.
webclientconsumer
.
service
;
import
com.lokesh.webclientconsumer.model.Animal
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
public
interface
AnimalService
{
Flux
<
Animal
>
getAnimals
();
Mono
<
Animal
>
findById
(
String
id
);
Mono
<
Animal
>
save
(
Animal
animal
);
}
src/main/java/com/lokesh/webclientconsumer/service/impl/AnimalServiceImpl.java
deleted
100644 → 0
View file @
348282f6
package
com
.
lokesh
.
webclientconsumer
.
service
.
impl
;
import
com.lokesh.webclientconsumer.model.Animal
;
import
com.lokesh.webclientconsumer.service.AnimalService
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.web.reactive.function.client.WebClient
;
import
org.springframework.web.reactive.function.client.WebClientResponseException
;
import
reactor.core.publisher.Flux
;
import
reactor.core.publisher.Mono
;
import
static
com
.
lokesh
.
webclientconsumer
.
constants
.
AnimalConstants
.*;
@Slf4j
@Service
public
class
AnimalServiceImpl
implements
AnimalService
{
private
WebClient
client
=
WebClient
.
create
(
BASE_URL
);
public
Flux
<
Animal
>
getAnimals
()
{
return
client
.
get
()
.
uri
(
GET_ALL_ANIMALS
)
.
retrieve
()
.
bodyToFlux
(
Animal
.
class
);
}
@Override
public
Mono
<
Animal
>
findById
(
String
id
)
{
try
{
return
client
.
get
()
.
uri
(
GET_ANIMAL_BYID
,
id
)
.
retrieve
()
.
bodyToMono
(
Animal
.
class
);
}
catch
(
WebClientResponseException
wcre
)
{
log
.
error
(
"Error response code is { } and response body is { }"
,
wcre
.
getRawStatusCode
(),
wcre
.
getResponseBodyAsString
());
log
.
error
(
"Exception in method retrieveAllInvoices()"
,
wcre
);
throw
wcre
;
}
catch
(
Exception
ex
)
{
log
.
error
(
"Exception find in findById() method."
);
throw
ex
;
}
}
@Override
public
Mono
<
Animal
>
save
(
Animal
animal
)
{
return
client
.
post
()
.
uri
(
"/animal"
)
.
retrieve
()
.
bodyToMono
(
Animal
.
class
);
}
}
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