I don't know if Quarkus support XML (de)serialization while the response is reactive type(Uni/Multi). I used Spring Reactor and in Reactor, the response should always be Mono/Flux to make the whole pipeline non-blocking, from request to client and to the final response. Is this the proper way? I only see examples of returning int/String/List, never Uni/Multi in response.
I have modified the official example a little bit to check this is possible, but I don't get proper response.
@Inject
private PrimeService primeService;
@GET
@Path("/{number}")
@Timed
@Produces(MediaType.APPLICATION_XML)
public Uni<OutputDto> checkIfPrime(@PathParam long number) {
return primeService.checkPrime(number);
}
My service:
@ApplicationScoped
public class PrimeService {
private long highestPrimeNumberSoFar = 2;
Uni<OutputDto> checkPrime(long number) {
return Uni.createFrom().item(number)
.map(this::calculate)
.map(message -> new OutputDto(message, LocalDate.now()));
}
private String calculate(long number) {
if (number < 1) {
return "Only natural numbers can be prime numbers.";
}
if (number == 1) {
return "1 is not prime.";
}
if (number == 2) {
return "2 is prime.";
}
if (number % 2 == 0) {
return number + " is not prime, it is divisible by 2.";
}
for (int i = 3; i < Math.floor(Math.sqrt(number)) + 1; i = i + 2) {
if (number % i == 0) {
return number + " is not prime, is divisible by " + i + ".";
}
}
if (number > highestPrimeNumberSoFar) {
highestPrimeNumberSoFar = number;
}
return number + " is prime.";
}
}
When I query like curl -X GET http://localhost:8080/45646546546541
, I see:
Could not find MessageBodyWriter for response object of type: io.smallrye.mutiny.operators.uni.UniOnItemTransform of media type: application/xml;charset=UTF-8
I have io.quarkus:quarkus-resteasy-jaxb
in my dependencies.
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
<version>1.13.7.Final</version>
</dependency>
I want to:
Well, I just find that apart from quarkus-resteasy-jaxb
, I need to add this dependency:
<dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-resteasy-mutiny</artifactId> </dependency>
And I see XML response while returning Uni<OutputDto>
.
So jaxb does the serialization and resteasy-mutiny does the conversion.
No, according to the doc, it is not recommended. Check comment to see a proper solution.