try { int refreshInterval = Integer.parseInt(refreshIntervalStr); request.setCacheTtl(refreshInterval); } catch (NumberFormatException nfe) {
try { int refreshInterval = Integer.parseInt(refreshIntervalStr); request.setCacheTtl(refreshInterval); } catch (NumberFormatException nfe) {
try { int refreshInterval = Integer.parseInt(refreshIntervalStr); request.setCacheTtl(refreshInterval); } catch (NumberFormatException nfe) {
@Test public void addResponseWithForcedTtl() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponse("result"); assertTrue(cache.addResponse(request, response)); assertEquals("public,max-age=10", cache.map.get(key).getHeader("Cache-Control")); }
public TemplateLibrary loadTemplateLibrary(GadgetContext context, Uri uri) throws GadgetException { HttpRequest request = new HttpRequest(uri); request.setCacheTtl(300); HttpResponse response = pipeline.execute(request); if (response.getHttpStatusCode() != HttpResponse.SC_OK) {
@Test public void addResponseWithForcedTtl() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponse("result"); assertNotNull(cache.addResponse(request, response)); assertEquals("public,max-age=10", cache.map.get(key).getHeader("Cache-Control")); assertNotNull(extendedStrictNoCacheTtlCache.addResponse(request, response)); assertEquals("public,max-age=10", extendedStrictNoCacheTtlCache.map.get(key).getHeader("Cache-Control")); }
@Test public void addResponseWithForcedTtl() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponse("result"); assertNotNull(cache.addResponse(request, response)); assertEquals("public,max-age=10", cache.map.get(key).getHeader("Cache-Control")); assertNotNull(extendedStrictNoCacheTtlCache.addResponse(request, response)); assertEquals("public,max-age=10", extendedStrictNoCacheTtlCache.map.get(key).getHeader("Cache-Control")); }
@Test public void addResponseWithForcedTtlAndStrictNoCache() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponseBuilder() .setResponseString("result") .setStrictNoCache() .create(); assertTrue(cache.addResponse(request, response)); assertEquals("public,max-age=10", cache.map.get(key).getHeader("Cache-Control")); }
/** * Retrieves a spec from the network, parses, and adds it to the cache. */ protected T fetchFromNetwork(Query query) throws SpecRetrievalFailedException, GadgetException { HttpRequest request = new HttpRequest(query.specUri) .setIgnoreCache(query.ignoreCache) .setGadget(query.gadgetUri) .setContainer(query.container); // Since we don't allow any variance in cache time, we should just force the cache time // globally. This ensures propagation to shared caches when this is set. request.setCacheTtl((int) (refresh / 1000)); HttpResponse response = pipeline.execute(request); if (response.getHttpStatusCode() != HttpResponse.SC_OK) { int retcode = response.getHttpStatusCode(); if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) { // Convert external "internal error" to gateway error: retcode = HttpResponse.SC_BAD_GATEWAY; } throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "Unable to retrieve spec for " + query.specUri + ". HTTP error " + response.getHttpStatusCode(), retcode); } try { String content = response.getResponseAsString(); return parse(content, query); } catch (XmlException e) { throw new SpecParserException(e); } }
/** * Retrieves a spec from the network, parses, and adds it to the cache. */ protected T fetchFromNetwork(Query query) throws SpecRetrievalFailedException, GadgetException { HttpRequest request = new HttpRequest(query.specUri) .setIgnoreCache(query.ignoreCache) .setGadget(query.gadgetUri) .setContainer(query.container); // Since we don't allow any variance in cache time, we should just force the cache time // globally. This ensures propagation to shared caches when this is set. request.setCacheTtl((int) (refresh / 1000)); HttpResponse response = pipeline.execute(request); if (response.getHttpStatusCode() != HttpResponse.SC_OK) { int retcode = response.getHttpStatusCode(); if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) { // Convert external "internal error" to gateway error: retcode = HttpResponse.SC_BAD_GATEWAY; } throw new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, "Unable to retrieve spec for " + query.specUri + ". HTTP error " + response.getHttpStatusCode(), retcode); } try { String content = response.getResponseAsString(); return parse(content, query); } catch (XmlException e) { throw new SpecParserException(e); } }
@Test public void addResponseWithForcedTtlAndErrorResponse() { HttpRequest request = new HttpRequest(DEFAULT_URI).setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponseBuilder() .setResponseString("result") .setHttpStatusCode(500) .create(); assertNotNull(cache.addResponse(request, response)); assertNull(cache.map.get(key).getHeader("Cache-Control")); assertNotNull(extendedStrictNoCacheTtlCache.addResponse(request, response)); assertNull(extendedStrictNoCacheTtlCache.map.get(key).getHeader("Cache-Control")); }
@Test public void addResponseWithForcedTtlAndErrorResponse() { HttpRequest request = new HttpRequest(DEFAULT_URI).setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponseBuilder() .setResponseString("result") .setHttpStatusCode(500) .create(); assertNotNull(cache.addResponse(request, response)); assertNull(cache.map.get(key).getHeader("Cache-Control")); assertNotNull(extendedStrictNoCacheTtlCache.addResponse(request, response)); assertNull(extendedStrictNoCacheTtlCache.map.get(key).getHeader("Cache-Control")); }
@Test public void addResponseWithForcedTtlAndStrictNoCache() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponseBuilder() .setResponseString("result") .setStrictNoCache() .create(); assertNotNull(cache.addResponse(request, response)); assertEquals("public,max-age=10", cache.map.get(key).getHeader("Cache-Control")); assertNotNull(extendedStrictNoCacheTtlCache.addResponse(request, response)); assertEquals("public,max-age=10", extendedStrictNoCacheTtlCache.map.get(key).getHeader("Cache-Control")); }
@Test public void addResponseWithForcedTtlAndStrictNoCache() { HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(10); String key = cache.createKey(request); HttpResponse response = new HttpResponseBuilder() .setResponseString("result") .setStrictNoCache() .create(); assertNotNull(cache.addResponse(request, response)); assertEquals("public,max-age=10", cache.map.get(key).getHeader("Cache-Control")); assertNotNull(extendedStrictNoCacheTtlCache.addResponse(request, response)); assertEquals("public,max-age=10", extendedStrictNoCacheTtlCache.map.get(key).getHeader("Cache-Control")); }
public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = new HttpRequest(targetUri) .setIgnoreCache(isNoCache()) .setContainer(getContainer()); if (!Strings.isNullOrEmpty(getGadget())) { try { req.setGadget(Uri.parse(getGadget())); } catch (IllegalArgumentException e) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(), HttpResponse.SC_BAD_REQUEST); } } if (getRefresh() != null && getRefresh() >= 0) { req.setCacheTtl(getRefresh()); } // Allow the rewriter to use an externally forced MIME type. This is needed // allows proper rewriting of <script src="x"/> where x is returned with // a content type like text/html which unfortunately happens all too often if (rewriteMimeType != null) { req.setRewriteMimeType(getRewriteMimeType()); } req.setSanitizationRequested(sanitizeContent()); req.setCajaRequested(cajoleContent()); return req; }
public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = new HttpRequest(targetUri) .setIgnoreCache(isNoCache()) .setContainer(getContainer()); if (!StringUtils.isEmpty(getGadget())) { try { req.setGadget(Uri.parse(getGadget())); } catch (IllegalArgumentException e) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(), HttpResponse.SC_BAD_REQUEST); } } if (getRefresh() != null && getRefresh() >= 0) { req.setCacheTtl(getRefresh()); } // Allow the rewriter to use an externally forced MIME type. This is needed // allows proper rewriting of <script src="x"/> where x is returned with // a content type like text/html which unfortunately happens all too often if (rewriteMimeType != null) { req.setRewriteMimeType(getRewriteMimeType()); } req.setSanitizationRequested(sanitizeContent()); req.setCajaRequested(cajoleContent()); return req; }
public HttpRequest makeHttpRequest(Uri targetUri) throws GadgetException { HttpRequest req = new HttpRequest(targetUri) .setIgnoreCache(isNoCache()) .setContainer(getContainer()); if (!StringUtils.isEmpty(getGadget())) { try { req.setGadget(Uri.parse(getGadget())); } catch (IllegalArgumentException e) { throw new GadgetException(GadgetException.Code.INVALID_PARAMETER, "Invalid " + Param.GADGET.getKey() + " param: " + getGadget(), HttpResponse.SC_BAD_REQUEST); } } if (getRefresh() != null && getRefresh() >= 0) { req.setCacheTtl(getRefresh()); } // Allow the rewriter to use an externally forced MIME type. This is needed // allows proper rewriting of <script src="x"/> where x is returned with // a content type like text/html which unfortunately happens all too often if (rewriteMimeType != null) { req.setRewriteMimeType(getRewriteMimeType()); } req.setSanitizationRequested(sanitizeContent()); req.setCajaRequested(cajoleContent()); return req; }
/** * Retrieves a spec from the network, parses, and adds it to the cache. */ protected T fetchFromNetwork(Query query) throws SpecRetrievalFailedException, GadgetException { HttpRequest request = new HttpRequest(query.specUri) .setIgnoreCache(query.ignoreCache) .setGadget(query.gadgetUri) .setContainer(query.container) .setSecurityToken( new AnonymousSecurityToken("", 0L, query.gadgetUri.toString())); // Since we don't allow any variance in cache time, we should just force the cache time // globally. This ensures propagation to shared caches when this is set. request.setCacheTtl((int) (refresh / 1000)); HttpResponse response = pipeline.execute(request); if (response.getHttpStatusCode() != HttpResponse.SC_OK) { int retcode = response.getHttpStatusCode(); if (retcode == HttpResponse.SC_INTERNAL_SERVER_ERROR) { // Convert external "internal error" to gateway error: retcode = HttpResponse.SC_BAD_GATEWAY; } throw new SpecRetrievalFailedException(query.specUri, retcode); } try { String content = response.getResponseAsString(); return parse(content, query); } catch (XmlException e) { throw new SpecParserException(e); } }
oauthArguments.setSignViewer(true); HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(100) .addHeader(TEST_HEADER_KEY, TEST_HEADER_VALUE) .setContainer("container")
oauthArguments.setSignViewer(true); HttpRequest request = new HttpRequest(DEFAULT_URI) .setCacheTtl(100) .addHeader(TEST_HEADER_KEY, TEST_HEADER_VALUE) .setContainer("container")