我需要将基于soap的应用程序转换为基于rest的夸克应用程序。
我需要一个夸克rest服务来接受以下请求并生成响应。
请求:
<sum>
<a>5</a>
<b>5</b>
</sum> 响应:
<result>10</result>任何指示!!
发布于 2020-09-25 14:58:16
您可以简单地使用soap库(例如Apache)并解析该XML。没有特定的Quarkus集成,您可能很难生成本地映像。
发布于 2021-10-22 12:07:41
您需要将quarkus-resteasy-jaxb和quarkus-resteasy依赖项添加到pom.xml文件中:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>然后创建一个简单的模型类,但请记住@XmlRootElement注释:
package com.example;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Fruit {
public Fruit() {
}
public Fruit(String name, String description) {
this.name = name;
this.description = description;
}
public String name;
public String description;
}然后通过REST服务公开模型:
package com.example.controller;
import com.example.Fruit;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
@Path("/fruit")
public class FruitRestController {
@GET
@Produces(value = MediaType.APPLICATION_XML)
public List<Fruit> getFruit() {
List<Fruit> fruitList = new ArrayList<>();
fruitList.add(new Fruit("Apple", "Crunchy fruit"));
fruitList.add(new Fruit("Kiwi", "Delicious fruit"));
return fruitList;
}
}现在,只要您设置了XML,Quarkus控制器就会返回这样的Accepts application/xml响应:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<collection>
<fruit>
<name>Apple</name>
<description>Crunchy fruit</description>
</fruit>
<fruit>
<name>Kiwi</name>
<description>Delicious fruit</description>
</fruit>
</collection>发布于 2021-06-18 07:45:30
添加以下内容:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
<version>1.13.7.Final</version>
</dependency>这是:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>它们将使您能够用XML返回Uni<>。
https://stackoverflow.com/questions/64064734
复制相似问题