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); }
@Test public void testContainersChange() throws Exception { String beforeUrl = "//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"; String afterUrl = "//apache.org/random/url?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"; Uri uri = Uri.parse("http://www.example.org/index.html"); HttpRequest req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse(beforeUrl), uriManager.parseAndNormalize(req)); assertTrue(uriManager.looksLikeAccelUri(Uri.parse(beforeUrl))); assertFalse(uriManager.looksLikeAccelUri(Uri.parse(afterUrl))); config.newTransaction().addContainer(makeConfig("accel", "/random/url")).commit(); uri = Uri.parse("http://www.example.org/index.html"); req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse(afterUrl), uriManager.parseAndNormalize(req)); assertFalse(uriManager.looksLikeAccelUri(Uri.parse(beforeUrl))); assertTrue(uriManager.looksLikeAccelUri(Uri.parse(afterUrl))); } }
@Test public void testParseAndNormalizeAccelUri() throws Exception { Uri uri = Uri.parse("http://apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"); HttpRequest req = new HttpRequest(uri); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&debug=0&nocache=0&refresh=0" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); }
@Before public void setUp() throws Exception { ContainerConfig config = new FakeContainerConfig(); uriManager = new DefaultAccelUriManager(config, new DefaultProxyUriManager( config, null)); }
@Test public void testContainersChange() throws Exception { String beforeUrl = "//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"; String afterUrl = "//apache.org/random/url?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"; Uri uri = Uri.parse("http://www.example.org/index.html"); HttpRequest req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse(beforeUrl), uriManager.parseAndNormalize(req)); assertTrue(uriManager.looksLikeAccelUri(Uri.parse(beforeUrl))); assertFalse(uriManager.looksLikeAccelUri(Uri.parse(afterUrl))); config.newTransaction().addContainer(makeConfig("accel", "/random/url")).commit(); uri = Uri.parse("http://www.example.org/index.html"); req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse(afterUrl), uriManager.parseAndNormalize(req)); assertFalse(uriManager.looksLikeAccelUri(Uri.parse(beforeUrl))); assertTrue(uriManager.looksLikeAccelUri(Uri.parse(afterUrl))); } }
@Test public void testParseAndNormalizeAccelUri() throws Exception { Uri uri = Uri.parse("http://apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"); HttpRequest req = new HttpRequest(uri); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&debug=0&nocache=0&refresh=0" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); }
@Before public void setUp() throws Exception { ContainerConfig config = new FakeContainerConfig(); AccelUriManager accelUriManager = new DefaultAccelUriManager( config, new DefaultProxyUriManager(config, null)); rewriter = new FakeCaptureRewriter(); rewriterRegistry = new DefaultResponseRewriterRegistry( Arrays.<ResponseRewriter>asList(rewriter), null); servlet = new HtmlAccelServlet(); servlet.setHandler(new AccelHandler(pipeline, rewriterRegistry, accelUriManager, true)); }
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); }
@Test public void testParseAndNormalizeAccelUri() throws Exception { Uri uri = Uri.parse("http://apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"); HttpRequest req = new HttpRequest(uri); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&debug=0&nocache=0&refresh=0" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); }
@Before public void setUp() throws Exception { config = new BasicContainerConfig(); config .newTransaction() .addContainer(makeConfig("default", "/gadgets/proxy")) .addContainer(makeConfig("accel", "/gadgets/accel")) .commit(); uriManager = new DefaultAccelUriManager(config, new DefaultProxyUriManager( config, null)); }
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 testParseAndNormalizeNonAccelUri() throws Exception { Uri uri = Uri.parse("http://www.example.org/index.html"); HttpRequest req = new HttpRequest(uri); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0" + "&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); uri = Uri.parse("http://www.example.org/index.html"); req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0" + "&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); }
@Before public void setUp() throws Exception { config = new BasicContainerConfig(); config .newTransaction() .addContainer(makeConfig("default", "/gadgets/proxy")) .addContainer(makeConfig("accel", "/gadgets/accel")) .commit(); uriManager = new DefaultAccelUriManager(config, new DefaultProxyUriManager( config, null)); }
@Test public void testLooksLikeAccelUri() throws Exception { Uri uri = Uri.parse("http://apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"); assertTrue(uriManager.looksLikeAccelUri(uri)); uri = Uri.parse("http://www.example.org/index.html"); assertFalse(uriManager.looksLikeAccelUri(uri)); } }
@Test public void testParseAndNormalizeNonAccelUri() throws Exception { Uri uri = Uri.parse("http://www.example.org/index.html"); HttpRequest req = new HttpRequest(uri); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0" + "&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); uri = Uri.parse("http://www.example.org/index.html"); req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0" + "&rooe=1&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); }
@Test public void testLooksLikeAccelUri() throws Exception { Uri uri = Uri.parse("http://apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"); assertTrue(uriManager.looksLikeAccelUri(uri)); uri = Uri.parse("http://www.example.org/index.html"); assertFalse(uriManager.looksLikeAccelUri(uri)); }
@Test public void testParseAndNormalizeNonAccelUri() throws Exception { Uri uri = Uri.parse("http://www.example.org/index.html"); HttpRequest req = new HttpRequest(uri); assertEquals(Uri.parse("//apache.org/gadgets/proxy?container=default" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); uri = Uri.parse("http://www.example.org/index.html"); req = new HttpRequest(uri); req.setContainer("accel"); assertEquals(Uri.parse("//apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.example.org%2Findex.html" + "&debug=0&nocache=0&refresh=0" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"), uriManager.parseAndNormalize(req)); }
@Test public void testLooksLikeAccelUri() throws Exception { Uri uri = Uri.parse("http://apache.org/gadgets/accel?container=accel" + "&gadget=http%3A%2F%2Fwww.1.com%2Fa.html" + "&url=http%3A%2F%2Fwww.example.org%2Findex.html"); assertTrue(uriManager.looksLikeAccelUri(uri)); uri = Uri.parse("http://www.example.org/index.html"); assertFalse(uriManager.looksLikeAccelUri(uri)); }