Hello Divya, Looking at the URL you posted looks like you are using the wrong dispatch class, URLDecodingDispatch is used for URLs that are already encoded, looking at your example URL it looks like it is partially encoded (e.g. the query params &), in-fact looks like it is not properly encoded.
What error are you getting in gateway.log corresponding to 400 (Bad Request) ? Best, Sandeep On Thu, Aug 16, 2018 at 6:06 AM Divya Narayan <divya.nara...@guavus.com> wrote: > Hi , > > I tried to integrate grafana UI with knox gateway. I used > URLDecodingDispatch class but there were some calls which were failing like: > > > *http://platacc002-mgt-01.gvs.ggn:3000/api/datasources/proxy/1/ws/v1/timeline/metrics?metricNames=dfs.NNTopUserOpCounts.windowMs=1500000.op=__%.user=%&hostname=%25&appId=namenode&startTime=1534390641&endTime=1534401441* > > > The above call on grafana UI failed with below error: > > *Caused by: java.lang.IllegalArgumentException: Malformed escape pair at > index > 141: > http://platacc002-mgt-01.gvs.ggn:3000/api/datasources/proxy/1/ws/v1/timeline/metrics?metricNames=dfs.NNTopUserOpCounts.windowMs=1500000.op=__%.user=%&hostname=%25&appId=namenode&startTime=1534390641&endTime=1534401441* > *at java.net.URI.create(URI.java:852)* > *at > knoxdisp.URLDecodingDispatch.getDispatchUrl(URLDecodingDispatch.java:49)* > *at > org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter$GetAdapter.doMethod(GatewayDispatchFilter.java:132)* > *at > org.apache.hadoop.gateway.dispatch.GatewayDispatchFilter.doFilter(GatewayDispatchFilter.java:115)* > *at org.apache.ha* > *doop.gateway.filter.AbstractGatewayFilter.doFilter(AbstractGatewayFilter.java:61)* > *... 76 more* > > > Now instead of making rewrite rules for each of such URL, I decided to > change the dispatcher class itself to handle requests with special > characters. In dispatcher class I added URL encoding to encode all the > special characters. > Below is the code that I tried: > > @Override > > public URI getDispatchUrl(final HttpServletRequest request) { > > String decoded; > > String encodedURL = null; > > > try { > > decoded = URLDecoder.decode(request.getRequestURL().toString(), > "UTF-8" ); > > } catch (final Exception e) { > > /* fall back in case of exception */ > > decoded = request.getRequestURL().toString(); > > } > > > final StringBuffer str = new StringBuffer(decoded); > > final String query = request.getQueryString(); > > if ( query != null ) { > > try { > > encodedURL = URLEncoder.encode(query,"UTF-8"); > > } catch (UnsupportedEncodingException e) { > > e.printStackTrace(); > > } > > > str.append('?'); > > str.append(encodedURL); > > > > } > > final URI url = URI.create(str.toString()); > > return url; > > } > > } > > > > Now after making these changes, malformed error is resolved and all URLs > gets encoded like : > > > *Dispatch request: GET > http://platacc002-mgt-01.gvs.ggn:3000/api/datasources/proxy/1/ws/v1/timeline/metrics?metricNames%3Ddfs.NNTopUserOpCounts.windowMs%3D1500000.op%3D__%25.user%3D%25%26hostname%3D%2525%26appId%3Dnamenode%26startTime%3D1534400120%26endTime%3D1534410920 > <http://platacc002-mgt-01.gvs.ggn:3000/api/datasources/proxy/1/ws/v1/timeline/metrics?metricNames%3Ddfs.NNTopUserOpCounts.windowMs%3D1500000.op%3D__%25.user%3D%25%26hostname%3D%2525%26appId%3Dnamenode%26startTime%3D1534400120%26endTime%3D1534410920>* > > > > But the calls still doesn’t work. It throws HTTP Error code: 400 (Bad > Request). Can anyone help me to resolve these calls. > > > > Thanks > > Divya > >