6 Replies Latest reply on Mar 12, 2010 2:12 PM by vsalrhal1

    Crossdoman and HTTPS reference issues.

    vsalrhal1

      Howdy -

       

      I'm somewhat of a newbie when it comes to Flex. I've been keeping up with ActionScript for many, many years, so I have some knowledge here.

       

      I've recently been working to develop some widgets and API's for RSS and Atom parsing usability.

       

      I've completed the Flex/AS coding aspect.

       

      Aesthetically speaking, I've added a canvas and some CSS styling so that when it's prepared, I can just change the design.

       

      My issue -

       

      I can't parse the RSS Feeds because of an 'Security Error While Reading Feed URI!"...I'm assuming it's a crossdomain policy error.

       

      Here's my question;

       

      I'm not very versed in the area of crossdomainpolicy writing - I've created the XML and have added my own site to be allowed, as well as the "wildcard" for several others to be allowed.

       

      Here's my RSSparser.xml file -

                import mx.collections.ArrayCollection;          import mx.controls.Alert;                    import com.feed.FeedParser;                    private var parser:FeedParser;          private var updateTimer:Timer = new Timer(600000);                    [Bindable]          private var DP:ArrayCollection;          private var currentFeed:String;                              private function init():void {                    DP=null;                    Security.allowDomain(feedURI.text);                     Security.allowInsecureDomain(feedURI.text);                    //Security.s andboxType=Security.LOCAL_WITH_NETWORK;                    parser = new FeedParser(feedURI.text);                    parser.addEventListener("DataReady", dataHandler);                    parser.addEventListener("DataError", dataErrorHandler);                    parser.loadFeed();                         }                     private function dataErrorHandler(evt:Event):void {               Alert.show("Some Error ocurred reading data from feed!\n\nPossible Causes:\nInvalid feed URL\nInvalid feed type (Not RSS 2.0)\nInvalid feed format");          }                    private function loadAutoUpdate():void {               try {                    updateTimer.stop();                    updateTimer.removeEventListen er(TimerEvent.TIMER, onTime);               }               catch(e:Error) { }                              updateTimer.addEventListener(TimerEvent.TIMER, onTime);               updateTimer.start();          }                    private function onTime(evt:TimerEvent):void {               feedURI.text=currentFeed;               init();          }                     private function dataHandler(evt:Event):void {               DP = new ArrayCollection();               DP=parser.FEED_DATA;               currentFeed=feedURI.t ext;               loadAutoUpdate();          }                    private function loadURL():void {               if(dataGridItems.selectedIndex>-1) navigateToURL(new URLRequest(dataGridItems.selectedItem.link), "_blank");          }                    private function refresh():void {               feedURI.text=currentFeed;               init();          }                     private function switchFeed():void {               if(currentFeed==feedURI.text) Alert.show("That is not a valid URL. Please edit and try again.");               else init();          }     

       

      Below will be the coding for the FeedParser.as file

       

      FeedParser.as -

      package com.feed   {   //necessary imports   import com.XMLUtil; //usefull for correct xml format XMLUtil.as from corelibPackage   import com.adobe.xml.syndication.atom.Atom10; //imports from xmlsyndicationlib from adobe   import com.adobe.xml.syndication.atom.Entry;   import com.adobe.xml.syndication.rss.Item20;   import com.adobe.xml.syndication.rss.RSS20;     //some flash imports needed to work with the feed   import flash.display.Sprite;   import flash.events.Event;   import flash.events.IOErrorEvent;   import flash.events.SecurityErrorEvent;   import flash.net.URLLoader;   import flash.net.URLRequest;   import flash.net.URLRequestMethod;   //two classes used in the process   import mx.collections.ArrayCollection;   import mx.controls.Alert;     public class FeedParser extends Sprite   {   private var feedURI:String="http://news.yahoo.com/page/rss"; //default feed   private var feedLoader:URLLoader; //the feed loader   public var FEED_DATA:ArrayCollection=null; //the feed data       public function FeedParser(url:String)   {   feedURI=url; //on initiate, set the feed url   }     public function loadFeed():void {    //add the listener events and load the feed    feedLoader = new URLLoader();    var req:URLRequest = new URLRequest(feedURI);    req.method = URLRequestMethod.GET;    feedLoader.addEventListener(Event.COMPLETE, completeHandler);    feedLoader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);    feedLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorHandler);    feedLoader.load(req);   } //error handling function private function errorHandler(e:Event):void {   if(e.type==SecurityErrorEvent.SECURITY_ERROR) Alert.show("Security Error while reading feed URI!");   else if(e.type==IOErrorEvent.IO_ERROR) Alert.show("I/O Error while reading feed URI!");   else Alert.show(e.type+" Error while reading feed URI!");   }   //on result function   private function completeHandler(evt:Event):void {   var feedData:String=feedLoader.data; //get the feed contents   var feed_type:String="RSS";   var entrys:Array;   var tempObj:Object;     //old way to detect feed type & version   if(feedData.search("rss version=\"2.0\"")>-1) trace("FEED RSS 2.0");   else if(feedData.search("rss version=")>-1) trace("FEED RSS <=1.0");   else if(feedData.search("Atom")>-1) trace("FEED ATOM");   if(feedData.search("xmlns=\"http://www.w3.org/2005/Atom")>-1) feed_type="ATOM"; //check if is an ATOM feed   //if is a RSS feed   if(feed_type=="RSS") {    var rss:RSS20= new RSS20();    try { rss.parse(feedData); }  //parse it    catch(e:Error) {     Alert.show("Error Parsing Feed!\nInvalid link?");     return void;   }     entrys=rss.items; //get the items   FEED_DATA = new ArrayCollection(); //initiate the arrayCollection     //validate the feed   if(!XMLUtil.isValidXML(feedData)) {    Alert.show("Invalid or bad feed URI or structure!");    return void;   }     //built an array Collection with the results   for each(var entry:Item20 in entrys)   {    tempObj = new Object();    tempObj.title=entry.title;    tempObj.link=entry.link;    tempObj.desc=entry.description;    tempObj.author=entry.creator;    FEED_DATA.addItem(tempObj);    }   } else if(feed_type=="ATOM") { //else if is a ATOM feed, do the same process   var rssA:Atom10 = new Atom10()   try { rssA.parse(feedData); }   catch(e:Error) {    Alert.show("Error Parsing Feed!\nInvalid link?");    return void;   }   var entrysA:Array = rssA.entries;   var tempObj2:Object;   FEED_DATA = new ArrayCollection();   if(!XMLUtil.isValidXML(feedData)) {    Alert.show("Invalid or bad feed URI or structure!");    return void;   }   for each(var entryA:Entry in entrysA)   {    tempObj2 = new Object();    tempObj2.title=entryA.title;    tempObj2.link=entryA.links[0].href;    tempObj2.desc=entryA.content;    tempObj2.author=entryA.authors;    FEED_DATA.addItem(tempObj2);    }   }   else { //impossible to find feed type...     Alert.show("Cannot detect feed type\nInvalid link?")    return void;   }   this.dispatchEvent(new Event("DataReady")); //data is now ready to be used! listen this event to access data!   } } }

       

      That would be the AS3...pretty self explanatory.

       

       

      Now...my Cross Domain Policy...I'm not very familiar with this...so I'm not sure if I'm doing this right, or if I understand this...I'm used to pHp...

       

       

      So.....What am I to do to deliver these RSS feeds properly? Any help is greatly appreciated.

       

      Thank you in adavnce.

        • 1. Re: Crossdoman and HTTPS reference issues.
          vsalrhal1 Level 1

          Hmm....I guess that came through a bit mangled....I'm sorry for the inconvenience.

           

          What I know >

           

          Works fine locally, calls RSS without issue.

           

          On my website, has the security issue.

           

          crossdomainpolicy.xml is sitting in the root of the web page.

           

          Am I supposed to make a call to this file? if so - what's the syntax for it.

           

           

          thank you.

          • 2. Re: Crossdoman and HTTPS reference issues.
            levancho Level 3

            crossdomain.xml file has to be sitting on the server that serves you RSS feed, not the server that you have SWF deployed at

            sometimes thats not possible, especially if feed is from some unknown source,but there is a workaround,

            what you can do is a write simple server code, for example in php that you can deploy on same server that your SWF file and that php file can proxy all your request to whatever other domain you want, SWF will not complain because you will not be calling  original source directly,.

            BlazeDS has that "proxying" feature built in but I think its an overkill to deploy blazeDS just for that purpose.

            • 3. Re: Crossdoman and HTTPS reference issues.
              vsalrhal1 Level 1

              Levancho -

               

              Thanks for your timely response, you've brought clarity into a dark-clouded room.

               

              That's basically what I figured would end up being my asswer...which is absolutely a killer...

               

              I manage a few websites right now that are fairly outdated, and, although we're in the middle of reconstructing, and rebuilding, the pages are not being held on a server that is supporting pHp...why you might ask? because prior to my working here, no one else had ever caught it, nor had requested it...I guess no one uses forms over here and just e-mail links...(lol?)...

               

              so I was just trying to manifest a work around without using pHp proxy calls...

               

              but I'm guessing that won't be possible, as I'm assuming that the swf pulling the RSS from...say....CNN, doesn't have a crossdomainpolicy written to exclusively allow me access..as I understand it.

               


              Therefore, I have two options >

               

              Feed from a server allowing *.com, (basically wildcard for all websites ending in .com)...or, I need to get my server-host on placing us into a pHp enabled server before the weekend is over...Would that be correct?

               

              And if so, I will close the question out after you've responded....or anyone for that matter.

               

              Thank you in advance.

              • 4. Re: Crossdoman and HTTPS reference issues.
                levancho Level 3

                or you can purchase "CNN" and make modification to their crossdomain.xml file

                 

                there is actually another "exoperimental way of duing it"

                what if you make a reuqestio via javascript and than pass that xml to SWF ?

                that should work, even though I never tried it myself.

                • 5. Re: Crossdoman and HTTPS reference issues.
                  levancho Level 3

                  actuall , I just remebered, you might want to try yahoo pipes http://pipes.yahoo.com/pipes/

                   

                  it is lot more than just being a proxy, and sounds like nailing a pushpin with sledge hummer, but it should work .

                  • 6. Re: Crossdoman and HTTPS reference issues.
                    vsalrhal1 Level 1

                    I tried to do it the Javascript way, but the functionality was poor and the delivery wasn't consistant. It would give me a "Proxy Request Error: Server Requires Authentication"...which came down to the fact that our router has our network locked down...so I'm over that.

                     

                    I'll just have the web company switch our pages over to a MySQL & pHp Integrated database...

                     

                    Come to think of it, I should probably just re-do it all in Ruby.

                     

                    Moreover;

                     

                    I think that yahoo! pipes is very limited on what it allows me to parse / etc .... I'll have to look more into it..., as I don't know much, but I did come across it once-upon-a-time.....I'll close this out now.

                     

                    thank you for your help Levancho.