Chaining HTTP Requests / DynamicURLRequest

8 views
Skip to first unread message

Duro

unread,
Feb 4, 2010, 10:09:18 PM2/4/10
to Swiz Framework
I am trying to grab several differnt RSS feeds and then merge them
together. My thoughts were to use the CommandChain in swiz to grab
them all and then merge them after the chain completes. I'm wondering
what the best way to do this is. I need to be able to enter the feed
URL's at runtime.

I noticed the DynamicURLRequest object in the framework, but it does
not return an AsyncToken to be used with the CommandChain.

Any ideas?

Ben Clinkinbeard

unread,
Feb 4, 2010, 11:41:01 PM2/4/10
to swiz-fr...@googlegroups.com
I just committed this functionality to GitHub today, so I am providing the SWC here. Basically, we've created a generic way to chain actions, and events are the first implementation of that. My personal need for this and how I am using it now was/is to chain together several events that I [Mediate]. Construction of the chain looks like this.

// "this" is the IEventDispatcher on which Swiz is defined, but really just needs to be a IED that each point in the chain has access to
var ec:EventChain = new EventChain( this );
ec.addMember( new DataRequestEvent( DataRequestEvent.LOAD_CONFIG ) );
ec.addMember( new DataRequestEvent( DataRequestEvent.FETCH_CREDENTIALS ) );
ec.addMember( new DataRequestEvent( DataRequestEvent.FETCH_INITIAL_DATA ) );
ec.start();

The handler for the first event in the chain is in my ConfigController and looks like this.

[Mediate( "DataRequestEvent.LOAD_CONFIG" )]
public function loadConfig( event:DataRequestEvent ):void
{
    // uru is an injected URLRequestUtil ([Inject] public var uru:URLRequestUtil;) which is defined in a BeanProvider
    // [ event ] ensures the event will be relayed to my result handler, along with the ResultEvent
    uru.executeURLRequest( new URLRequest( "config.xml" ), loadConfig_result, loadConfig_fault, null, null, [ event ] );
}

DataRequestEvent extends ChainStepEvent, which is another Swiz class. My handler then looks like this

protected function loadConfig_result( event:Event, dre:DataRequestEvent ):void
{
   // do stuff

   // mark this event complete, which will trigger chain to proceed
   dre.complete();
}

I realize this may seem like a lot here, and it uses some new things that haven't been documented or explained yet (because they haven't been released yet), but it really is very simple and powerful once you get your head around it. Feel free to ask further questions as needed. :)

Ben




--
You received this message because you are subscribed to the Google Groups "Swiz Framework" group.
To post to this group, send email to swiz-fr...@googlegroups.com.
To unsubscribe from this group, send email to swiz-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/swiz-framework?hl=en.


swiz-framework.swc

Roland Ringgenberg

unread,
Feb 5, 2010, 8:14:06 AM2/5/10
to Swiz Framework
Cool, I like that!
:-)

Did someone already thought about using some sort of state pattern
around this?
Say for example if you have a transition from state C to state E run
eventChain1 etc

Cheers,
Roland

On Feb 5, 5:41 am, Ben Clinkinbeard <ben.clinkinbe...@gmail.com>
wrote:

> > swiz-framewor...@googlegroups.com<swiz-framework%2Bunsubscribe@go oglegroups.com>


> > .
> > For more options, visit this group at
> >http://groups.google.com/group/swiz-framework?hl=en.
>
>
>

>  swiz-framework.swc
> 69KViewDownload

Ben Clinkinbeard

unread,
Feb 5, 2010, 8:59:47 AM2/5/10
to swiz-fr...@googlegroups.com
Hi Roland,

We've got lots of ideas around this functionality, but the example I showed is where it currently stands. Rest assured though, things will get better over time. :)

Ben



To unsubscribe from this group, send email to swiz-framewor...@googlegroups.com.

Chris Scott

unread,
Feb 5, 2010, 9:02:54 AM2/5/10
to swiz-fr...@googlegroups.com
Um, big things are coming. But you need to wait for em.

:)

-chris

On Fri, Feb 5, 2010 at 8:14 AM, Roland Ringgenberg <rin...@gmail.com> wrote:
To unsubscribe from this group, send email to swiz-framewor...@googlegroups.com.

Duro

unread,
Feb 5, 2010, 3:38:36 PM2/5/10
to Swiz Framework
Thanks guys. My last question is this. Do you think that using the
1.0.0-alpha is a bad idea on a production project that goes live in a
week. It's a pretty small widget, but still, it needs to be production
ready by the 15th. I'm happy to be an alpha tester, but I guess my
biggest concern is if I run into problem, that I won't be able to get
them resolved quick enough to get this baby live.

Thoughts?

Ben Clinkinbeard

unread,
Feb 5, 2010, 3:49:43 PM2/5/10
to swiz-fr...@googlegroups.com
Chris and I are using it on a production project but we don't go live that soon. The 15th is actually our target date for the beta release, so things should be pretty stable by then. Without knowing all of your requirements its hard to say, but I feel like the code is pretty solid.

Ben




Duro

unread,
Feb 5, 2010, 4:06:14 PM2/5/10
to Swiz Framework
Well I think I've managed to start getting this working with 0.6.4. I
created a delegate and a method that takes a url as an argument. This
method creates an HTTPService object, assigns the url, and returns the
AsyncToken from the 'send' method of the HTTPService object.

I have this running using the CommandChain just fine, or at least all
three HTTP requests are sent off, and the results handler is
triggered. However, for some reason the results handler is getting
called twice for every request (3 requests gets me 6 calls to the
results handler). Any ideas on why that might be?

Any help is appreciated.

On Feb 5, 12:49 pm, Ben Clinkinbeard <ben.clinkinbe...@gmail.com>
wrote:


> Chris and I are using it on a production project but we don't go live that
> soon. The 15th is actually our target date for the beta release, so things
> should be pretty stable by then. Without knowing all of your requirements
> its hard to say, but I feel like the code is pretty solid.
>
> Ben
>

> On Fri, Feb 5, 2010 at 3:38 PM, Duro <a...@duromedia.com> wrote:
> > Thanks guys. My last question is this. Do you think that using the
> > 1.0.0-alpha is a bad idea on a production project that goes live in a
> > week. It's a pretty small widget, but still, it needs to be production
> > ready by the 15th. I'm happy to be an alpha tester, but I guess my
> > biggest concern is if I run into problem, that I won't be able to get
> > them resolved quick enough to get this baby live.
>
> > Thoughts?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Swiz Framework" group.
> > To post to this group, send email to swiz-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > swiz-framewor...@googlegroups.com<swiz-framework%2Bunsu...@googlegroups.com>

Duro

unread,
Feb 5, 2010, 4:38:06 PM2/5/10
to Swiz Framework
Never mind guys, apparently this is a known bug in 3.4 and 4.0-beta2.
If an explicit result and fault handler for the HTTPService object is
not set, it calls the Async responder twice.

See: http://bugs.adobe.com/jira/browse/SDK-22333 (for 4.0-beta2) and
http://bugs.adobe.com/jira/browse/SDK-22883 (3.4)

The workaround is to explicitly add the following when building the
HTTPService object:

httpService.addEventListener(ResultEvent.RESULT, function():void{});
httpService.addEventListener(FaultEvent.FAULT, function():void{});

Adam

Reply all
Reply to author
Forward
0 new messages