Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media type text/xml not working with REST Client Reactive #25884

Closed
wjglerum opened this issue May 31, 2022 · 3 comments · Fixed by #25888
Closed

Media type text/xml not working with REST Client Reactive #25884

wjglerum opened this issue May 31, 2022 · 3 comments · Fixed by #25888
Labels
area/rest-client kind/bug Something isn't working
Milestone

Comments

@wjglerum
Copy link
Contributor

wjglerum commented May 31, 2022

Describe the bug

I tried updating our project to use the REST Client Reactive from RESTEasy Reactive, however I can't get it to work with one of our REST Clients that uses text/xml. It does work fine for others that use JSON for example.

Expected behavior

The XML in the body of the response gets successfully processed with both media type text/xml and application/xml.

Actual behavior

The REST client fails with an exception when using text/xml

javax.ws.rs.ProcessingException: Response could not be mapped to type class org.acme.SimpleJaxbTest$Dto

	at org.jboss.resteasy.reactive.client.impl.ClientReaderInterceptorContextImpl.proceed(ClientReaderInterceptorContextImpl.java:62)
	at org.jboss.resteasy.reactive.client.impl.ClientSerialisers.invokeClientReader(ClientSerialisers.java:146)
	at org.jboss.resteasy.reactive.client.impl.RestClientRequestContext.readEntity(RestClientRequestContext.java:182)
	at org.jboss.resteasy.reactive.client.handlers.ClientResponseCompleteRestHandler.mapToResponse(ClientResponseCompleteRestHandler.java:101)
	at org.jboss.resteasy.reactive.client.handlers.ClientResponseCompleteRestHandler.handle(ClientResponseCompleteRestHandler.java:32)
	at org.jboss.resteasy.reactive.client.handlers.ClientResponseCompleteRestHandler.handle(ClientResponseCompleteRestHandler.java:28)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.invokeHandler(AbstractResteasyReactiveContext.java:219)
	at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:141)
	at org.jboss.resteasy.reactive.client.impl.RestClientRequestContext$1.lambda$execute$0(RestClientRequestContext.java:276)
	at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:100)
	at io.vertx.core.impl.AbstractContext.dispatch(AbstractContext.java:63)
	at io.vertx.core.impl.EventLoopContext.lambda$runOnContext$0(EventLoopContext.java:38)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:469)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:833)

It does work fine when you create an endpoint that uses application/xml or when you switch back to the REST Client from RESTEasy Classic with JAXB.

How to Reproduce?

Based on the tests I found here: https://github.com/quarkusio/quarkus/blob/main/extensions/resteasy-reactive/rest-client-reactive-jaxb/deployment/src/test/java/io/quarkus/rest/client/reactive/jaxb/test/SimpleJaxbTest.java
I made a small reproducer:

package org.acme;

import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import org.eclipse.microprofile.rest.client.RestClientBuilder;
import org.junit.jupiter.api.Test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URI;
import java.util.Objects;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

@QuarkusTest
public class SimpleJaxbTest {

    @TestHTTPResource
    URI uri;

    @Test
    void shouldConsumeXMLEntity() {
        var dto = RestClientBuilder.newBuilder().baseUri(uri).build(XmlClient.class).dto();
        assertThat(dto, equalTo(new Dto("foo", "bar")));
    }

    @Path("/xml")
    public interface XmlClient {

        @GET
        @Path("/dto")
        @Produces(MediaType.TEXT_XML)
        Dto dto();
    }

    @Path("/xml")
    public static class XmlResource {

        @GET
        @Produces(MediaType.TEXT_XML)
        @Path("/dto")
        public Dto dto() {
            return new Dto("foo", "bar");
        }
    }

    @XmlRootElement(name = "Dto")
    public static class Dto {
        public String name;
        public String value;

        public Dto(String name, String value) {
            this.name = name;
            this.value = value;
        }

        public Dto() {
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;
            Dto dto = (Dto) o;
            return Objects.equals(name, dto.name) && Objects.equals(value, dto.value);
        }

        @Override
        public int hashCode() {
            return Objects.hash(name, value);
        }
    }
}

Extensions used:

    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-rest-client-reactive-jaxb</artifactId>
    </dependency>
    <dependency>
      <groupId>io.quarkus</groupId>
      <artifactId>quarkus-resteasy-reactive-jaxb</artifactId>
    </dependency>

Reproducer: Archive.zip

Output of uname -a or ver

Darwin Willems-MBP.i.btp34.nl 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

Output of java -version

openjdk version "17.0.3" 2022-04-19 OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7) OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.9.2.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: /Users/wjglerum/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4 Java version: 17.0.3, vendor: Eclipse Adoptium, runtime: /Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home Default locale: en_NL, platform encoding: US-ASCII OS name: "mac os x", version: "12.4", arch: "x86_64", family: "mac"

Additional information

Did I miss any documentation here? Or is there something else needed to make this work?

@wjglerum wjglerum added the kind/bug Something isn't working label May 31, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented May 31, 2022

/cc @michalszynkiewicz

@wjglerum
Copy link
Contributor Author

wjglerum commented May 31, 2022

Did some digging myself and found that the JAXB message body writers and readers were only set up for application/xml and not for text/xml. Created a PR to add those and validated it against my own local project which seems to be working now.

@wjglerum wjglerum changed the title MediaType TEXT_XML not working with REST Client Reactive Media type text/xml not working with REST Client Reactive May 31, 2022
@wjglerum
Copy link
Contributor Author

It also seemed to fail for RESTEasy Reactive endpoints with text/xml

image

@quarkus-bot quarkus-bot bot added this to the 2.10 - main milestone Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant