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

URL unsafe characters get decoded before the request is sent #2227

Closed
Breina opened this issue Nov 7, 2023 · 0 comments · Fixed by #2228
Closed

URL unsafe characters get decoded before the request is sent #2227

Breina opened this issue Nov 7, 2023 · 0 comments · Fixed by #2228

Comments

@Breina
Copy link
Contributor

Breina commented Nov 7, 2023

If using the Apache Http Client, when the path contains URL encoded unsafe characters, they get decoded while setting up the RestTemplate, causing an internal exception.

Feign config

@Configuration
public class FeignConfig {

    @Bean
    public TestClient testClient() {
        return Feign.builder()
                .client(new ApacheHttpClient(org.apache.http.impl.client.HttpClientBuilder.create().build()))
                .target(TestClient.class, "https://website.com/path");
    }
}

Client

public interface TestClient {
    @RequestLine("GET /")
    String findSomething(URI uri);
}

Usage

@Component
public class TestComponent {

    private final TestClient testClient;

    public TestComponent(TestClient testClient) {
        this.testClient = testClient;
    }

    @PostConstruct
    public void test() {
        testClient.findSomething(URI.create("https://website.com/path/text%7Ctext"));
    }
}

Result

Caused by: feign.RetryableException: URL 'https://website.com/path/text|text/' couldn't be parsed into a URI executing GET https://website.com/path/text|text/
	at feign.FeignException.errorExecuting(FeignException.java:277) ~[feign-core-12.4.jar:na]
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:110) ~[feign-core-12.4.jar:na]
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:70) ~[feign-core-12.4.jar:na]
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:96) ~[feign-core-12.4.jar:na]
	at jdk.proxy2/jdk.proxy2.$Proxy43.findSomething(Unknown Source) ~[na:na]
	at com.example.test.TestComponent.test(TestComponent.java:18) ~[classes/:na]
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:577) ~[na:na]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMethod.invoke(InitDestroyAnnotationBeanPostProcessor.java:457) ~[spring-beans-6.0.13.jar:6.0.13]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:401) ~[spring-beans-6.0.13.jar:6.0.13]
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:219) ~[spring-beans-6.0.13.jar:6.0.13]
	... 17 common frames omitted
Caused by: java.io.IOException: URL 'https://website.com/path/text|text/' couldn't be parsed into a URI
	at feign.httpclient.ApacheHttpClient.execute(ApacheHttpClient.java:79) ~[feign-httpclient-12.4.jar:na]
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:100) ~[feign-core-12.4.jar:na]
	... 26 common frames omitted
Caused by: java.net.URISyntaxException: Illegal character in path at index 29: https://website.com/path/text|text/
	at java.base/java.net.URI$Parser.fail(URI.java:2973) ~[na:na]
	at java.base/java.net.URI$Parser.checkChars(URI.java:3144) ~[na:na]
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3226) ~[na:na]
	at java.base/java.net.URI$Parser.parse(URI.java:3174) ~[na:na]
	at java.base/java.net.URI.<init>(URI.java:623) ~[na:na]
	at org.apache.http.client.utils.URIBuilder.<init>(URIBuilder.java:82) ~[httpclient-4.5.14.jar:4.5.14]
	at feign.httpclient.ApacheHttpClient.toHttpUriRequest(ApacheHttpClient.java:99) ~[feign-httpclient-12.4.jar:na]
	at feign.httpclient.ApacheHttpClient.execute(ApacheHttpClient.java:77) ~[feign-httpclient-12.4.jar:na]
	... 27 common frames omitted
Breina added a commit to Breina/feign that referenced this issue Nov 7, 2023
@velo velo closed this as completed in #2228 Nov 8, 2023
velo pushed a commit that referenced this issue Nov 8, 2023
* Do not decode URL encoding while setting up RequestTemplate (#2227)

* Add unit test for preserving URL encoding in RequestTemplate (#2227)
velo pushed a commit that referenced this issue Oct 7, 2024
* Do not decode URL encoding while setting up RequestTemplate (#2227)

* Add unit test for preserving URL encoding in RequestTemplate (#2227)
velo pushed a commit that referenced this issue Oct 8, 2024
* Do not decode URL encoding while setting up RequestTemplate (#2227)

* Add unit test for preserving URL encoding in RequestTemplate (#2227)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant