Exemplo n.º 1
0
 protected static Uri ValidateUrl(String urlToValidate)
 {
     if (urlToValidate == null)
     {
         throw new Exception("url parameter is missing.");
     }
     try
     {
         UriBuilder url = UriBuilder.parse(urlToValidate);
         if (!"http".Equals(url.getScheme()) && !"https".Equals(url.getScheme()))
         {
             throw new GadgetException(GadgetException.Code.INVALID_PARAMETER,
                                       "Invalid request url scheme in url: " + HttpUtility.UrlEncode(urlToValidate) +
                                       "; only \"http\" and \"https\" supported.");
         }
         if (string.IsNullOrEmpty(url.getPath()))
         {
             url.setPath("/");
         }
         return(url.toUri());
     }
     catch
     {
         throw new Exception("url parameter is not a valid url.");
     }
 }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }