public GadgetsHandlerApi.ProxyResponse getProxy(GadgetsHandlerApi.ProxyRequest request) throws ProcessingException { verifyBaseParams(request, true); Set<String> fields = beanFilter.processBeanFields(request.getFields()); ProxyUri proxyUri = createProxyUri(request); List<Uri> uris = proxyUriManager.make(ImmutableList.of(proxyUri), null); HttpResponse httpResponse = null; try { if (isFieldIncluded(fields, "proxyContent")) { httpResponse = proxyHandler.fetch(proxyUri); } } catch (IOException e) { LOG.log(Level.INFO, "Failed to fetch resource " + proxyUri.getResource().toString(), e); throw new ProcessingException("Error getting response content", HttpResponse.SC_BAD_GATEWAY); } catch (GadgetException e) { // TODO: Clean this log if it is too spammy LOG.log(Level.INFO, "Failed to fetch resource " + proxyUri.getResource().toString(), e); throw new ProcessingException("Error getting response content", HttpResponse.SC_BAD_GATEWAY); } try { return createProxyResponse(uris.get(0), httpResponse, fields, getProxyExpireMs(proxyUri, httpResponse)); } catch (IOException e) { // Should never happen! LOG.log(Level.WARNING, "Error creating proxy response", e); throw new ProcessingException("Error getting response content", HttpResponse.SC_INTERNAL_SERVER_ERROR); } }
Gadget gadget = processor.process(context); boolean needIfrUrls = isFieldIncluded(fields, "iframeurls"); if (needIfrUrls) { if(!gadgetAdminStore.checkFeatureAdminInfo(gadget)) { translateUris(iframeUriManager.makeAllRenderingUris(gadget)) : null; Boolean needsTokenRefresh = isFieldIncluded(fields, "needstokenrefresh") ? gadget.getAllFeatures().contains("auth-refresh") : null; boolean alwaysAppendSecurityToken = config.getBool(gadget.getContext().getContainer(), Integer tokenTTL = isFieldIncluded(fields, "tokenTTL") ? securityTokenCodec.getTokenTimeToLive(context.getContainer()) : null;
if (tokenData != null) { expiryTimeMs = tokenData.getExpiresAt(); tokenTTL = isFieldIncluded(fields, "tokenTTL") ? securityTokenCodec.getTokenTimeToLive(tokenData.getContainer()) : null; moduleId = isFieldIncluded(fields, "moduleId") ? moduleId : null;
public GadgetsHandlerApi.JsResponse getJs(GadgetsHandlerApi.JsRequest request) throws ProcessingException { verifyBaseParams(request, false); Set<String> fields = beanFilter.processBeanFields(request.getFields()); JsUri jsUri = createJsUri(request); Uri servedUri = jsUriManager.makeExternJsUri(jsUri); String content = null; Long expireMs = null; if (isFieldIncluded(fields, "jsContent")) { JsResponse response; try { response = jsPipeline.execute(jsRequestBuilder.build(jsUri, servedUri.getAuthority())); } catch (JsException e) { throw new ProcessingException(e.getMessage(), e.getStatusCode()); } content = response.toJsString(); if (response.isProxyCacheable()) { expireMs = getDefaultExpiration(); } } else { expireMs = getDefaultExpiration(); } return createJsResponse(request.getUrl(), servedUri, content, fields, expireMs); }