Spring-cloud-netflix: URISyntaxException with { in a param URL when using Zuul as a proxy

Created on 19 Mar 2016  路  13Comments  路  Source: spring-cloud/spring-cloud-netflix

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

Most helpful comment

Try using apache http client rather than the ribbon client.

    @Bean
    public RibbonCommandFactory<?> ribbonCommandFactory(
            final SpringClientFactory clientFactory) {
        return new HttpClientRibbonCommandFactory(clientFactory);
    }

All 13 comments

Maybe something with commit 41c3640

Sorry @spencergibb but, i've try with 1.1.0-BUILD-SNAPSHOT (18/03/2016 11:58:28),
and i always have the same problem :(

I think the problem appear only with { caracter. Maybe due to usage or URITemplate.

@dacofr does it work urlencoded? %7B%22pgach%22%3A%5B%2239469%22%5D%7D.

No, always the same problem :(

URISyntaxException: Illegal character in query at index 44: http://localhost:8080/echo?param=%7B"pgach":["39469"]%7D

Hi @spencergibb any news about this issue ?
Thanks for your response.

no news.

Same problem here. @spencergibb I think it is related to Jersey. See here for more information https://java.net/jira/si/jira.issueviews:issue-html/JERSEY-2525/JERSEY-2525.html. However, I have no idea how we can resolve this.

Hi, any chance to see this issue resolved ?

Thanks

Try using apache http client rather than the ribbon client.

    @Bean
    public RibbonCommandFactory<?> ribbonCommandFactory(
            final SpringClientFactory clientFactory) {
        return new HttpClientRibbonCommandFactory(clientFactory);
    }

Thanks, Work's fine with HttpClient.
Any difference (speed, latency, ...) between RibonnClient and HttpClient ?

I don't know. It's really the difference between JerseyClient (which ribbon client uses) and apache httpclient.

That should be documented and possibly auto configured. It should possibly be the default. @dsyer thoughts?

Apache http client is now the default

Was this page helpful?
0 / 5 - 0 ratings