Пример #1
0
        /**
         * Render the gadget into a string by performing the following steps:
         *
         * - Retrieve gadget specification information (GadgetSpec, MessageBundle, etc.)
         *
         * - Fetch any preloaded data needed to handle the request, as handled by Preloader.
         *
         * - Perform rewriting operations on the output content, handled by Rewriter.
         *
         * @param gadget The gadget for the rendering operation.
         * @return The rendered gadget content
         * @throws RenderingException if any issues arise that prevent rendering.
         */
        public String render(Gadget gadget)
        {
            try
            {
                View          view    = gadget.getCurrentView();
                GadgetContext context = gadget.getContext();
                GadgetSpec    spec    = gadget.getSpec();

                IPreloads preloads = preloader.preload(context, spec,
                                                       PreloaderService.PreloadPhase.HTML_RENDER);
                gadget.setPreloads(preloads);
                String content;

                if (view.getHref() == null)
                {
                    content = view.getContent();
                }
                else
                {
                    // TODO: Add current url to GadgetContext to support transitive proxying.
                    UriBuilder uri = new UriBuilder(view.getHref());
                    uri.addQueryParameter("lang", context.getLocale().getLanguage());
                    uri.addQueryParameter("country", context.getLocale().getCountry());

                    sRequest request = new sRequest(uri.toUri())
                                       .setIgnoreCache(context.getIgnoreCache())
                                       .setOAuthArguments(new OAuthArguments(view))
                                       .setAuthType(view.getAuthType())
                                       .setSecurityToken(context.getToken())
                                       .setContainer(context.getContainer())
                                       .setGadget(spec.getUrl());
                    sResponse response = DefaultHttpCache.Instance.getResponse(request);

                    if (response == null || response.isStale())
                    {
                        sRequest proxyRequest = createPipelinedProxyRequest(gadget, request);
                        response = requestPipeline.execute(proxyRequest);
                        DefaultHttpCache.Instance.addResponse(request, response);
                    }

                    if (response.isError())
                    {
                        throw new RenderingException("Unable to reach remote host. HTTP status " +
                                                     response.getHttpStatusCode());
                    }
                    content = response.responseString;
                }

                return(rewriter.rewriteGadget(gadget, content));
            }
            catch (GadgetException e)
            {
                throw new RenderingException(e.Message, e);
            }
        }
Пример #2
0
        /**
         * Creates a set of all configuration needed to satisfy the requested feature set.
         *
         * Appends special configuration for gadgets.util.hasFeature and gadgets.util.getFeatureParams to
         * the output js.
         *
         * This can't be handled via the normal configuration mechanism because it is something that
         * varies per request.
         *
         * @param reqs The features needed to satisfy the request.
         * @throws GadgetException If there is a problem with the gadget auth token
         */
        private String GetLibraryConfig(Gadget gadget, ICollection <GadgetFeature> reqs)

        {
            GadgetContext context = gadget.getContext();

            JsonObject features = containerConfig.GetJsonObject(context.getContainer(), FEATURES_KEY);

            Dictionary <String, Object> config = new Dictionary <string, object>(features == null ? 2 : features.Names.Count + 2);

            if (features != null)
            {
                // Discard what we don't care about.
                foreach (GadgetFeature feature in reqs)
                {
                    String name = feature.getName();
                    Object conf = features.Opt(name);
                    if (conf != null)
                    {
                        config.Add(name, conf);
                    }
                }
            }

            // Add gadgets.util support. This is calculated dynamically based on request inputs.
            ModulePrefs prefs  = gadget.getSpec().getModulePrefs();
            var         values = prefs.getFeatures().Values;
            Dictionary <String, Dictionary <String, String> > featureMap =
                new Dictionary <string, Dictionary <string, string> >(values.Count);

            foreach (Feature feature in values)
            {
                featureMap.Add(feature.getName(), feature.getParams());
            }
            config.Add("core.util", featureMap);

            // Add authentication token config
            ISecurityToken authToken = context.getToken();

            if (authToken != null)
            {
                Dictionary <String, String> authConfig = new Dictionary <String, String>(2);
                String updatedToken = authToken.getUpdatedToken();
                if (updatedToken != null)
                {
                    authConfig.Add("authToken", updatedToken);
                }
                String trustedJson = authToken.getTrustedJson();
                if (trustedJson != null)
                {
                    authConfig.Add("trustedJson", trustedJson);
                }
                config.Add("shindig.auth", authConfig);
            }
            return("gadgets.config.init(" + JsonConvert.ExportToString(config) + ");\n");
        }
Пример #3
0
 public static sRequest newHttpRequest(GadgetContext context,
             RequestAuthenticationInfo authenticationInfo)
 {
     sRequest request = new sRequest(authenticationInfo.getHref())
         .setSecurityToken(context.getToken())
         .setOAuthArguments(new OAuthArguments(authenticationInfo))
         .setAuthType(authenticationInfo.getAuthType())
         .setContainer(context.getContainer())
         .setGadget(Uri.fromJavaUri(context.getUrl()));
     return request;
 }
Пример #4
0
        public static sRequest newHttpRequest(GadgetContext context,
                                              RequestAuthenticationInfo authenticationInfo)
        {
            sRequest request = new sRequest(authenticationInfo.getHref())
                               .setSecurityToken(context.getToken())
                               .setOAuthArguments(new OAuthArguments(authenticationInfo))
                               .setAuthType(authenticationInfo.getAuthType())
                               .setContainer(context.getContainer())
                               .setGadget(Uri.fromJavaUri(context.getUrl()));

            return(request);
        }