spring-cloud-gateway: java.lang.IllegalArgumentException: Invalid character '[' for QUERY_PARAM in "match[]"
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (8 by maintainers)
Commits related to this issue
- Handle partial encoded URI. #462 — committed to wangzw/spring-cloud-gateway by wangzw 6 years ago
- Merge pull request #467 from wangzw/issue462 Handle partial encoded URI. #462 — committed to spring-cloud/spring-cloud-gateway by ryanjbaxter 5 years ago
- Only attempt to decrypt properties that are not overridden (#462) — committed to Johnny850807/spring-cloud-gateway by jaarts 5 years ago
- Revert "Only attempt to decrypt properties that are not overridden (#462)" This reverts commit 59798f52ed54766099d76f970640093954359d49. — committed to Johnny850807/spring-cloud-gateway by ryanjbaxter 5 years ago
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. 😃
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:
WebFlux raw controller scenario:
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= keyashttp://localhost:8080/test?key=test=%20key@spencergibb Would you please consider fixing this behaviour which causes inconsistencies between the gateway and the webflux ecosystem?
#467 to fix this issue, and this patch works well for me.