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

Path param annotated with @Encoded are not url encoded by the quarkus-rest-client-jackson anymore #40521

Closed
mrickly opened this issue May 8, 2024 · 5 comments · Fixed by #40522
Assignees
Labels
area/jackson Issues related to Jackson (JSON library) area/rest-client env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@mrickly
Copy link

mrickly commented May 8, 2024

Describe the bug

quarkus-rest-client-jackson interface:

package ch.mobi.glu.test.reproducer.rest;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.Encoded;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

@Path("/api/v4")
@ApplicationScoped
@RegisterRestClient
public interface GitLabClient {

    @GET
    @Path("/projects/{projectId}/repository/files/{filePath}/raw")
    @Produces(MediaType.TEXT_PLAIN)
    String getRawFile(@PathParam("projectId") Integer projectId, @PathParam("filePath") @Encoded String filePath);

}

Expected behavior

The filePath path param is url encoded. Still working with 3.8.4

Actual behavior

The filePath path param is not url encoded anymore. Fails since 3.9.1

How to Reproduce?

package ch.mobi.glu.reproducer.rest;

import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.junit.jupiter.api.Test;

import ch.mobi.glu.test.reproducer.rest.GitLabClient;
import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class GitLabClientTest {

    @RestClient
    GitLabClient gitLabClient;

    @Test
    public void testRawFileEndpoint() {
        gitLabClient.getRawFile(123, "src/main/resources/messages/test1_en_GB.properties");
    }

}

Output of uname -a or ver

No response

Output of java -version

openjdk 21.0.3 2024-04-16 LTS OpenJDK Runtime Environment Zulu21.34+20-SA (build 21.0.3+9-LTS) OpenJDK 64-Bit Server VM Zulu21.34+20-SA (build 21.0.3+9-LTS, mixed mode, sharing)

Quarkus version or git rev

3.9.1

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

Apache Maven 3.9.2 (c9616018c7a021c1c39be70fb2843d6f5f9b8a1c) Maven home: C:\ieu\apache-maven-3.9.2 Java version: 21.0.3, vendor: Azul Systems, Inc., runtime: C:\ieu\java\openjdk-21 Default locale: en_US, platform encoding: UTF-8 OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

Additional information

No response

@mrickly mrickly added the kind/bug Something isn't working label May 8, 2024
@quarkus-bot quarkus-bot bot added area/jackson Issues related to Jackson (JSON library) area/rest-client env/windows Impacts Windows machines labels May 8, 2024
Copy link

quarkus-bot bot commented May 8, 2024

/cc @cescoffier (rest-client), @geoand (jackson,rest-client), @gsmet (jackson)

@gastaldi gastaldi self-assigned this May 8, 2024
@mrickly
Copy link
Author

mrickly commented May 8, 2024

Removing the @Encoded annotation helps. What does the spec say?

@gastaldi
Copy link
Contributor

gastaldi commented May 8, 2024

@mrickly because your filePath expects just a single path param, you need to use {filePath:.+} if using @Encoded.

So your interface would be:

    @Path("/api/v4")
    @RegisterRestClient
    public interface GitLabClient {
        @GET
        @Path("/projects/{projectId}/repository/files/{filePath:.+}/raw")
        @Produces(MediaType.TEXT_PLAIN)
        String getRawFile(@PathParam("projectId") Integer projectId, @PathParam("filePath") @Encoded String filePath);
    }

@gastaldi
Copy link
Contributor

gastaldi commented May 8, 2024

I created a test here that shows it works properly: #40522

@mrickly
Copy link
Author

mrickly commented May 8, 2024

@gastaldi : Thank you. Adding the regex in the interface does not change the url of the GET request in 3.9.1 (or 3.9.4) though: https://somehost.example.com/api/v4/projects/123/repository/files/src/main/resources/messages/test1_en_GB.properties/raw.
But the result should be (and used to be) https://somehost.example.com/api/v4/projects/123/repository/files/src%2Fmain%2Fresources%2Fmessages%2Ftest1_en_GB.properties/raw.
Adding @Encoded used to be necessary to obtain this behaviour. Now apparently it is url encoded by default and @Encoded disables the url encoding. It is not clear to me what microprofile spec the client is conforming to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/jackson Issues related to Jackson (JSON library) area/rest-client env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants