我不知道 Quarkus 是否支持 XML(反)序列化,而响应是反应类型(Uni/Multi)。我使用了 Spring Reactor,在 Reactor 中,响应应该始终是 Mono/Flux,以使整个管道无阻塞,从请求到客户端再到最终响应。这是正确的方法吗?我只看到返回 int/String/List 的示例,从来没有看到 Uni/Multi 作为响应。
我已经稍微修改了官方示例以检查这是可能的,但我没有得到正确的响应。
@Inject
private PrimeService primeService;
@GET
@Path("/{number}")
@Timed
@Produces(MediaType.APPLICATION_XML)
public Uni<OutputDto> checkIfPrime(@PathParam long number) {
return primeService.checkPrime(number);
}
我的服务:
@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.";
}
}
当我查询 likecurl -X GET http://localhost:8080/45646546546541
时,我看到:
Could not find MessageBodyWriter for response object of type: io.smallrye.mutiny.operators.uni.UniOnItemTransform of media type: application/xml;charset=UTF-8
我有io.quarkus:quarkus-resteasy-jaxb
我的依赖项。
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
<version>1.13.7.Final</version>
</dependency>
我想要:
- 通过配置属性配置 XML 解析器功能
- 能够将 Uni/Multi 转换为 XML