@Before public void setUp() throws Exception { ContainerConfig config = new FakeContainerConfig(); uriManager = new DefaultAccelUriManager(config, new DefaultProxyUriManager( config, null)); }
private Uri makeProxiedUri(ProxyUri puc, Integer forcedRefresh, String version) { UriBuilder queryBuilder = puc.makeQueryParams(forcedRefresh, version); String container = puc.getContainer(); UriBuilder uri = new UriBuilder(); uri.setAuthority(getReqConfig(container, PROXY_HOST_PARAM)); // Chained vs. query-style syntax is determined by the presence of CHAINED_PARAMS_TOKEN String path = getReqConfig(container, PROXY_PATH_PARAM); if (path.contains(CHAINED_PARAMS_TOKEN)) { // Chained proxy syntax. Stuff query params into the path and append URI verbatim at the end path = path.replace(CHAINED_PARAMS_TOKEN, queryBuilder.getQuery()); uri.setPath(path); String uriStr = uri.toString(); String curUri = uriStr + (!uriStr.endsWith("/") ? "/" : "") + puc.getResource().toString(); return Uri.parse(curUri); } // Query-style syntax. Use path as normal and append query params at the end. queryBuilder.addQueryParameter(Param.URL.getKey(), puc.getResource().toString()); uri.setQuery(queryBuilder.getQuery()); uri.setPath(path); return uri.toUri(); }
public void verifyRefresh(boolean debug, boolean noCache, String version, Integer refresh) throws Exception { String host = "host.com"; String path = "/proxy/path"; ProxyUriManager.Versioner versioner = makeVersioner(null, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); List<ProxyUri> proxyUris = Lists.newLinkedList(); proxyUris.add(new ProxyUri(refresh, debug, noCache, CONTAINER, SPEC_URI.toString(), RESOURCE_1)); List<Uri> uris = manager.make(proxyUris, null); assertEquals(1, uris.size()); verifyQueryUriWithRefresh(RESOURCE_1, uris.get(0), debug, noCache, version, refresh, host, path); }
@Test(expected = GadgetException.class) public void mismatchedHostStrict() throws Exception { String host = "host.com"; String path = "/proxy/path"; DefaultProxyUriManager manager = makeManager("foo" + host, path, null); manager.setUseStrictParsing(true); Uri testUri = new UriBuilder().setAuthority(host).setPath(path) .addQueryParameter(Param.URL.getKey(), "http://foo.com").toUri(); manager.process(testUri); }
@Test(expected = GadgetException.class) public void missingContainerParamChained() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + "/path"; DefaultProxyUriManager manager = makeManager(host, path, null); Uri testUri = new UriBuilder().setAuthority(host).setPath( "/proxy/refresh=123/path/http://foo.com").toUri(); manager.process(testUri); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
public List<Uri> make(List<ProxyUri> resources, Integer forcedRefresh) { if (resources.isEmpty()) { return Collections.emptyList(); } List<Uri> resourceUris = Lists.newArrayListWithCapacity(resources.size()); for (ProxyUri puc : resources) { resourceUris.add(puc.getResource()); } Map<Uri, String> versions; if (versioner == null) { versions = Collections.emptyMap(); } else { versions = Maps.newHashMapWithExpectedSize(resources.size()); List<String> versionList = versioner.version(resourceUris, resources.get(0).getContainer()); if (versionList != null && versionList.size() == resources.size()) { // This should always be the case. // Should we error if not, or just WARNING? Iterator<String> versionIt = versionList.iterator(); for (ProxyUri puc : resources) { versions.put(puc.getResource(), versionIt.next()); } } } List<Uri> result = Lists.newArrayListWithCapacity(resources.size()); for (ProxyUri puc : resources) { result.add(makeProxiedUri(puc, forcedRefresh, versions.get(puc.getResource()))); } return result; }
@Test(expected = GadgetException.class) public void missingUrlChained() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + "/path"; DefaultProxyUriManager manager = makeManager(host, path, null); Uri testUri = new UriBuilder().setAuthority(host).setPath( "/proxy/container=" + CONTAINER + "/path/").toUri(); manager.process(testUri); }
@Test(expected = GadgetException.class) public void mismatchedHostStrict() throws Exception { String host = "host.com"; String path = "/proxy/path"; DefaultProxyUriManager manager = makeManager("foo" + host, path, null); manager.setUseStrictParsing(true); Uri testUri = new UriBuilder().setAuthority(host).setPath(path) .addQueryParameter(Param.URL.getKey(), "http://foo.com").toUri(); manager.process(testUri); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
public List<Uri> make(List<ProxyUri> resources, Integer forcedRefresh) { if (resources.isEmpty()) { return Collections.emptyList(); } List<Uri> resourceUris = Lists.newArrayListWithCapacity(resources.size()); for (ProxyUri puc : resources) { resourceUris.add(puc.getResource()); } Map<Uri, String> versions; if (versioner == null) { versions = Collections.emptyMap(); } else { versions = Maps.newHashMapWithExpectedSize(resources.size()); List<String> versionList = versioner.version(resourceUris, resources.get(0).getContainer()); if (versionList != null && versionList.size() == resources.size()) { // This should always be the case. // Should we error if not, or just WARNING? Iterator<String> versionIt = versionList.iterator(); for (ProxyUri puc : resources) { versions.put(puc.getResource(), versionIt.next()); } } } List<Uri> result = Lists.newArrayListWithCapacity(resources.size()); for (ProxyUri puc : resources) { result.add(makeProxiedUri(puc, forcedRefresh, versions.get(puc.getResource()))); } return result; }
@Test(expected = GadgetException.class) public void missingUrlChained() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + "/path"; DefaultProxyUriManager manager = makeManager(host, path, null); Uri testUri = new UriBuilder().setAuthority(host).setPath( "/proxy/container=" + CONTAINER + "/path/").toUri(); manager.process(testUri); }
private DefaultProxyUriManager makeManager(String host, String path, ProxyUriManager.Versioner versioner) { ContainerConfig config = createMock(ContainerConfig.class); expect(config.getString(CONTAINER, DefaultProxyUriManager.PROXY_HOST_PARAM)) .andReturn(host).anyTimes(); expect(config.getString(CONTAINER, DefaultProxyUriManager.PROXY_PATH_PARAM)) .andReturn(path).anyTimes(); replay(config); return new DefaultProxyUriManager(config, versioner); }
@Test(expected = GadgetException.class) public void mismatchedHostStrict() throws Exception { String host = "host.com"; String path = "/proxy/path"; DefaultProxyUriManager manager = makeManager("foo" + host, path, null); manager.setUseStrictParsing(true); Uri testUri = new UriBuilder().setAuthority(host).setPath(path) .addQueryParameter(Param.URL.getKey(), "http://foo.com").toUri(); manager.process(testUri); }
public void verifyRefresh(boolean debug, boolean noCache, String version, Integer refresh) throws Exception { String host = "host.com"; String path = "/proxy/path"; ProxyUriManager.Versioner versioner = makeVersioner(null, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); List<ProxyUri> proxyUris = Lists.newLinkedList(); proxyUris.add(new ProxyUri(refresh, debug, noCache, CONTAINER, SPEC_URI.toString(), RESOURCE_1)); List<Uri> uris = manager.make(proxyUris, null); assertEquals(1, uris.size()); verifyQueryUriWithRefresh(RESOURCE_1, uris.get(0), debug, noCache, version, refresh, host, path); }
private void checkValidate(String path, UriStatus status, String version) throws Exception { String host = "host.com"; // Pass null for status if version is null, since null version shouldn't result // in a check to the versioner. ProxyUriManager.Versioner versioner = makeVersioner(version == null ? null : status, version); DefaultProxyUriManager manager = makeManager(host, path, versioner); Gadget gadget = mockGadget(false, false); List<Uri> resources = ImmutableList.of(RESOURCE_1); List<Uri> uris = manager.make( ProxyUriManager.ProxyUri.fromList(gadget, resources), 123); assertEquals(1, uris.size()); ProxyUriManager.ProxyUri proxyUri = manager.process(uris.get(0)); assertEquals(RESOURCE_1, proxyUri.getResource()); assertEquals(CONTAINER, proxyUri.getContainer()); assertEquals(SPEC_URI.toString(), proxyUri.getGadget()); assertEquals(123, (int)proxyUri.getRefresh()); assertEquals(status, proxyUri.getStatus()); assertEquals(false, proxyUri.isDebug()); assertEquals(false, proxyUri.isNoCache()); }
private Uri makeProxiedUri(ProxyUri puc, Integer forcedRefresh, String version) { UriBuilder queryBuilder = puc.makeQueryParams(forcedRefresh, version); String container = puc.getContainer(); UriBuilder uri = new UriBuilder(); uri.setAuthority(getReqConfig(container, PROXY_HOST_PARAM)); // Chained vs. query-style syntax is determined by the presence of CHAINED_PARAMS_TOKEN String path = getReqConfig(container, PROXY_PATH_PARAM); if (path.contains(CHAINED_PARAMS_TOKEN)) { // Chained proxy syntax. Stuff query params into the path and append URI verbatim at the end path = path.replace(CHAINED_PARAMS_TOKEN, queryBuilder.getQuery()); uri.setPath(path); String uriStr = uri.toString(); String curUri = uriStr + (!uriStr.endsWith("/") ? "/" : "") + puc.getResource().toString(); return Uri.parse(curUri); } // Query-style syntax. Use path as normal and append query params at the end. queryBuilder.addQueryParameter(Param.URL.getKey(), puc.getResource().toString()); uri.setQuery(queryBuilder.getQuery()); uri.setPath(path); return uri.toUri(); }
result.add(makeProxiedUri(puc, forcedRefresh, versions.get(puc.getResource())));
@Test(expected = GadgetException.class) public void missingUrlChained() throws Exception { String host = "host.com"; String path = "/proxy/" + DefaultProxyUriManager.CHAINED_PARAMS_TOKEN + "/path"; DefaultProxyUriManager manager = makeManager(host, path, null); Uri testUri = new UriBuilder().setAuthority(host).setPath( "/proxy/container=" + CONTAINER + "/path/").toUri(); manager.process(testUri); }
private DefaultProxyUriManager makeManager(String host, String path, ProxyUriManager.Versioner versioner) { ContainerConfig config = createMock(ContainerConfig.class); expect(config.getString(CONTAINER, DefaultProxyUriManager.PROXY_HOST_PARAM)) .andReturn(host).anyTimes(); expect(config.getString(CONTAINER, DefaultProxyUriManager.PROXY_PATH_PARAM)) .andReturn(path).anyTimes(); replay(config); return new DefaultProxyUriManager(config, versioner); }