/// <summary>
 /// Corrects the base uri from bvParameters and returns the baseUri which is corrected.
 /// </summary>
 /// <returns>Corrected Base URI as String</returns>
 public String correctedBaseUri()
 {
     return(BVUtility.removeBVParameters
            (
                (bvParameters.BaseURI == null) ? "" : bvParameters.BaseURI
            ));
 }
 /// <summary>
 /// Retrieves the fragment string portion from the URL.
 /// </summary>
 /// <returns>Returns the Fragment String</returns>
 public String fragmentString()
 {
     if (this._fragmentString == null)
     {
         this._fragmentString = BVUtility.getFragmentString(bvParameters.PageURI);
     }
     return(this._fragmentString);
 }
 /// <summary>
 /// Retrieves the query string portion from the URL.
 /// </summary>
 /// <returns>Returns the Query String</returns>
 public String queryString()
 {
     if (this._queryString == null)
     {
         this._queryString = BVUtility.getQueryString(bvParameters.PageURI);
     }
     return(this._queryString);
 }
 /// <summary>
 ///     Append all content to _uiContent, including Integration Code iff it should be included.
 /// </summary>
 /// <param name="contentLoader"></param>
 private void AppendContent(IContentLoader contentLoader)
 {
     if (IncludeIntegrationCode)
     {
         _uiContent.Append(GetIntegrationCode());
     }
     _uiContent.Append(contentLoader.LoadContent(SeoContentUrl));
     BVUtility.replacePageURIFromContent(_uiContent, CorrectedBaseUri);
 }
        // if BVParameters.PageNumber isn't valid, check query string for page # (return default of "1")
        private void setPageNumber()
        {
            if (IsValidPageNumber(bvParameters.PageNumber))
            {
                return;
            }

            bvParameters.PageNumber = BVUtility.getPageNumber(queryString());
        }
        public string LoadContent(Uri uri)
        {
            string content = null;

            try
            {
                var httpRequest = (HttpWebRequest)WebRequest.Create(uri);
                httpRequest.AutomaticDecompression = DecompressionMethods.GZip;
                httpRequest.Timeout          = ConnectionTimeout;
                httpRequest.ReadWriteTimeout = SocketTimeout;
                httpRequest.UserAgent        = UserAgent;
                if (!string.IsNullOrEmpty(ProxyHost) &&
                    !ProxyHost.Equals("none", StringComparison.InvariantCultureIgnoreCase))
                {
                    var proxy = new WebProxy(ProxyHost, ProxyPort);
                    httpRequest.Proxy = proxy;
                }

                var webResponse = (HttpWebResponse)httpRequest.GetResponse();
                using (var reader = new StreamReader(webResponse.GetResponseStream(), Encoding))
                {
                    content = reader.ReadToEnd();
                }
            }
            catch (ProtocolViolationException e)
            {
                Logger.Error(BVMessageUtil.getMessage("ERR0012"), e);
                throw new BVSdkException("ERR0012");
            }
            catch (IOException e)
            {
                Logger.Error(BVMessageUtil.getMessage("ERR0019"), e);
                throw new BVSdkException("ERR0019");
            }
            catch (WebException e)
            {
                Logger.Error(BVMessageUtil.getMessage("ERR0012"), e);
                throw new BVSdkException("ERR0012");
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                throw new BVSdkException(e.Message);
            }

            var isValidContent = BVUtility.validateBVContent(content);

            if (!isValidContent)
            {
                Logger.Error(BVMessageUtil.getMessage("ERR0025"));
                throw new BVSdkException("ERR0025");
            }


            return(content);
        }
Пример #7
0
        public void TestIsRevealDebugEnabled()
        {
            // No bvreveal=debug in query param or reveal:debug in bvstate
            BVParameters bvParam = new BVParameters();

            bvParam.BaseURI = "http://localhost:8080/Sample/Example-1.jsp";
            bvParam.PageURI = "http://localhost:8080/Sample/Example-1.jsp?bvstate=pg:2/ct:r/st:p/id:ssl-certificates";

            Assert.IsFalse(BVUtility.isRevealDebugEnabled(bvParam), "reveal debug should be false");

            // Has bvreveal=notdebug in query param. No reveal:debug in bvstate
            bvParam         = new BVParameters();
            bvParam.BaseURI = "http://localhost:8080/Sample/Example-1.jsp";
            bvParam.PageURI = "http://localhost:8080/Sample/Example-1.jsp?bvstate=pg:2/ct:r/st:p/id:ssl-certificates&bvreveal=notdebug";

            Assert.IsFalse(BVUtility.isRevealDebugEnabled(bvParam), "reveal debug should be false");

            // Has bvreveal=debug in query param
            bvParam         = new BVParameters();
            bvParam.BaseURI = "http://localhost:8080/Sample/Example-1.jsp";
            bvParam.PageURI = "http://localhost:8080/Sample/Example-1.jsp?bvstate=pg:2/ct:r/st:p/id:ssl-certificates&bvreveal=debug";

            Assert.IsTrue(BVUtility.isRevealDebugEnabled(bvParam), "reveal debug should be true");

            // Has reveal:notdebug in bvstate
            bvParam         = new BVParameters();
            bvParam.BaseURI = "http://localhost:8080/Sample/Example-1.jsp";
            bvParam.PageURI = "http://localhost:8080/Sample/Example-1.jsp?bvstate=pg:2/ct:r/st:p/id:ssl-certificates/reveal:notdebug";

            Assert.IsFalse(BVUtility.isRevealDebugEnabled(bvParam), "reveal debug should be false");

            // Has reveal:debug in bvstate
            bvParam         = new BVParameters();
            bvParam.BaseURI = "http://localhost:8080/Sample/Example-1.jsp";
            bvParam.PageURI = "http://localhost:8080/Sample/Example-1.jsp?bvstate=pg:2/ct:r/st:p/id:ssl-certificates/reveal:debug";

            Assert.IsTrue(BVUtility.isRevealDebugEnabled(bvParam), "reveal debug should be true");
        }
Пример #8
0
        public void TestPageURIReplacementInContent()
        {
            /*
             * bvrrp in content with no query/fragment string in baseUri.
             * append ?
             */
            String        data    = "{INSERT_PAGE_URI}bvrrp=9344/reviews/product/4/5000001.htm";
            StringBuilder content = new StringBuilder();

            content.Append(data);
            String baseUri         = "http://localhost:8080/index.jsp";
            String expectedContent = "http://localhost:8080/index.jsp?bvrrp=9344/reviews/product/4/5000001.htm";

            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing query string in baseUri.
             * append &
             */
            data    = "{INSERT_PAGE_URI}bvrrp=9344/reviews/product/4/5000001.htm";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp?a=b";
            expectedContent = "http://localhost:8080/index.jsp?a=b&bvrrp=9344/reviews/product/4/5000001.htm";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with no query/fragment string in baseUri.
             * append ?
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp";
            expectedContent = "http://localhost:8080/index.jsp?bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing query string in baseUri.
             * append &
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp?a=b";
            expectedContent = "http://localhost:8080/index.jsp?a=b&bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing fragment string in baseUri.
             * baseUri - ends with #!
             * append nothing
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp#!";
            expectedContent = "http://localhost:8080/index.jsp#!bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing fragment string in baseUri.
             * baseUri - not end with #! but ends with ?
             * append nothing
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp#!a=b?";
            expectedContent = "http://localhost:8080/index.jsp#!a=b?bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing fragment string in baseUri.
             * baseUri - not end with #! and not ends with ? but contains ?
             * append &
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp#!a=b?testing=true";
            expectedContent = "http://localhost:8080/index.jsp#!a=b?testing=true&bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing fragment string in baseUri.
             * baseUri - not end with #! and doesnot contain ?
             * append ?
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp#!a=b";
            expectedContent = "http://localhost:8080/index.jsp#!a=b?bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing _escaped_fragment_ string in baseUri.
             * baseUri - ends with _escaped_fragment_=
             * append nothing
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp?_escaped_fragment_=";
            expectedContent = "http://localhost:8080/index.jsp?_escaped_fragment_=bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing _escaped_fragment_ string in baseUri.
             * baseUri - contains _escaped_fragment_ with ? in it
             * append %26
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp?_escaped_fragment_=a/b?c=d";
            expectedContent = "http://localhost:8080/index.jsp?_escaped_fragment_=a/b?c=d%26bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");

            /*
             * bvstate in content with existing _escaped_fragment_ string in baseUri.
             * baseUri - contains _escaped_fragment_ with no ? in it
             * append ?
             */
            data    = "{INSERT_PAGE_URI}bvstate=pg:2/ct:r/st:p/id:5000001";
            content = new StringBuilder();
            content.Append(data);
            baseUri         = "http://localhost:8080/index.jsp?_escaped_fragment_=a/b";
            expectedContent = "http://localhost:8080/index.jsp?_escaped_fragment_=a/b?bvstate=pg:2/ct:r/st:p/id:5000001";
            BVUtility.replacePageURIFromContent(content, baseUri);

            Assert.AreEqual <string>(content.ToString(), expectedContent, "actual and expected content should be same");
        }
 /// <summary>
 ///     Implementation to check if sdk is enabled/disabled.
 ///     The settings are based on the configurations from BVConfiguration and BVParameters.
 /// </summary>
 /// <returns>A Boolean value, true if sdk is enabled and false if it is not enabled</returns>
 public bool isSdkEnabled()
 {
     _sdkEnabled = bool.Parse(_bvConfiguration.getProperty(BVClientConfig.SEO_SDK_ENABLED));
     _sdkEnabled = _sdkEnabled || BVUtility.isRevealDebugEnabled(_bvParameters);
     return(_sdkEnabled);
 }
Пример #10
0
        /// <summary>
        /// Returns the footer based on the configuration that is set.
        /// </summary>
        /// <param name="accessMethod">Parameter to provide the BV SEO Content Access Method</param>
        /// <returns>Footer Content as a String</returns>
        public String displayFooter(String accessMethod)
        {
            string FooterTemplate = Resources.footer.ToString();

            if (!string.IsNullOrEmpty(FooterTemplate))
            {
                VelocityContext context = new VelocityContext();

                if (BVUtility.isRevealDebugEnabled(_bvParameters))
                {
                    Hashtable revealMap = null;
                    revealMap = new Hashtable();

                    if (
                        _bvParameters != null
                        &&
                        !_bvParameters.SubjectType.getCS2013Text().Equals(
                            BVSubjectType.SELLER,
                            StringComparison.OrdinalIgnoreCase
                            )
                        )
                    {
                        foreach (string configName in BVCoreConfig.values())
                        {
                            revealMap.Add(configName, _bvConfiguration.getProperty(configName));
                        }
                    }

                    foreach (string configName in BVClientConfig.values())
                    {
                        revealMap.Add(configName, _bvConfiguration.getProperty(configName));
                    }
                    context.Put("revealMap", revealMap);
                }

                string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                String methodType = Boolean.Parse(
                    _bvConfiguration.getProperty(BVClientConfig.LOAD_SEO_FILES_LOCALLY)) ? "LOCAL" : "CLOUD";
                context.Put("sdk_enabled", _bvConfiguration.getProperty(BVClientConfig.SEO_SDK_ENABLED));
                context.Put("_bvParameters", _bvParameters);
                context.Put("methodType", methodType);
                context.Put("executionTime", executionTime);
                context.Put("accessMethod", accessMethod);
                context.Put("version", assemblyVersion);

                String message = null;
                if (messageList != null && messageList.Count > 0)
                {
                    message = "";
                    foreach (String messageStr in messageList)
                    {
                        message += messageStr;
                    }
                }
                context.Put("message", message);

                String  url          = null;
                Boolean loadFromFile = Boolean.Parse(_bvConfiguration.getProperty(BVClientConfig.LOAD_SEO_FILES_LOCALLY));
                if (!loadFromFile && _bvSeoSdkUrl != null)
                {
                    url = _bvSeoSdkUrl.seoContentUri().ToString();
                }
                context.Put("url", url);

                StringWriter writer = new StringWriter();
                _velocityEngine.Evaluate(context, writer, "footer", FooterTemplate);

                return(writer.ToString());
            }
            else
            {
                return(String.Empty);
            }
        }