Ajax calls through fw1 or remote proxy

898 views
Skip to first unread message

Phil Cruz

unread,
Mar 3, 2010, 1:50:22 PM3/3/10
to framework-one
I want to implement a jqGrid like discussed in this article,
http://www.coldfusion-ria.com/Blog/index.cfm/2009/1/27/Using-jQuery-based-jqGrid-with-ColdFusion-Part-1.

In the example, the grid is loaded by calling a CFC that has remote
access, 'Users.cfc?method=getUsers'. The getUsers() method directly
queries the database for the data. To implement this in my application
I think I have a couple of options

1. Use a ColdSpring-generate remote proxy - Unlike the simple example,
I won't have a single CFC that hits the database to get the data.
There will be a userService.cfc which has an instance of a userDAO.cfc
(autowired by CS) that will grab this data. I can't hit the
userService.cfc directly because it wouldn't be initialized so that's
where the remote proxy comes in.

2. Make the call through fw1 - I would still have the userService.cfc
and userDAO.cfc but create an fw1 action that would return the data,
i.e. index.cfm?action=user.getUsers&returnformat=json.

Any thoughts on which approach might be better? I'm leaning towards
option 1.

-Phil

Sean Corfield

unread,
Mar 10, 2010, 2:50:14 AM3/10/10
to framew...@googlegroups.com
On Wed, Mar 3, 2010 at 10:50 AM, Phil Cruz <ph...@philcruz.com> wrote:
> Any thoughts on which approach might be better? I'm leaning towards
> option 1.

I strongly dislike pure data calls going through an MVC framework.
Barney Boisvert posted a good blog entry on this. Much better to hit a
CFC directly for pure data calls (and FW/1 supports that automatically
without you needing to do anything - just call the CFC from JavaScript
and FW/1 will get out of your way!).
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Phil Cruz

unread,
Mar 10, 2010, 3:36:19 PM3/10/10
to framew...@googlegroups.com
Yeah, my gut was telling me to avoid that approach. I searched Barney's site for a blog entry on that but didn't come up with anything. If you have a link to the blog entry that would be great. 

So if I hit a CFC directly, it does seems like I need to be using ColdSpring/remote proxy (because the actual service CFC will have dependencies) or am I over-complicating things? (I mean I could have a very simplistic CFC that returns data just like in the example, but in practice that's not the case).

-Phil


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


kibaniwi

unread,
Mar 10, 2010, 4:38:01 AM3/10/10
to framework-one
I imagine you might be leaning towards option 1 because as a smart
developer you want to decouple your web services from your front-
controller application framework. I like to think of it as a
completely different 'channel'. But what say you wanted to take
advantage of things you have already set up in fw1, like security or
logging?

This is where AOP comes in, if you haven't already considered it. Your
proxy can expose your service code, at the same time intercepting
requests and adding calls to security and/or logging methods that are
already set up in your app. Similar to startXX and beforeXX I guess.
This can be done seamlessly so you never have to change your base
code. It is sweet when you set it up - you can add web services just
by using a naming convention and know that ancillary functions will
'just work'.

e.g. an aop proxy can add arguments to a function so all your web
service requests expect username/password even though your base code
does not.

Darren

On Mar 10, 7:50 am, Sean Corfield <seancorfi...@gmail.com> wrote:


> On Wed, Mar 3, 2010 at 10:50 AM, Phil  Cruz <p...@philcruz.com> wrote:
>
> > Any thoughts on which approach might be better? I'm leaning towards
> > option 1.
>
> I strongly dislike pure data calls going through an MVC framework.
> Barney Boisvert posted a good blog entry on this. Much better to hit a
> CFC directly for pure data calls (and FW/1 supports that automatically
> without you needing to do anything - just call the CFC from JavaScript
> and FW/1 will get out of your way!).
> --
> Sean A Corfield -- (904) 302-SEAN

> Railo Technologies US --http://getrailo.com/
> An Architect's View --http://corfield.org/

Sean Corfield

unread,
Mar 10, 2010, 6:49:12 PM3/10/10
to framew...@googlegroups.com
On Wed, Mar 10, 2010 at 12:36 PM, Phil Cruz <ph...@philcruz.com> wrote:
> Yeah, my gut was telling me to avoid that approach. I searched Barney's site
> for a blog entry on that but didn't come up with anything. If you have a
> link to the blog entry that would be great.

Oops! It was Brian Kotek, not Barney Boisvert:

http://www.briankotek.com/blog/index.cfm/2007/7/25/AJAX-Data-Requests-vs-AJAX-Content-Requests

> So if I hit a CFC directly, it does seems like I need to be using
> ColdSpring/remote proxy (because the actual service CFC will have
> dependencies) or am I over-complicating things? (I mean I could have a very
> simplistic CFC that returns data just like in the example, but in practice
> that's not the case).

You will need a remote proxy. I personally don't like the way
ColdSpring does this so I tend to handcode specific remote API CFCs
for my services as a whole (instead of the 1:1 mapping ColdSpring
creates).

Judith Barnett

unread,
Mar 10, 2010, 6:59:27 PM3/10/10
to framew...@googlegroups.com
Do you have an example of this you could share?

Sean Corfield

unread,
Mar 10, 2010, 8:05:39 PM3/10/10
to framew...@googlegroups.com
On Wed, Mar 10, 2010 at 3:59 PM, Judith Barnett <jmba...@gmail.com> wrote:
> Do you have an example of this you could share?

It depends on what the requirements are for the remote API - that's
why I hand code them (and they're different for every project).

The general pattern of a remote API method is:

<cfset var fooService = application.beanFactory.getBean( 'fooService' ) />
<cfset var data = fooService.getSomeData( someArgs ) />
<!--- massage the data into the appropriate format for the remote API
result --->
<cfreturn massagedData />

For example, you might have a UserService that returns a User bean but
you might return just a struct from the remote API containing just id,
firstName, lastName.

Dan Vega

unread,
Mar 16, 2010, 9:48:06 AM3/16/10
to framework-one
I have a similar problem. I am calling a cfc remote method directly in
a view via javascript

jquery grid excerpt

url:'cfc/Http5.cfc?method=get&theUrl=#rc.sURL#&_cf_nodebug=true

When I make the call the request seems to run fine but in firebug I
see the following error.

Exception in

The action dashboard.index failed.
Element USERNAME is undefined in VARIABLES.

The default action controller/action in my application is
dashboard.index. How can I avoid this so that my call to the remote
method on my url just returns me data.


On Mar 10, 9:05 pm, Sean Corfield <seancorfi...@gmail.com> wrote:


> On Wed, Mar 10, 2010 at 3:59 PM, Judith Barnett <jmbarn...@gmail.com> wrote:
> > Do you have an example of this you could share?
>
> It depends on what the requirements are for the remote API - that's
> why I hand code them (and they're different for every project).
>
> The general pattern of a remote API method is:
>
> <cfset var fooService = application.beanFactory.getBean( 'fooService' ) />
> <cfset var data = fooService.getSomeData( someArgs ) />
> <!--- massage the data into the appropriate format for the remote API
> result --->
> <cfreturn massagedData />
>
> For example, you might have a UserService that returns a User bean but
> you might return just a struct from the remote API containing just id,
> firstName, lastName.
> --
> Sean A Corfield -- (904) 302-SEAN

> Railo Technologies US --http://getrailo.com/
> An Architect's View --http://corfield.org/

Nando

unread,
Mar 17, 2010, 12:34:38 PM3/17/10
to framew...@googlegroups.com
I'm also trying to implement an ajax call to a remote cfc, and it seems fw1 may be intercepting the request as it would for any .cfm template. I'm a little confused by what's going on here, so I thought I take a step back and ask what the proper way of doing this is. I could also easily be misinterpreting something.

What I'm trying to do is upload a file "ajax style" without refreshing the page. I know it can't be done using an ajax request, but there are, for instance, jQuery plugins that utilize an iframe:


I can't seem to get this to work, no matter whether I submit the request via the framework, a stand alone .cfm file (intercepted as expected), or a remote CFC (intercepted, it seems, because I get a coldspring error out of setupApplication(), which should only be called by the framework ... ). 

Nando

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




--
Nando M. Breiter
The CarbonZero Project
CP 234
6934 Bioggio
Switzerland

+41 91 606 6372

na...@carbonzero.ch
www.carbonzero.ch

Sean Corfield

unread,
Mar 17, 2010, 11:11:04 PM3/17/10
to framew...@googlegroups.com
I'm puzzled. This is a tested - and working - scenario as far as I can
tell. There's even an example of it that ships with FW/1 (the 'remote'
example: it has a remote access CFC which it calls as a Web Service,
via Flex Remoting and as a simple, in-browser invocation of the CFC
method directly - just as you are doing).

FW/1's onRequestStart() method checks for invocations of .cfc files
and it deletes the onRequest() method specifically so that such
requests do not get intercepted.

Since you're on CF9 Dan, I wonder if it's something specific to that?
Nando, are you also on CF9?

What happens if you try to hit the CFC with that URL in your browser?

Sean

Nando

unread,
Mar 18, 2010, 1:20:50 PM3/18/10
to framew...@googlegroups.com
Sean, I'm on CF9 with this app and will try the remote example to try and narrow the problem down. It may be something else I'm running into specifically because I'm trying to upload a file via an Ajax-like method that uses an iframe to submit the request. I must admit I don't always fully understand what I'm doing ... :-)

Nando

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

Dan Vega

unread,
Mar 18, 2010, 1:52:18 PM3/18/10
to framework-one
Ok this is just weird.

I am calling the method in the browser

http://localhost/dummy/cfc/http5.cfc?method=test

<cffunction access="remote" name="test">
<cfreturn "hello world">
</cffunction>

And when I run that I am seeing the component browser login, anyone
know why that is?

On Mar 18, 1:20 pm, Nando <d.na...@gmail.com> wrote:
> Sean, I'm on CF9 with this app and will try the remote example to try and
> narrow the problem down. It may be something else I'm running into
> specifically because I'm trying to upload a file via an Ajax-like method
> that uses an iframe to submit the request. I must admit I don't always fully
> understand what I'm doing ... :-)
>
> Nando
>

> On Thu, Mar 18, 2010 at 4:11 AM, Sean Corfield <seancorfi...@gmail.com>wrote:
>
>
>
>
>
> > I'm puzzled. This is a tested - and working - scenario as far as I can
> > tell. There's even an example of it that ships with FW/1 (the 'remote'
> > example: it has a remote access CFC which it calls as a Web Service,
> > via Flex Remoting and as a simple, in-browser invocation of the CFC
> > method directly - just as you are doing).
>
> > FW/1's onRequestStart() method checks for invocations of .cfc files
> > and it deletes the onRequest() method specifically so that such
> > requests do not get intercepted.
>
> > Since you're on CF9 Dan, I wonder if it's something specific to that?
> > Nando, are you also on CF9?
>
> > What happens if you try to hit the CFC with that URL in your browser?
>
> > Sean
>

> > On Tue, Mar 16, 2010 at 6:48 AM, Dan Vega <danv...@gmail.com> wrote:
> > > I have a similar problem. I am calling a cfc remote method directly in
> > > a view via javascript
>
> > > jquery grid excerpt
>
> > >  url:'cfc/Http5.cfc?method=get&theUrl=#rc.sURL#&_cf_nodebug=true
>
> > > When I make the call the request seems to run fine but in firebug I
> > > see the following error.
>
> > > Exception in
>
> > > The action dashboard.index failed.
> > > Element USERNAME is undefined in VARIABLES.
>
> > > The default action controller/action in my application is
> > > dashboard.index. How can I avoid this so that my call to the remote
> > > method on my url just returns me data.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "framework-one" group.
> > To post to this group, send email to framew...@googlegroups.com.
> > To unsubscribe from this group, send email to

> > framework-on...@googlegroups.com<framework-one%2Bunsubscribe@goog legroups.com>

Dan Vega

unread,
Mar 18, 2010, 2:26:08 PM3/18/10
to framework-one
Just confirmed that the same cfc works fine outside of the framework.
Any ideas of why this is happening in fw1?

Dan Vega

unread,
Mar 18, 2010, 2:56:32 PM3/18/10
to framework-one
I am a big dummy, 2 many green beers yesterday :)

So Ray gave me a great idea, add a log to the top of the cfc and write
out

<cflog file="extranet" text="#serializejson(url)#">

When I did this I saw

"Information","jrpp-363","03/18/10","14:49:34","EXTRANET","{""action"":""security.login""}"

A bell went off right away, on every request I was do a security check

// force login check if section is not security
if( request.section != "security"){
if( !structKeyExists(session,"isLoggedIn") || !session.isLoggedIn )
{
redirect("security.login");
}
}

So I just made a quick addition for any cfcs to get bpypassed

// force login check if section is not security
if( request.section != "security" && request.base != "/cfc/" ){
if( !structKeyExists(session,"isLoggedIn") || !session.isLoggedIn )
{
redirect("security.login");
}
}

Sorry for the posts on issues that were my fault :)

On Mar 18, 1:52 pm, Dan Vega <danv...@gmail.com> wrote:

Sean Corfield

unread,
Mar 18, 2010, 4:26:23 PM3/18/10
to framew...@googlegroups.com
This is another reason why my thinking on controller invocation from
early lifecycle points should queue up calls for the onRequest()
processing: so you could reliably use controllers for this sort of
security without fouling up remote calls...

Sean

Scott Conklin

unread,
Dec 14, 2010, 7:04:56 PM12/14/10
to framew...@googlegroups.com
thanks for this... running into one issue
in my remote proxy, i don't seem to have access to the objectfactory.

i thought by calling the setBeanFactory() method in setupApplication i
would have access to the factory
in my remote facade.

can someone tell me the best way to gain access to this. should i add it
the application scope myself?

thanks

On 12/11/2010 12:06 AM, Sean Corfield wrote:
> On Fri, Dec 10, 2010 at 2:39 PM, Scott Conklin<socr...@sconklin.com> wrote:
>> 1) jquery grid tree:
>> -- call remote facade
>> "ajax" : {"url" : "/remote/userfacade.cfc?method=getUsers"}
> Yup. This is a data call so it should go direct to a CFC.
>
>> 2) remote/userfacade.cfc
>> 3) model/user/userService.cfc
> Yup.
>
>> b) if so, does best practice mean to have an xxFacade.cfc convention
>> for each service where necessary? or is there a better naming
>> convention?
> I tend to have a remote facade for the whole app or, if that's "too
> big", a remote facade for each "section" of the app.
>
>> c) does this belong in a "remote" dir like in the samples or could
>> this be in the model/user/ dir in this case or a services dir?
> The remote CFCs must be web accessible. Your service / model does not
> need to be.
>
>> d) i read that if wanted to invoke security, then i should pass
>> credentials on each call
> Generally, yes.
>
>> e) i have read AOP is the way to handle security in this scenario,
>> where is the best place to learn how to do this?
> Google Aspect Oriented Programming and read the ColdSpring documentation.
>
> Personally I'm not convinced that AOP is the best solution because I'm
> not convinced that auto-generated facades are the right solution. I
> generally find a custom, hand-written facade is a more appropriate
> solution - and that means custom security. But YMMV.
>
> There's no One True Way here. If your solution works for you - it's a
> solution and it's "right". No matter what solution you pick, there
> will _always_ be a "better" solution around the corner once you have
> new knowledge...
>
> (and you sent this direct to me, not to the list?)

Sean Corfield

unread,
Dec 15, 2010, 6:57:38 PM12/15/10
to framew...@googlegroups.com
On Tue, Dec 14, 2010 at 4:04 PM, Scott Conklin <socr...@sconklin.com> wrote:
> thanks for this... running into one issue
> in my remote proxy, i don't seem to have access to the objectfactory.

Question: Since your remote proxy is "outside" FW/1, how would you
expect to access the object factory?

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

> can someone tell me the best way to gain access to this. should i add it the
> application scope myself?

I would probably put it in application scope directly - and then call
setBeanFactory() to tell FW/1 about it.

(and that's the assumption ColdSpring makes about remote proxies, BTW,
so it's common practice).


--
Sean A Corfield -- (904) 302-SEAN

Railo Technologies, Inc. -- http://getrailo.com/

Scott Conklin

unread,
Dec 16, 2010, 8:49:06 AM12/16/10
to framew...@googlegroups.com
yes, realised it was a silly question after i had already posted it,
i saw later a post that telling me that i should add the beanfactory to the application scope and then tell setbeanfactory() about it
thanks...

Reply all
Reply to author
Forward
0 new messages