Reputation: 73
I need to convert my soap based application into rest based quarkus application.
I need a quarkus rest service to take below request and generate response.
Request :
<sum>
<a>5</a>
<b>5</b>
</sum>
Response :
<result>10</result>
Any pointers !!
Upvotes: 1
Views: 7612
Reputation: 31
You need to add quarkus-resteasy-jaxb
and quarkus-resteasy
dependency in your pom.xml
file:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
Then create a simple model class, but remember the @XmlRootElement
annotation:
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;
}
And then expose the model via a REST service:
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;
}
}
Now as long as you set the Accepts application/xml
header this Quarkus rest controller will return a XML response like this:
<?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>
Upvotes: 3
Reputation: 12728
Add this:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jaxb</artifactId>
<version>1.13.7.Final</version>
</dependency>
and this:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-mutiny</artifactId>
</dependency>
They will make it possible for you to return Uni<> in XML.
Upvotes: 0
Reputation: 12817
You can simply use a soap library (e.g Apache CXF) and parse the XML. There will be no particular Quarkus integration, and you will probably have a hard time producing a native image.
Upvotes: 0