boolean bypassCache = false; try { obj = fetchFromNetwork(query); } catch (SpecRetrievalFailedException e) {
private MessageBundle getBundleFor(GadgetSpec spec, Locale locale, boolean ignoreCache, String container) throws GadgetException { LocaleSpec localeSpec = spec.getModulePrefs().getLocale(locale); if (localeSpec == null) { return MessageBundle.EMPTY; } if (localeSpec.getMessages().toString().length() == 0) { return localeSpec.getMessageBundle(); } LocaleQuery query = new LocaleQuery(); query.setSpecUri(localeSpec.getMessages()) .setGadgetUri(spec.getUrl()) .setContainer(container) .setIgnoreCache(ignoreCache); query.locale = localeSpec; return super.getSpec(query); }
/** * 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); } }
private MessageBundle getBundleFor(GadgetSpec spec, Locale locale, boolean ignoreCache, String container, String view) throws GadgetException { LocaleSpec localeSpec = spec.getModulePrefs().getLocale(locale, view); if (localeSpec == null) { return MessageBundle.EMPTY; } if (localeSpec.getMessages().toString().length() == 0) { return localeSpec.getMessageBundle(); } LocaleQuery query = new LocaleQuery(); query.setSpecUri(localeSpec.getMessages()) .setGadgetUri(spec.getUrl()) .setContainer(container) .setIgnoreCache(ignoreCache); query.locale = localeSpec; return super.getSpec(query); }
/** * 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); } }
private MessageBundle getBundleFor(GadgetSpec spec, Locale locale, boolean ignoreCache, String container) throws GadgetException { LocaleSpec localeSpec = spec.getModulePrefs().getLocale(locale); if (localeSpec == null) { return MessageBundle.EMPTY; } if (localeSpec.getMessages().toString().length() == 0) { return localeSpec.getMessageBundle(); } LocaleQuery query = new LocaleQuery(); query.setSpecUri(localeSpec.getMessages()) .setGadgetUri(spec.getUrl()) .setContainer(container) .setIgnoreCache(ignoreCache); query.locale = localeSpec; return super.getSpec(query); }
/** * 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); } }
boolean bypassCache = false; try { obj = fetchFromNetwork(query); } catch (SpecRetrievalFailedException e) {
public GadgetSpec getGadgetSpec(GadgetContext context) throws GadgetException { String rawxml = context.getParameter(RAW_GADGETSPEC_XML_PARAM_NAME); if (rawxml != null) { // Set URI to a fixed, safe value (localhost), preventing a gadget rendered // via raw XML (eg. via POST) to be rendered on a locked domain of any other // gadget whose spec is hosted non-locally. try { Uri uri = RAW_GADGET_URI; return new GadgetSpec(uri, XmlUtil.parse(rawxml), rawxml); } catch (XmlException e) { throw new SpecParserException(e); } } Uri gadgetUri = context.getUrl(); Query query = new Query() .setSpecUri(gadgetUri) .setContainer(context.getContainer()) .setGadgetUri(gadgetUri) .setIgnoreCache(context.getIgnoreCache()); return super.getSpec(query); }
boolean bypassCache = false; try { obj = fetchFromNetwork(query); } catch (SpecRetrievalFailedException e) {
public GadgetSpec getGadgetSpec(GadgetContext context) throws GadgetException { String rawxml = context.getParameter(RAW_GADGETSPEC_XML_PARAM_NAME); if (rawxml != null) { // Set URI to a fixed, safe value (localhost), preventing a gadget rendered // via raw XML (eg. via POST) to be rendered on a locked domain of any other // gadget whose spec is hosted non-locally. try { Uri uri = RAW_GADGET_URI; return new GadgetSpec(uri, XmlUtil.parse(rawxml), rawxml); } catch (XmlException e) { throw new SpecParserException(e); } } Uri gadgetUri = context.getUrl(); Query query = new Query() .setSpecUri(gadgetUri) .setContainer(context.getContainer()) .setGadgetUri(gadgetUri) .setIgnoreCache(context.getIgnoreCache()); return super.getSpec(query); }