@Test public void shouldBuildURLWithQueryParametersHavingSpecialCharacters() throws Exception { ViewContext context = createNiceMock(ViewContext.class); ProxyHelper helper = new ProxyHelper(context); MultivaluedMap<String, String> map = new MultivaluedHashMap<>(); map.putSingle("data", "abcd/efgh"); assertEquals("http: map.putSingle("data", "abcd efgh"); assertEquals("http: }
public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType) { Set<String> keySet = queryParameters.keySet(); URIBuilder builder; try { builder = new URIBuilder(baseUrl + "/" + endPoint); for(String key: keySet) { builder.addParameter(key, queryParameters.getFirst(key)); } if(authType == null || authType.equalsIgnoreCase("simple")) { builder.addParameter("user.name", viewContext.getUsername()); } return builder.build().toString(); } catch (URISyntaxException e) { LOG.error("Failed to build a URL from the baseUrl: {} and endPoint: {}. Exception: {}", baseUrl, endPoint, e); throw new TezWebAppException("Failed to build a URL from the baseUrl:" + baseUrl + "and endPoint: " + endPoint, e); } }
ProxyHelper { public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType) { Set<String> keySet = queryParameters.keySet(); URIBuilder builder; try { builder = new URIBuilder(baseUrl + "/" + endPoint); for(String key: keySet) { builder.addParameter(key, queryParameters.getFirst(key)); } if(authType == null || authType.equalsIgnoreCase("simple")) { builder.addParameter("user.name", viewContext.getUsername()); } return builder.build().toString(); } catch (URISyntaxException e) { LOG.error("Failed to build a URL from the baseUrl: {} and endPoint: {}. Exception: {}", baseUrl, endPoint, e); throw new TezWebAppException("Failed to build a URL from the baseUrl:" + baseUrl + "and endPoint: " + endPoint, e); } } }
ProxyHelper { public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType) { Set<String> keySet = queryParameters.keySet(); URIBuilder builder; try { builder = new URIBuilder(baseUrl + "/" + endPoint); for(String key: keySet) { builder.addParameter(key, queryParameters.getFirst(key)); } if(authType == null || authType.equalsIgnoreCase("simple")) { builder.addParameter("user.name", viewContext.getUsername()); } return builder.build().toString(); } catch (URISyntaxException e) { LOG.error("Failed to build a URL from the baseUrl: {} and endPoint: {}. Exception: {}", baseUrl, endPoint, e); throw new TezWebAppException("Failed to build a URL from the baseUrl:" + baseUrl + "and endPoint: " + endPoint, e); } } @Inject  ProxyHelper(ViewContext viewContext); }
ProxyHelper { public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType) { Set<String> keySet = queryParameters.keySet(); URIBuilder builder; try { builder = new URIBuilder(baseUrl + "/" + endPoint); for(String key: keySet) { builder.addParameter(key, queryParameters.getFirst(key)); } if(authType == null || authType.equalsIgnoreCase("simple")) { builder.addParameter("user.name", viewContext.getUsername()); } return builder.build().toString(); } catch (URISyntaxException e) { LOG.error("Failed to build a URL from the baseUrl: {} and endPoint: {}. Exception: {}", baseUrl, endPoint, e); throw new TezWebAppException("Failed to build a URL from the baseUrl:" + baseUrl + "and endPoint: " + endPoint, e); } } @Inject  ProxyHelper(ViewContext viewContext); String getResponse(String url, Map<String, String> headers, String authType); String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType); }
ProxyHelper { public String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType) { Set<String> keySet = queryParameters.keySet(); URIBuilder builder; try { builder = new URIBuilder(baseUrl + "/" + endPoint); for(String key: keySet) { builder.addParameter(key, queryParameters.getFirst(key)); } if(authType == null || authType.equalsIgnoreCase("simple")) { builder.addParameter("user.name", viewContext.getUsername()); } return builder.build().toString(); } catch (URISyntaxException e) { LOG.error("Failed to build a URL from the baseUrl: {} and endPoint: {}. Exception: {}", baseUrl, endPoint, e); throw new TezWebAppException("Failed to build a URL from the baseUrl:" + baseUrl + "and endPoint: " + endPoint, e); } } @Inject  ProxyHelper(ViewContext viewContext); String getResponse(String url, Map<String, String> headers, String authType); String getProxyUrl(String baseUrl, String endPoint, MultivaluedMap<String, String> queryParameters, String authType);  }