It is not possible for me to use the Quarkus Rest client (org.eclipse.microprofile.rest.client), because it modifies the XML under the hood and makes it invalid. In detail:
I have some XML which looks like this:
@Getter
@Setter
@ToString
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "OrderRequest")
public class OrderRequest {
@XmlElement(name="Company", defaultValue = "My Company")
private String company = "My Company";
@XmlElement(name = "Order")
private OrderType order;
}
and
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "OrderType", propOrder = {
"GetContracts"
})
@Getter
@Setter
@NoArgsConstructor
public class OrderType {
@XmlElement(name = "GetContracts")
protected GetContractsType getContracts;
}
which should build an XML in the end that looks like this...
<?xml version="1.0" encoding="UTF-8" ?>
<OrderRequest>
<Company>My Company</Company>
<Order>
<GetContracts>
<!-- more tags -->
</GetContracts>
</Order>
</OrderRequest>
Quarkus rest client definition:
@Produces(MediaType.APPLICATION_XML)
@Consumes(MediaType.APPLICATION_XML)
@RegisterProviders({
@RegisterProvider(ResponseExceptionHandler.class),
@RegisterProvider(RequestFilter.class),
@RegisterProvider(ResponseFilter.class)
})
@RegisterClientHeaders(ApiHeaderHandler.class)
// @RegisterRestClient
@RestClient
public interface ApiService {
@POST
@Path("/Order")
Object orderRequest(OrderRequest orderRequest);
}
invocation....
ApiService apiService = org.eclipse.microprofile.rest.client.RestClientBuilder.newBuilder()
.baseUri(URI.create(url))
.connectTimeout(10, TimeUnit.SECONDS)
.build(ApiService.class);
apiService.orderRequest(orderRequest); //build via Java with the classes above
The invocation works, because I get a response from the target api which says XML invalid: The element 'Order' has invalid child element 'getContracts'.
This means that anywhere under the hood this rest client makes probably some strange reflection thing, because it modifies the XML types itself! First of all, I thought it takes the getter method, so I changed getContracts to GetContracts, but no effect. Then I thought that "Get" confuses the framework, so it could lead to some strange reflection behaviour, so I renamed it to "FooContracts" to narrow the problem down. But then, the error messages says XML invalid: The element 'Order' has invalid child element 'fooContracts', so it is no a problem with "get", because it even makes "Foo" to lowercase!
I made some tests with Postman to match the responses and indeed, I get the same error in Postman when I send this XML with lowercase getContracts...
<?xml version="1.0" encoding="UTF-8" ?>
<OrderRequest>
<Company>My Company</Company>
<Order>
<getContracts>
<!-- more tags -->
</getContracts>
</Order>
</OrderRequest>
XML invalid: The element 'Order' has invalid child element 'getContracts'.
So it is clear, this Quarkus Rest client or something else under the hood damages the XML by making elements lowercase. Any ideas what I can do now?