Local Vs Remote.

1 view
Skip to first unread message

Gavin Baumanis

unread,
Jun 9, 2010, 8:46:19 AM6/9/10
to galaxy-dev
I have been having some issues lately with getting a remote service to
behave correctly.
I am sureit is doing everything it should be doing - I am pretty sure
it is me - since this is the first time I have tried to create and
even use a remote service for that matter.

I have an object defined, "LoginService".
The user object contains several methods for, you guessed it,
authenticating a user for access to an application.

Currently the LoginService cfc takes a username and password pair and
attempts to authenticate those credentials against an LDAP service.

The return type of the LoginService cfc is a USER object.

The user object has many properties and for ease of reading we'll
limit it to just a few;
username,
firstname,
surname and finally,
isauthenticated which is a boolean, all other properties in this
example are strings.

isauthenticated gets set as true if the username/password pair match
corectly. Other appropriate user details get set also in the user
object after querying the LDAP service for exra attributes after a
successful username/password match.

Currently, this all works fine and dandy if I am using the CFC as a
local service.
But when I invoke the CFC as a remote service it all comes to great
and sudden stop.

SO what I need to know is;
Should the loginservice only return the is authenticated value (a
single property) - and then I can requery from within the application
proper for all other attributes required?

Or alternatiively what do I need to do to have my remote service
return more than "a" property?

As always - thanks in advance!

Robin Hilliard

unread,
Jun 9, 2010, 5:49:42 PM6/9/10
to galax...@googlegroups.com
On 09/06/2010, at 10:46 PM, Gavin Baumanis wrote:

> SO what I need to know is;
> Should the loginservice only return the is authenticated value (a
> single property) - and then I can requery from within the application
> proper for all other attributes required?

Remember that the remote call uses web services, so structs and arrays will pose no problem. We have talked about a plugin to support CF typed objects over a remote call, but I'd like people to think of services normally being as platform-neutral as possible (think of the Yahoo APIs for example).

Robin

Gavin Baumanis

unread,
Jun 9, 2010, 6:25:30 PM6/9/10
to galaxy-dev
Hi Robin,
Thanks for the reply.
I have never used a web service before - so I have no idea what can
successfully be used.
But just to crystallise things in my mind - and for the benefit of any
who come across the group later on...

Am I right in believing I could do this, then?

<cffunction .....>
<cfscript>
str_user = StructNew();
StructInsert(str_user, "isAuthenticated", qry_loginResult);
StructInsert(str_user, "firstname",
qry_userdetails.firstname);
StructInsert(str_user, "surname", qry_userdetails.surname);
StructInsert(str_user, "......", qry_userdetails.......);
</cfscript>
<cfreturn str_user />
</cffunction>


Gavin

Phil Haeusler

unread,
Jun 9, 2010, 7:23:05 PM6/9/10
to galax...@googlegroups.com
Hi Gavin

Another way I believe you can successfully pass a CFC back from Galaxy
is to define a <CFPROPERTY> tag in your remote galaxy CFC that
references the CFC you wish to return.

For example in your LoginService.cfc, just add the following

<cfproperty name="user" type="path.to.user.cfc">

The purposes this serves is to explicitly inform ColdFusion to include
the definition of your User.cfc within the WSDL that it generates for
LoginService.cfc. If you don't in the Web Service call ColdFusion would
return a typed object that isn't defined in the WSDL and the calling
service wouldn't be able to understand it - which is the situation
you've come across. (fyi - The name="user" is just a placeholder here)
In a non-galaxy CFC you would specify the user.cfc as a returntype on
your remote method to achieve the same result, however as Galaxy only
exposes a single remote method send() you need to explicitly list it here.

Now, when you call the remote Galaxy service you should be able to
successfully get the User object back to the calling ColdFusion code.
Be aware that only the public properties that have been defined with a
<cfproperty> within User.cfc will be returned by ColdFusion

However, the important thing to recognise now is that the User object
you get back to your calling code is a User Java object not a User CFC
object. This means that you'd need to convert that back to a CFC if you
wanted to user the actual methods on the CFC.

But this same conversion would also be required if you serialised the
object to a Plain-Old struct as per Robin's example.

However, in both cases, if you just wanted to use the returned object as
a pure value-object (i.e. just referencing the properties on the object,
and not relying on any methods) then with either method no further
conversion is necessary.

If you are interested, i've got some code that converts a returned Java
CFC back into a regular ColdFusion CFC - it's quite simple, and i think
would actually make a nice optional plug-in into Galaxy at some time in
the future.

I hope you can follow that - shout out if i just confused your further.

Phil

Gavin Baumanis

unread,
Jun 12, 2010, 8:19:35 AM6/12/10
to galaxy-dev
Hi Everyone again,

Currently in my (LDAP-login) CFC that works correctly, locally - I
have the following kind of lines in the CFC constructor;

<cfset this.userid = "">
<cfset this.userdn = "">
<cfset this.givenname = "">
<cfset this.sn = "">
<cfset this.userIsAuthenticated = "false">

I wan to return all of these values to the calling code.
So I have created a cfproperty tag for them all;

<cfproperty name="cn" type="string" default="">
<cfproperty name="dn" type="string" default="">
<cfproperty name="givenname" type="string" default="">
<cfproperty name="sn" type="string" default="">
<cfproperty name="userIsAuthenticated" type="boolean" default="">

My question is do I still need the "this....." declarations? Ot dos
the cfproperty tag now take care of that?

As usual - thanks! - Gavin.
Reply all
Reply to author
Forward
0 new messages