java.lang.IllegalArgumentException: Invalid character '[' for QUERY_PARAM in "match[]"

See original GitHub issue
2018-08-01 08:21:20.226 ERROR 1 --- [-server-epoll-7] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://xxx.com/grafana/api/datasources/proxy/1/api/v1/series?match[]=jvm_classes_loaded%7Binstance%3D%22config%3A8888%22%7D&start=1533108081&end=1533111681]

java.lang.IllegalArgumentException: Invalid character '[' for QUERY_PARAM in "match[]"
	at org.springframework.web.util.HierarchicalUriComponents.verifyUriComponent(HierarchicalUriComponents.java:417) ~[spring-web-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
	at org.springframework.web.util.HierarchicalUriComponents.lambda$verify$4(HierarchicalUriComponents.java:383) ~[spring-web-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
	at java.util.Map.forEach(Map.java:630) ~[na:1.8.0_111]
	at org.springframework.web.util.HierarchicalUriComponents.verify(HierarchicalUriComponents.java:382) ~[spring-web-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
	at org.springframework.web.util.HierarchicalUriComponents.<init>(HierarchicalUriComponents.java:152) ~[spring-web-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
	at org.springframework.web.util.UriComponentsBuilder.build(UriComponentsBuilder.java:394) ~[spring-web-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
	at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:73) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$GatewayFilterAdapter.filter(FilteringWebHandler.java:133) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
	at org.springframework.cloud.gateway.filter.OrderedGatewayFilter.filter(OrderedGatewayFilter.java:44) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.lambda$filter$0(FilteringWebHandler.java:115) ~[spring-cloud-gateway-core-2.0.1.RELEASE.jar!/:2.0.1.RELEASE]

Use gateway to forward grafana request get above error.

Seems the request http://xxx.com/grafana/api/datasources/proxy/1/api/v1/series?match[]=jvm_classes_loaded%7Binstance%3D%22config%3A8888%22%7D&start=1533108081&end=1533111681 not encoded well. But not sure if it is a gateway issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
fuvidanicommented, Aug 31, 2018

I have the same issue, just like described above. In my case the query params always contain an URL with “=” in it. The target service alone can handle these requests without any problem, the gateway unfortunately not. It’d be nice, if you could push a fix for that or provide an official workaround. 😃

3reactions
bcelenkcommented, Aug 2, 2018

Hi, I’ve come across with the same problem, where Spring’s URL handling can handle the request but gateway fails with an exception.

Example URI: http://localhost:8080/test?key=test= key

Gateway Scenario:

Caused by: java.lang.IllegalArgumentException: Invalid character '=' for QUERY_PARAM in "test=%20key"
	at org.springframework.web.util.HierarchicalUriComponents.verifyUriComponent(HierarchicalUriComponents.java:417)
	at org.springframework.web.util.HierarchicalUriComponents.lambda$verify$4(HierarchicalUriComponents.java:385)
	at java.util.Map.forEach(Map.java:630)
	at org.springframework.web.util.HierarchicalUriComponents.verify(HierarchicalUriComponents.java:382)
	at org.springframework.web.util.HierarchicalUriComponents.<init>(HierarchicalUriComponents.java:152)
	at org.springframework.web.util.UriComponentsBuilder.build(UriComponentsBuilder.java:394)
	at org.springframework.cloud.gateway.filter.RouteToRequestUrlFilter.filter(RouteToRequestUrlFilter.java:73)
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$GatewayFilterAdapter.filter(FilteringWebHandler.java:133)
	at org.springframework.cloud.gateway.filter.OrderedGatewayFilter.filter(OrderedGatewayFilter.java:44)
	at org.springframework.cloud.gateway.handler.FilteringWebHandler$DefaultGatewayFilterChain.lambda$filter$0(FilteringWebHandler.java:115)
	at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45)
	... 153 more

WebFlux raw controller scenario:

   @GetMapping("/test")
    @ResponseStatus(HttpStatus.OK)
    public Mono<String> ping(ServerWebExchange exchange){
        System.out.println(exchange.getRequest().getQueryParams());
        return Mono.just("works");
    }

results with {key=[test= key]}

In summary, raw controller handles the partial encoding by the order of "="s. However, RouteToRequestUrlFilter passes the query params to HierarchicalUriComponents as encoded because of ‘%’ in the sample URI. Since, HierarchicalUriComponents expects fully encoded parameters this.encodeState = encoded ? EncodeState.FULLY_ENCODED : EncodeState.RAW; It fails.

I think gateway should support these kind of cases to provide compatibility with Webflux, and this could happen in many situations.

For example, chrome encodes the uri http://localhost:8080/test?key=test= key as http://localhost:8080/test?key=test=%20key

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring Cloud Gateway: Invalid character '=' for QUERY_PARAM
Error: java.lang.IllegalArgumentException: Invalid character '=' for QUERY_PARAM in "scheduler.cron.expression=0%200%20*%20*%20MON,THU".
Read more >
Developers - Invalid character in query param - - Bountysource
java.lang.IllegalArgumentException: Invalid character '[' for QUERY_PARAM in "match[]" at org.springframework.web.util.HierarchicalUriComponents.
Read more >
UriBuilder (Java(TM) EE 7 Specification APIs)
java.lang. ... Builder methods perform contextual encoding of characters not permitted in the ... Throws: IllegalArgumentException - if scheme is invalid.
Read more >
UriBuilder (RESTEasy JAX-RS 2.0.1.GA API)
java.lang.IllegalArgumentException - if there are any URI template parameters without a supplied value, or if a value is null. UriBuilderException - if ...
Read more >
UriBuilder (Java(TM) EE 8 Specification APIs)
java.lang. ... Builder methods perform contextual encoding of characters not permitted in the ... Throws: IllegalArgumentException - if scheme is invalid.
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