/** * 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); } }
/** * 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); } }