public List<Uri> make(List<ProxyUri> ctx, Integer forcedRefresh) { // Just wraps the original ProxyUriManager and adds a few query params. for (ProxyUri proxyUri : ctx) { proxyUri.setSanitizeContent(true); if (expectedMime != null) { proxyUri.setRewriteMimeType(expectedMime); } } return wrapped.make(ctx, forcedRefresh); } }
public Uri make(ProxyUriManager.ProxyUri uri, Uri context) { if (config.shouldRewriteURL(uri.getResource().toString())) { List<ProxyUriManager.ProxyUri> puris = Lists.newArrayList(uri); List<Uri> returned = wrapped.make(puris, null); return returned.get(0); } return context.resolve(uri.getResource()); } }
public Uri make(ProxyUriManager.ProxyUri uri, Uri context) { if (config.shouldRewriteURL(uri.getResource().toString())) { List<ProxyUriManager.ProxyUri> puris = Lists.newArrayList(uri); List<Uri> returned = wrapped.make(puris, null); return returned.get(0); } return context.resolve(uri.getResource()); } }
public Uri make(ProxyUriManager.ProxyUri uri, Uri context) { if (config.shouldRewriteURL(uri.getResource().toString())) { List<ProxyUriManager.ProxyUri> puris = Lists.newArrayList(uri); List<Uri> returned = wrapped.make(puris, null); return returned.get(0); } return context.resolve(uri.getResource()); } }
public List<Uri> make(List<ProxyUri> ctx, Integer forcedRefresh) { // Just wraps the original ProxyUriManager and adds a few query params. List<Uri> origUris = wrapped.make(ctx, forcedRefresh); List<Uri> sanitizedUris = Lists.newArrayListWithCapacity(origUris.size()); for (Uri origUri : origUris) { UriBuilder newUri = new UriBuilder(origUri); newUri.addQueryParameter(Param.SANITIZE.getKey(), "1"); if (expectedMime != null) { newUri.addQueryParameter(Param.REWRITE_MIME_TYPE.getKey(), expectedMime); } sanitizedUris.add(newUri.toUri()); } return sanitizedUris; } }
public List<Uri> make(List<ProxyUri> ctx, Integer forcedRefresh) { // Just wraps the original ProxyUriManager and adds a few query params. List<Uri> origUris = wrapped.make(ctx, forcedRefresh); List<Uri> sanitizedUris = Lists.newArrayListWithCapacity(origUris.size()); for (Uri origUri : origUris) { UriBuilder newUri = new UriBuilder(origUri); newUri.addQueryParameter(Param.SANITIZE.getKey(), "1"); if (expectedMime != null) { newUri.addQueryParameter(Param.REWRITE_MIME_TYPE.getKey(), expectedMime); } sanitizedUris.add(newUri.toUri()); } return sanitizedUris; } }
public Uri parseAndNormalize(HttpRequest httpRequest) throws GadgetException { Gadget gadget = DomWalker.makeGadget(httpRequest); ProxyUriManager.ProxyUri proxied = looksLikeAccelUri(httpRequest.getUri()) ? proxyUriManager.process(httpRequest.getUri()) : new ProxyUriManager.ProxyUri( gadget, httpRequest.getUri()); return proxyUriManager.make(ImmutableList.of(proxied), 0).get(0); }
public Uri parseAndNormalize(HttpRequest httpRequest) throws GadgetException { Gadget gadget = DomWalker.makeGadget(httpRequest); ProxyUriManager.ProxyUri proxied = looksLikeAccelUri(httpRequest.getUri()) ? proxyUriManager.process(httpRequest.getUri()) : new ProxyUriManager.ProxyUri( gadget, httpRequest.getUri()); return proxyUriManager.make(ImmutableList.of(proxied), 0).get(0); }
public Uri parseAndNormalize(HttpRequest httpRequest) throws GadgetException { // Make a gadget object with the accel container. Gadget gadget = DomWalker.makeGadget(httpRequest); gadget.setContext(new GadgetContext(gadget.getContext()) { @Override public String getContainer() { return AccelUriManager.CONTAINER; } }); // Normalize the request url to proxy uri form. ProxyUriManager.ProxyUri proxied = looksLikeAccelUri(httpRequest.getUri()) ? proxyUriManager.process(httpRequest.getUri()) : new ProxyUriManager.ProxyUri( gadget, httpRequest.getUri()); return proxyUriManager.make(ImmutableList.of(proxied), 0).get(0); }
@Test public void makeSingleNoMime() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); List<ProxyUri> input = Lists.newArrayList(proxyUri); List<Uri> output = Lists.newArrayList(uri); Integer refresh = new Integer(0); expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); expect(proxyUri.setSanitizeContent(true)).andReturn(proxyUri).once(); replay(proxyUri); SanitizingProxyUriManager rewriter = makeRewriter(null); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(1, returned.size()); verify(proxyUri); }
@Test public void makeSingleNoMime() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); List<ProxyUri> input = Lists.newArrayList(proxyUri); List<Uri> output = Lists.newArrayList(uri); Integer refresh = new Integer(0); expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); expect(proxyUri.setSanitizeContent(true)).andReturn(proxyUri).once(); replay(proxyUri); SanitizingProxyUriManager rewriter = makeRewriter(null); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(1, returned.size()); verify(proxyUri); }
@Test(expected = ProcessingException.class) public void testGetProxyDataFail() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); new HttpResponse("response"); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andThrow( new GadgetException(Code.FAILED_TO_RETRIEVE_CONTENT)); replay(); gadgetHandler.getProxy(request); }
@Test(expected = ProcessingException.class) public void testGetProxyDataFail() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); new HttpResponse("response"); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andThrow( new GadgetException(Code.FAILED_TO_RETRIEVE_CONTENT)); replay(); gadgetHandler.getProxy(request); }
@Test public void makeSingleNoMime() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); List<ProxyUri> input = Lists.newArrayList(proxyUri); List<Uri> output = Lists.newArrayList(uri); Integer refresh = new Integer(0); expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); SanitizingProxyUriManager rewriter = makeRewriter(null); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(1, returned.size()); assertEquals("1", returned.get(0).getQueryParameter(Param.SANITIZE.getKey())); assertNull(returned.get(0).getQueryParameter(Param.REWRITE_MIME_TYPE.getKey())); }
@Test public void testUrlRewrite() throws Exception { String uri = "http://www.example.com/"; String unproxied = uri; String proxied = "http://shindig.com/gadgets/proxy?url=" + uri; expect(proxyUriManager.make(EasyMock.anyObject(List.class), EasyMock.isNull(Integer.class))) .andReturn(ImmutableList.<Uri>of(Uri.parse(proxied))).anyTimes(); replay(proxyUriManager); // Uris that transistion the page assertUrlRewritten("a", "href", uri, unproxied); assertUrlRewritten("area", "href", uri, unproxied); // Uris that load media assertUrlRewritten("img", "src", uri, proxied); // Uris that have no effect on the document assertUrlRewritten("blockquote", "cite", uri, unproxied); assertUrlRewritten("q", "cite", uri, unproxied); assertUrlRewritten("del", "cite", uri, unproxied); assertUrlRewritten("ins", "cite", uri, unproxied); }
@Test public void testUrlRewrite() throws Exception { String uri = "http://www.example.com/"; String unproxied = uri; String proxied = "http://shindig.com/gadgets/proxy?url=" + uri; expect(proxyUriManager.make(EasyMock.anyObject(List.class), EasyMock.isNull(Integer.class))) .andReturn(ImmutableList.<Uri>of(Uri.parse(proxied))).anyTimes(); replay(proxyUriManager); // Uris that transistion the page assertUrlRewritten("a", "href", uri, unproxied); assertUrlRewritten("area", "href", uri, unproxied); // Uris that load media assertUrlRewritten("img", "src", uri, proxied); // Uris that have no effect on the document assertUrlRewritten("blockquote", "cite", uri, unproxied); assertUrlRewritten("q", "cite", uri, unproxied); assertUrlRewritten("del", "cite", uri, unproxied); assertUrlRewritten("ins", "cite", uri, unproxied); }
@Test public void testGetProxySimple() throws Exception { List<String> fields = ImmutableList.of("proxyurl"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertEquals(resUri, response.getProxyUrl()); assertNull(response.getProxyContent()); assertEquals(timeSource.currentTimeMillis() + HttpUtil.getDefaultTtl() * 1000, response .getExpireTimeMs().longValue()); verify(); }
@Test public void testGetProxySimple() throws Exception { List<String> fields = ImmutableList.of("proxyurl"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertEquals(resUri, response.getProxyUrl()); assertNull(response.getProxyContent()); assertEquals(timeSource.currentTimeMillis() + HttpUtil.getDefaultTtl() * 1000, response .getExpireTimeMs().longValue()); verify(); }
@Test public void testGetProxyEmptyData() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); HttpResponse httpResponse = new HttpResponseBuilder().setHttpStatusCode(504).create(); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andReturn(httpResponse); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertNull(response.getProxyUrl()); assertEquals("", response.getProxyContent().getContentBase64()); assertEquals(504, response.getProxyContent().getCode()); verify(); }
@Test public void testGetProxyEmptyData() throws Exception { List<String> fields = ImmutableList.of("proxycontent.*"); Uri resUri = Uri.parse("server.com/gadgets/proxy?url=" + RESOURCE); GadgetsHandlerApi.ProxyRequest request = createProxyRequest(RESOURCE, CONTAINER, fields); Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); expect(proxyUriManager.make(capture(uriCapture), EasyMock.anyInt())).andReturn( ImmutableList.of(resUri)); HttpResponse httpResponse = new HttpResponseBuilder().setHttpStatusCode(504).create(); expect(proxyHandler.fetch(EasyMock.isA(ProxyUri.class))).andReturn(httpResponse); replay(); GadgetsHandlerApi.ProxyResponse response = gadgetHandler.getProxy(request); assertEquals(1, uriCapture.getValue().size()); ProxyUri pUri = uriCapture.getValue().get(0); assertEquals(CONTAINER, pUri.getContainer()); assertNull(response.getProxyUrl()); assertEquals("", response.getProxyContent().getContentBase64()); assertEquals(504, response.getProxyContent().getCode()); verify(); }