@Override protected void doGet(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { if (logger.isLoggable(Level.FINE)) { logger.fine("Accel request = " + request.toString()); } HttpRequest req = ServletUtil.fromHttpServletRequest(request); req.setContainer(AccelUriManager.CONTAINER); HttpResponse response; try { response = accelHandler.fetch(req); } catch (GadgetException e) { response = ServletUtil.errorResponse(e); } ServletUtil.copyToServletResponse(response, servletResponse); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { if (logger.isLoggable(Level.FINE)) { logger.fine("Accel request = " + request.toString()); } HttpRequest req = ServletUtil.fromHttpServletRequest(request); req.setContainer(AccelUriManager.CONTAINER); HttpResponse response = null; try { response = accelHandler.fetch(req); } catch (GadgetException e) { response = ServletUtil.errorResponse(e); } ServletUtil.copyResponseToServlet(response, servletResponse); }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse servletResponse) throws IOException { if (logger.isLoggable(Level.FINE)) { logger.fine("Accel request = " + request.toString()); } HttpRequest req = ServletUtil.fromHttpServletRequest(request); req.setContainer(AccelUriManager.CONTAINER); HttpResponse response = null; try { response = accelHandler.fetch(req); } catch (GadgetException e) { response = ServletUtil.errorResponse(e); } ServletUtil.copyResponseToServlet(response, servletResponse); }
private static HttpRequest createCacheableRequest() { return new HttpRequest(SPEC_URL) .setGadget(SPEC_URL) .setContainer(ContainerConfig.DEFAULT_CONTAINER); }
private static HttpRequest createCacheableRequest() { return new HttpRequest(SPEC_URL) .setGadget(SPEC_URL) .setContainer(ContainerConfig.DEFAULT_CONTAINER); }
private static HttpRequest createCacheableRequest() { return new HttpRequest(SPEC_URL) .setGadget(SPEC_URL) .setContainer(ContainerConfig.DEFAULT_CONTAINER); }
private static HttpRequest createIgnoreCacheRequest() { return new HttpRequest(SPEC_URL) .setIgnoreCache(true) .setGadget(SPEC_URL) .setContainer(ContainerConfig.DEFAULT_CONTAINER); }
public FetchedData fetch(ExternalReference ref, String mimeType) throws UriFetchException { LOG.info("Retrieving " + ref.toString()); Uri resourceUri = gadgetUri.resolve(Uri.fromJavaUri(ref.getUri())); HttpRequest request = new HttpRequest(resourceUri).setContainer(container).setGadget(gadgetUri); try { HttpResponse response = requestPipeline.execute(request); byte[] responseBytes = IOUtils.toByteArray(response.getResponse()); return FetchedData.fromBytes(responseBytes, mimeType, response.getEncoding(), new InputSource(ref.getUri())); } catch (GadgetException e) { LOG.info("Failed to retrieve: " + ref.toString()); return null; } catch (IOException e) { LOG.info("Failed to read: " + ref.toString()); return null; } }
private static HttpRequest createIgnoreCacheRequest() { return new HttpRequest(SPEC_URL) .setIgnoreCache(true) .setGadget(SPEC_URL) .setContainer(ContainerConfig.DEFAULT_CONTAINER); }
private static HttpRequest createIgnoreCacheRequest() { return new HttpRequest(SPEC_URL) .setIgnoreCache(true) .setGadget(SPEC_URL) .setContainer(ContainerConfig.DEFAULT_CONTAINER); }
private void testImportsAndBackgroundUrlsInStyleTag(String html, String expected, String container) throws Exception { Document doc = htmlParser.parseDom(html); ContentRewriterFeature.Config config = injector.getInstance( ContentRewriterFeature.DefaultConfig.class); EasyMock.replay(); StyleTagProxyEmbeddedUrlsVisitor visitor = new StyleTagProxyEmbeddedUrlsVisitor( config, proxyUriManager, injector.getInstance(CssResponseRewriter.class)); Gadget gadget = DomWalker.makeGadget(new HttpRequest(Uri.parse("http://1.com/")).setContainer( container)); NodeList list = doc.getElementsByTagName("style"); visitor.revisit(gadget, ImmutableList.of(list.item(0))); EasyMock.verify(); assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(serializer.serialize(doc))); } }
private void testImportsAndBackgroundUrlsInStyleTag(String html, String expected, String container, Config config) throws Exception { // TODO: IMPORTANT! This test needs to not rely on the packaged shindig config, but rather // mock the config with expected values, so that tests do not fail when people set // alternative defaults. Document doc = htmlParser.parseDom(html); StyleTagProxyEmbeddedUrlsVisitor visitor = new StyleTagProxyEmbeddedUrlsVisitor( config, proxyUriManager, injector.getInstance(CssResponseRewriter.class)); Gadget gadget = DomWalker.makeGadget(new HttpRequest(Uri.parse("http://1.com/")).setContainer( container)); NodeList list = doc.getElementsByTagName("style"); visitor.revisit(gadget, ImmutableList.of(list.item(0))); EasyMock.verify(); assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(serializer.serialize(doc))); } }
private void testImportsAndBackgroundUrlsInStyleTag(String html, String expected, String container, Config config) throws Exception { // TODO: IMPORTANT! This test needs to not rely on the packaged shindig config, but rather // mock the config with expected values, so that tests do not fail when people set // alternative defaults. Document doc = htmlParser.parseDom(html); StyleTagProxyEmbeddedUrlsVisitor visitor = new StyleTagProxyEmbeddedUrlsVisitor( config, proxyUriManager, injector.getInstance(CssResponseRewriter.class)); Gadget gadget = DomWalker.makeGadget(new HttpRequest(Uri.parse("http://1.com/")).setContainer( container)); NodeList list = doc.getElementsByTagName("style"); visitor.revisit(gadget, ImmutableList.of(list.item(0))); EasyMock.verify(); assertEquals(StringUtils.deleteWhitespace(expected), StringUtils.deleteWhitespace(serializer.serialize(doc))); } }
/** * Constructs a new HttpRequest in the context of the gadget. * For example, the implementation may choose to copy User Agent or referer etc. */ protected HttpRequest createNewHttpRequest(Gadget gadget, String uriStr) { HttpRequest request = new HttpRequest(Uri.parse(uriStr)); if (gadget != null) { GadgetSpec spec = gadget.getSpec(); if (spec != null) { request.setGadget(spec.getUrl()); } GadgetContext context = gadget.getContext(); if (context != null) { request.setContainer(context.getContainer()); } request.setParam(CACHE_ENFORCEMENT_FETCH_PARAM, "1"); } return request; }
public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setOAuth2Arguments(new OAuth2Arguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
@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 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 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)); }