question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

URISyntaxException with { in a param URL when using Zuul as a proxy

See original GitHub issue

I’ve a very simple backend API with a Controller like this

@RestController
@RequestMapping("/echo")
public class MyController {
    @RequestMapping(value = "", method = RequestMethod.GET)
    public String echoParam(
        @RequestParam("param") String param) {
        return param;
    }
}

When i call http://localhost:8080/echo?param={"pgach":["39469"]} all works fine (For some reason, the content of param need to be a JSON string)

Next, i create a simple EurekaServer and connect my backend to Eureka (nothing special) Then, i create a simple ZuulProxy server with this application.yml

server:
  port: 8585

zuul:
  routes:
    backend_ok:
      path: /backend_ok/**
      url: http://localhost:8080
    backend_ko:
      path: /backend_ko/**
      serviceId: backend

The first case works fine (using url) : http://localhost:8585/backend_ok/echo?param={"pgach":["39469"]}

But in the second case (using serviceId) http://localhost:8585/backend_ko/echo?param={"pgach":["39469"]}

I got this Exception

Caused by: javax.ws.rs.core.UriBuilderException: java.net.URISyntaxException: Illegal character in query at index 44: http://localhost:8080/echo?param=%7B"pgach":["39469"]%7D
    at com.sun.jersey.api.uri.UriBuilderImpl.createURI(UriBuilderImpl.java:723) ~[jersey-core-1.19.jar:1.19]
    at com.sun.jersey.api.uri.UriBuilderImpl._build(UriBuilderImpl.java:651) ~[jersey-core-1.19.jar:1.19]
    at com.sun.jersey.api.uri.UriBuilderImpl.build(UriBuilderImpl.java:641) ~[jersey-core-1.19.jar:1.19]
    at com.sun.jersey.api.client.WebResource.<init>(WebResource.java:88) ~[jersey-client-1.19.jar:1.19]
    at com.sun.jersey.api.client.WebResource.queryParam(WebResource.java:443) ~[jersey-client-1.19.jar:1.19]
    at com.netflix.niws.client.http.RestClient.execute(RestClient.java:598) ~[ribbon-httpclient-2.1.0.jar:2.1.0]
    at com.netflix.niws.client.http.RestClient.execute(RestClient.java:527) ~[ribbon-httpclient-2.1.0.jar:2.1.0]
    at com.netflix.niws.client.http.RestClient.execute(RestClient.java:92) ~[ribbon-httpclient-2.1.0.jar:2.1.0]
    at com.netflix.client.AbstractLoadBalancerAwareClient$1.call(AbstractLoadBalancerAwareClient.java:109) ~[ribbon-loadbalancer-2.1.0.jar:2.1.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:303) ~[ribbon-loadbalancer-2.1.0.jar:2.1.0]
    at com.netflix.loadbalancer.reactive.LoadBalancerCommand$3$1.call(LoadBalancerCommand.java:287) ~[ribbon-loadbalancer-2.1.0.jar:2.1.0]

I’m using SpringBoot 1.3.3 and 1.1.0.M4 of spring-cloud-netflix. I don’t know where to search. I tink the problem is with Ribbon, but not sure.

Thanks for your help

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
spencergibbcommented, May 9, 2016

Try using apache http client rather than the ribbon client.

    @Bean
    public RibbonCommandFactory<?> ribbonCommandFactory(
            final SpringClientFactory clientFactory) {
        return new HttpClientRibbonCommandFactory(clientFactory);
    }
0reactions
spencergibbcommented, Oct 5, 2016

Apache http client is now the default

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.net.URI encoding exception in Zuul gateway exception
You need to encode the { and } characters in the query portion of the URI. They should be replaced with %7B and...
Read more >
8. Router and Filter: Zuul - Spring Cloud
The proxy uses Ribbon to locate an instance to which to forward through discovery. All requests are executed in a hystrix command, so...
Read more >
Spring REST with a Zuul Proxy - Baeldung
Exploring the use of the Zuul proxy for a Spring REST API, working around CORS and the same-origin policy constraint of the browser....
Read more >
org.springframework.cloud.netflix.zuul.filters.ZuulProperties
This page shows Java code examples of org.springframework.cloud.netflix.zuul.filters.ZuulProperties.
Read more >
Spencer Gibb - spring-cloud/spring-cloud - Gitter
me: Can you use the profile naming convention for bootstrap properties ... {Internet -> Apache(Reverse Proxy) -> Zuul(Reverse Proxy) -> SpringMVC API}.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found