Hello since there is now 7.x-3.0-beta1, is there any plans on someone updating the module?
Will the task be challenging in a particular way? I cant wait to test amf in d7.

CommentFileSizeAuthor
#16 amfphp_server.zip88.91 KBsylvain lecoy
#13 amfphp_server.zip431.21 KBsylvain lecoy

Comments

sylvain lecoy’s picture

subscribing..

I am writing a d7 version for service 3.0

Will update this post then.

imp7’s picture

that's exciting, I am not much of a coder but cant wait to test things :)

RAFA3L’s picture

subscribing..

TheWizz’s picture

subscribe

carlosg2’s picture

subscribe

autodidactic’s picture

Subscribed

biteuljiouce’s picture

subscribing..

jyee’s picture

subscribing

sylvain lecoy’s picture

I have a working copy of the AMF Server (with Service 7.0-dev) but I need some clean-up to post the code (I have issues in configuring the server: admin side).

You can have a demo of a flash drupal 7 driven website with Services 3.0 and AMF Server here: http://www.teorestaurant.com/

Once I'll finish the clean-up I can post the code then the maintainer can commit to cvs.

imp7’s picture

looking great Sylvain Lecoy, nice deeplinking.

I prefer flash sites to be stage.scaleMode = StageScaleMode.NO_SCALE , although I cant read the language, its impossible to read on a small window.

Cant wait to test Services 3.0 and amf.

nexus74’s picture

chompin at the bit for AMFPHP for D7....

snelson’s picture

Does anybody have any AMFPHP for D7 code to start with? Doesn't even need to be clean, but it'd be great to have somewhere to start from. I'll get a beta release up in the next week ...

sylvain lecoy’s picture

StatusFileSize
new431.21 KB

Here is my version of amfphp_server.

I included the library and removed the fancy stuff who dealed with php4 (and good riddance !). Since drupal 7 requieres php5, I optimized some part of the lib which I think can be included in the module since the version change very few and the project has become very stable.

The configuration is not working (I don't know why but the module base is working)

TheWizz’s picture

I tried your amfphp_server.zip in D7 with the current RC of Services, but couldn't make it work. Is there a complete working sample somewhere (including Flash or Flex code)? Or perhaps a screen-cast or tutorial on how to put all the pieces together?

FYI, I have successfully used AMFPHP under Drupal 6, where it integrates nicely with Views. I haven't found any Views integration in the D7 version. Perhaps those parts just aren't there yet?

-JM

asimov6’s picture

I also tried the module in the zip file and couldn't get it to work at first. Then I discovered that while the module is named "amfphp_server", the code in AMFPHPGateway.php referes to the modulename as "amfphp". When I corrected this, the module started to work.

sylvain lecoy’s picture

StatusFileSize
new88.91 KB

Oops you're right asimo, forgot to change the old repository.

Here is the archive with the changes.

Do not forget to put your endpoint in debug mode (service 3 feature) to connect from IDE: it will auto turn on the debug for AMFPHPGateway.

@impl7: I don't like the way my website scale as well, this is requested from my client but I will suggest him again to change for something better.

@snelson: I have some clean-up to do, and make the configuration working (the form doesn't display in the endpoint settings but I can't figure out why).

Do you need a co-maintainer ? I have some ideas to write tests for this module (flash based) and improves the Flash/Flex handling (e.g. Flex needs uid to identify objects but Flash doesn't then its a feature we can skip in case of flash based client).
I have written some function to set the explicitType and then retrieve native Flash class client side. The mapping is basically done with Drupal entities (User class for client, Node class in flash, etc.)

TheWizz’s picture

@asimov6: Then I discovered that while the module is named "amfphp_server", the code in AMFPHPGateway.php referes to the modulename as "amfphp".

Yes, I figured that one out - assuming you're referring to this line:

require_once drupal_get_path('module', 'amfphp_server') . "/amfphp/core/amf/app/Gateway.php";

However, I still can't figure out how to make it DO something. I can get to the "amfphp and this gateway are installed correctly" page, but that's pretty much it. Clicking "Load the service browser" just gets me a "page not found". Is there something like a service browser that allows me to see and test the RPC operations? In the D6 version there were functions such as node.get, views.get, etc. Is this still there (e.g., Views integration)? The configuration where this was set up in D6 doesn't seem to be there any more.

A simple, working example would probably do wonders in allowing me to figure this out. Or if someone has the time to write up a brief tutorial on the steps required to get something very basic working, end to end. I've done both straight AMFPHP (without Drupal) as well as BlazeDS (Adobe's Java base counterpart), so I'm quite familiar with the concepts. I think I just need a little nudge in the right direction to actually get this off the gound.

-JM

TheWizz’s picture

Hmm, actually think that it *is* working, sort-of. When attempting this call from Flash

drupal.call("system.connect", responder);

I get a 401 response with the description

Access denied for user 0 "anonymous"
"/Applications/MAMP/htdocs/d7/sites/all/modules/services/services.runtime.inc"

So I believe the call is getting through, but runs into some authentication problem. I run this test from Flash debugger. I.e., *not* from Flash embedded in a web page. I don't know how to handle the authentication in this case. Ultimately, I want to make the service calls from Adobe AIR, so hopefully this can be accomplished somehow.

sylvain lecoy’s picture

Ok basically its more a Service module issue that you encountered.

When you set an endpoint, you have to tell what methods will be avialable on your endpoint by going to Resource tab. Here you can thick or not which methods you want to make visible for your endpoint. Service 3 has changed the way you provide accesses.

Views integration is part of the service module as well, amfphp_server, like the previous amfphp for drupal 6, is really just an adapter to connect flash to php. From my last experience, they didn't implemented yet Views service as wiews is not very stable for now.

TheWizz’s picture

I see. Any idea how I could authenticate from a Flash/AIR client using only AMF protocol? Or do I *have* to do this using a browser before starting to communicate frmo Flash (which pretty much rules out AIR, I guess)?

-JM

sylvain lecoy’s picture

Again, this module is just a wrapper to make your application communicate with drupal through AMF3.0. It allows Object serialization/deserialization, object mapping (as3 classes to entity), and that's it.

In flash side you can set a header in the NetConnection object, and read it from php. Services implements two authentication methods: OAuth and Session, respectively OAuth Authentication module and Session Authentication module (which are packaged in the Service module).

TheWizz’s picture

I've made some progress, and believe I have the authentication part working. Now I'm trying to make a successful service call through AMF. I have two services configured, one REST service called "rest" and an AMFPHP service called "services". I can successfully make a REST call as follows:

http://localhost:8888/d7/rest/node/1

What would be the corresponding Flash call to the "services" service? I've tried various permutations of the call parameters, such as

d7.call("node", responder, "view", 1);

where d7 is the NetConnection connected to "http://localhost:8888/d7/services". Is there any documentation or pointers anywhere as to what I can pass as parameters when I call the service?

-JM

sylvain lecoy’s picture

here is my class to communicate with:

package fr.teo.site.services
{
  import flash.net.NetConnection;
  import flash.net.Responder;
  import flash.net.registerClassAlias;
  
  import fr.teo.site.events.ActualiteEvent;
  import fr.teo.site.events.MenuEvent;
  import fr.teo.site.services.vo.ArticleVO;
  import fr.teo.site.services.vo.MenuVO;
  
  import org.drupal7.fields.ImageField;
  import org.drupal7.fields.LongTextWithSummaryField;
  import org.robotlegs.mvcs.Actor;
  
  public final class AMFPHPGateway extends Actor implements ITeoService
  {
    private var connection:NetConnection = new NetConnection();

    public function AMFPHPGateway()
    {
      connection.connect('/amfphp');
      registerClassAlias('org.drupal.article', ArticleVO);
      registerClassAlias('org.drupal.menu', MenuVO);
      registerClassAlias('org.drupal.fields.image', ImageField);
      registerClassAlias('org.drupal.fields.text_default', LongTextWithSummaryField);
    }
    
    public function getActualites():void
    {
      var responder:Responder = new Responder(getActualitesResult, getActualitesStatus);
      connection.call('teo.actualites', responder);
    }
    
    public function getActualitesResult(articles:Array):void
    {
      dispatch(new ActualiteEvent(ActualiteEvent.RETRIEVE_ACTUALITE, Vector.<ArticleVO>(articles)));
    }
    public function getActualitesStatus(obj:*):void
    {
      var debug:Boolean = true;
    }
    
    public function getMenus():void
    {
      var responder:Responder = new Responder(getMenusResult, getMenusStatus);
      connection.call('teo.menus', responder);
    }
    
    public function getMenusResult(menus:Array):void
    {
      dispatch(new MenuEvent(MenuEvent.RETRIEVE_MENU, Vector.<MenuVO>(menus)));
    }
    public function getMenusStatus(obj:*):void
    {
      var debug:Boolean = true;
    }
  }
}

In your case it should be .call("node.view", responder, 1);

TheWizz’s picture

Many thanks or your response. You put me on the right track again. However, after some spelunking inside the services module, I came to the conlusion that the proper syntax should really be

d7.call("node.retrieve", responder, 1);

since "node.view" gave me the same problem as before. Can you confirm my findings, and that the proper syntax should indeed be "node.retrieve"? At least this does work and returns the contents of node 1. Where would be the proper place to look for the various nouns and verbs being used here? Incidentally, just looking at the UI in the services module seems to agree with my findings, as the operations on the "node" resource are named "create", "retrieve", "update", "delete" and "index". Presumably those are the exact actions available pn the "node" resource.

BTW, is it possible to control user access rights to these operations? I.e., I may want all logged in users to "retrieve", but only users with specific roles to "update". I guess this is more a general Services question than AMFPHP related, though.

Finally, many thanks for your detailed write-up titled "Class Mapping from Drupal Entities to Flash Object" at http://drupal.org/node/1048838

TheWizz’s picture

It seems that the error checking in amfphp_server_method_call could be improved to avoid the difficulty I had. Passing the wrong operation name currently results in an "Access denied for user Xxx" error being returned to Flash, which is misleading in that it implies some kind of permission error. The reason for this is that the $controller being passed to services_controller_execute is undefined in this case, causing the call_user_func_array call to return un-TRUE. I propose instead checking for this condition in the function that calls services_controller_execute from the amfphp_server.module, something like this:

function amfphp_server_method_call($method_name, $args) {
  // TODO: add the option to skip this for regular flash client. In the params
  // of the endpoint for instance.
  // convert all userid to uid
  //  $args = amfphp_server_fix_uid($args, 0);

  // Any authentication needed for Zend_AMF Server must be set in the cookies
  $auth_arguments = $_COOKIE;
  $endpoint = services_get_server_info('endpoint', '');
  $controller = services_controller_get($method_name, $endpoint);
  
  if (!isset($controller)) {
   return services_error(t('Method not found "@method"', array(
      '@method' => $method_name
    )), 401);
  }

I assume I could try to provide a patch, but it's quite a simple addition [starting from "if (!isset($controller))"], so hopefully the above snippet will do fine, assuming you like the idea.

-JM

TheWizz’s picture

I ran into trouble using the user.login function of Services under D7 through AMFPHP. The reason being the AMFPHP authenticationFilter starting the session before the user.login action regenerates the session ID, causing the session ID cookie to be set to the old session ID in the response header. My solution was to simply remove the AMFPHP authenticationFilter by commenting it out in Gateway.php. It would seem to me that the Services module already takes care of authentication anyway, so the authentication in AMFPHP appears superfluous, and in this case actually caused harm.

Does this seem to make sense, or is the AMFPHP authenticationFilter actually serving some purpose also under Services?

-JM

danielm’s picture

subscribing

ricovitch’s picture

subscribing

danielm’s picture

hello everybody,

When I use #16 amfphp_server.zip and I go to admin/config/services/services/amfphp/charset I get the following error:

Recoverable fatal error: Argument 1 passed to drupal_attributes() must be an array, null given, called in /var/www/public/includes/form.inc on line 3107 and defined in drupal_attributes() (line 2258 of /var/www/public/includes/common.inc).

Thank you for your help

Sincerely
Daniel

sylvain lecoy’s picture

Hello, The archive was actually provided with this bug. I didn't managed to know if it was Service related, drupal related, or my fault.

I will have a look this week end and get back to you.

Regards

Sylvain

kari.nies’s picture

Subscribing...

socialtalker’s picture

subscribing

rolf vreijdenberger’s picture

Hello all,

I've been pointed to this issue just a couple of hours ago so I thought I would let you know, for those interested in amf connection with drupal7, I have just released a sandbox project that is fully functional, tested, has an actionscript package ready to go along with both the D6 amfphp implementation and my amfserver D7 implementation, based on the Zend Amf engine.

It makes full use of session authentication and, here's a good thing, also for cookie disabled clients like the flash player, flash and flex authoring tool and air apps.
It's production grade and I invite you all to take a look.

see the module page for more info: http://drupal.org/sandbox/rolfvreijdenberger/1122068

cheers

giorgio79’s picture

#33
It looks like this is live http://drupal.org/project/amfserver
Awesome :D

snelson’s picture

Fantastic work Rolf ... this is exactly what AMF and Drupal needed. Many thanks! I think it now makes sense to deprecate this AMFPHP module for D7, and I'll be happy to update the project page accordingly. Do you have any plans to backport to D6? Not that its necessary, just wondering ...

rolf vreijdenberger’s picture

Hi Snelson,

Thanks and also many thanks to YOU for your work! We have all happily used the amfphp library for quite a time.
I might port to 6.x-3.x version of services, but I am not sure about it yet.
D6 has a fine version of amf integration and I am not sure that many people would mind using services version 2 with D6 and amfphp.
That said, the backport to 6.x-3x would not be that complicated since it will use other means of authentication than the 2.x version etc, so if there's a demand, I would be willing to do so.

cheers

nexus74’s picture

Issue tags: +menu, +flash, +navigation, +drupal 7

I had a Flash menu that displayed all the primary links in D6 using AMFPHP and Services. I'm trying to this in D7 but I don't see any service for "menu.get." I have Services and the new amfserver modules installed. Is there an equivalent to "menu.get" ?

Here's my AS3 code:

// Declare our baseURL and gateway string.
var baseURL:String = "http://localhost:8888/d7";
var gateway:String = baseURL + "/services/amfphp";
var sessionId:String = "";


// Declare our Drupal connection
var drupal:NetConnection = new NetConnection();
drupal.objectEncoding = ObjectEncoding.AMF3;

// Connect to the Drupal gateway
drupal.connect( gateway );

// Set up our responder with the callbacks.
var responder:Responder = new Responder( onConnect, onError);

// Connect to Drupal
drupal.call("system.connect", responder);

// Loads a Drupal node.
function loadMenu( menu_id:String )
{
	// Set up our responder with the callbacks.
	var nodeResponse:Responder = new Responder( onMenuLoad, onError);
	// Call Drupal to get the node.
	drupal.call( "menu.get", nodeResponse, sessionId, menu_id );
}

// Called when Drupal returns with a successful connection.
function onConnect( result:Object )
{
	// Set our sessionId variable.
	sessionId = result.sessid;
	trace("We are connected!!!");
	trace("Session Id: " + sessionId);
	// Load menu
	loadMenu("primary-links");
}

// Called when Drupal returns with our node.
function onMenuLoad( menu:Object )
{
	for(var i=0; i< menu.length; i++)
	{ 
		trace(menu[i].title +" | " + menu[i].href);
		var menuItem:MenuItem = new MenuItem();
		addChild(menuItem);
		menuItem.label.text = menu[i].title;
		menuItem.x	=	50;
		menuItem.y 	=	(menuItem.height + 4) * i + menuItem.height / 2;
		menuItem.buttonMode = true;
		
		if(i==0) 
		{
			menuItem.addEventListener(MouseEvent.MOUSE_DOWN, clicked0);		
		}
	
	}
	
}

function clicked0(e:MouseEvent):void
{
	//e.target.visible = false;
	trace("you clicked object 0")
}


// Called when an error occurs connecting to Drupal.
function onError( error:Object )
{
	
	for each (var item in error)
 	{
	trace(item);
	}
}

The above code successfully connects to Drupal 7.

Thank you

rolf vreijdenberger’s picture

hi Nexus,

this is more of a support request for services, so this isn't the place to post. I'm guessing you don't yet know this :) It has nothing to do with either amfphp or amfserver.

There isn't a menu resource yet in D7 services, but if/when it's available you will be able to consume the service via amf.
You can check if there is an issue created in the services issue tracker, it's probably a feature request already.

cheers

nexus74’s picture

Rolf,

Thank you for your response. Ok, I'll keep a look out for the menu service. Thanks for the heads up

-N