cancel
Showing results for 
Search instead for 
Did you mean: 

PHP Library $session->save() errors out over SSL/encryption

ofrxnz
Champ in-the-making
Champ in-the-making
So, I am currently working on a PHP-based Alfresco upload applet. 

In a non-encrypted environment, the code at the end works great, over SSL, the $session->save(); command fails.  providing the following error

500 - socket_connect() failed. Reason: () The requested address is not valid in its context.

Hunting it down, when I use  both SSL and non-SSL connections I am able to use GET/retrieve statements to retrieve data such as $repository->authenticate($user, $password); $repository->createSession($_SESSION["ticket"]); $session->getNode($spacesStore,$nodeID); and $props =  $childNode->properties;

So, I seem to be able to retrieve any data I wish from the repository using the alfresco PHP API over SSL however, $session->save(); doesn't like SSL. 

The code I am using is posted below.  First, it sets up a session with the repo using a user-session ticket generated in another applet. It then pulls the children of the designated "drop box" node to see if a file with the same name exists.  I don't want people to update/delete/overwrite files at this point.  It successfully checks polls alfresco to run a file name comparison, then begins to setup the child.  This code works great over a non-encrypted connection but, over ssl, everything works till i call $session-save().

I am running a 1028 bit RSA ssl key over port 443 using a url like the following.  https://server.company.com/alfresco/api.  Alfresco is version "Version: Labs - v3.0.0 (Stable 1526)" this test box used the windows 3.0 full installer running on win 2k3 r2.  The php server is the current version of xampp with openssl enabled. 

   try{
  
   //get configuration paramaters
   $params = &JComponentHelper::getParams( 'com_alfrescodropbox' );
   $params->merge( &$row->params );
   $repoURL =  (string)$params->get( 'Server' );
   $nodeID = (string)$params->get( 'Node');

   //setup session
   $repository = new Repository($repoURL);
   $session = $repository->createSession($_SESSION["ticket"]);
   $spacesStore = new SpacesStore($session);
  
   //find target dropbox node
   $currentNode = null;
   $currentNode = $session->getNode($spacesStore,$nodeID);
  
      /////////////////////////
     //check for file with existing name
   $children = $currentNode->children;
   foreach($children as $key=>$value){
      $broken = explode('/', $key);
      $childNode = $session->getNode($spacesStore,$broken[3]);
      $props =  $childNode->properties;
      if($props['{http://www.alfresco.org/model/content/1.0}name'] == $_FILES['uploadedfile']['name']){
         $updateError = 'We\'re sorry but, we currently do not allow users to update or delete files.  <br /> Please change the file\'s name or contact your Project Manager to remove older files';
         $this->setRedirect($link, $updateError, 'error');
         return;
      }
   }
   //////////////////////////

  
  
   //create child
   $upload = $currentNode->createChild('cm_content', 'cm_contains', 'cm_'.$_FILES['uploadedfile']['name']);
  
   //prep file metadata/conetnt
   $pathFile = $_FILES['uploadedfile']['tmp_name'];
   $content_data = new ContentData($upload, $property, $mimetype, $encoding);
   $content_data->mimetype = $_FILES['uploadedfile']['type'];
   $content_data->encoding = "UTF-8";
   $content_data->writeContentFromFile($pathFile);
  
   //prep upload packaege
   $upload->cm_content = $content_data;
   $upload->cm_name = $_FILES['uploadedfile']['name'];
   $fileName = (string)$upload->cm_name;
       
    //push data to alfresco
    $session->save(true);
    }
    catch (Exception $e) {
       JError::raiseError(500, $e->getMessage());
     }
10 REPLIES 10

sonanaren
Champ in-the-making
Champ in-the-making
Hi ofrxnz,

Are you accessing Alfresoc repository remotely, how did u achieve the same?

i am trying to connect to remote alfresco repository for performing some action thru PHP application (remotely) .

i want to perform action like adding user, mapping user to groups and spaces, permissions etc. Went thru the lot of document in alfresco wiki which are not completed i guess.

Could you please help me with the procedure and guide me to the right path. please reply fast.

Thanks,
Narendran Srinivasan
PHP Developer
+91 9941964931

ofrxnz
Champ in-the-making
Champ in-the-making
Narendran,

The best place to start is here. 
http://wiki.alfresco.com/wiki/PHP_SDK

The SDK is part of this package you download here.  You will need to pull out the interface libraries in the SDK, which is part of the SVN path on the following page, and simply include it in your application.  It is a bit picky on the path. 
http://wiki.alfresco.com/wiki/Alfresco_PHP_Library_Installation_Instructions

once you get these two working, you should have all the files you need in the right place. 

   require_once "Alfresco/Service/Repository.php";
   require_once "Alfresco/Service/Session.php";

Here is a basic authentication script
http://wiki.alfresco.com/wiki/PHP_Tutorial_One_Complete_Script

Also, if you want to write your own interface all of alfresco's get and post hooks are located on the following page of your server (admin access only)

http://server.company.com/alfresco/service/index

I hope that gets you started.  I'm not near any of my work material at the moment.  I may be able to scrounge up some more information if you need it.

Adam

sonanaren
Champ in-the-making
Champ in-the-making
Adam,

Thanks for your reply. Will go thru the same and get to you if i have issue.

Thanks,
Narendran Srinivasan
PHP Developer
+91 9941964931

sonanaren
Champ in-the-making
Champ in-the-making
Adam,

I could not understand the document.

Where should i install the PHP Library (phpIntegration-unsupported.amp), is it to my php application or to the alfresco installation.

PHP library is with .amp format and how to extract the same. even i couldnt find the PHP SDK installation.

In the below code

require_once "Alfresco/Service/Repository.php";
require_once "Alfresco/Service/Session.php";

Where can i find the above file and where is it installed whether it is in the PHP application or in the Alfresco installation.

Please help me out with the clear installation.

Awaiting your reply.

Thanks,
Narendran Srinivasan
PHP Developer
+91 9941964931

ofrxnz
Champ in-the-making
Champ in-the-making
you can take the SDK files out of the AMP files by unzipping it (.amp == .zip) or you can download them from here http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/modules/php-sdk/source/php/rem...  You will want to download every file in that directory and make sure it's path is /Alfresco/Service/  or you will have to edit every one of those files. 

Once you have those files in place, you can start coding with them.  This will basically eliminate the need to create some of the more common tasks associated with tapping into alfresco since they have already done the work. 

That is the way I have always done it.  If you need some code examples i can see if i can find something on my end. 

There are two other ways to do this.  I occasionally have done the second.

1. ) insatall the amp into alfresco (not supported)
http://wiki.alfresco.com/wiki/AMP_Files
http://wiki.alfresco.com/wiki/Module_Management_Tool

2.) writing your own connector.  Alfresco takes GET and POST requests and usually returns JSON data so its fairly straight forward to write your own connector.

sonanaren
Champ in-the-making
Champ in-the-making
My alfresco installation is in a different server. in my local machine i am building a PHP Application. Guess you want me to install the Alfresco SDK in my local PHP Application right and i must place the library in this structure in my local machine (/Alfresco/Service/).

Is my understanding correct. Sorry for bothering you i have been breaking my head for last two days.

Await your reply.

Regards,
Narendran Srinivasan
PHP Developer
+91 9941964931

ofrxnz
Champ in-the-making
Champ in-the-making
Shoot me a Private message with your email so i can send you some code examples i have where Alfresco is installed on a different server

But, in your case,

you will want to start with the files at this link.  Download all of them including sub-folders and the contents of sub-folders
http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/modules/php-sdk/source/php/rem...

These files are the base of every PHP application I have made that remotely taps into Alfresco.  Those files take care of the basics of interfacing with Alfresco. 

Once you have those files downloaded, you will want to start with one of the tutorials.  Your code will be a little different than theirs.  They are assuming you are using the amp.  But, once you have a tutorial working, you know are on the right track

http://wiki.alfresco.com/wiki/PHP_API_Tutorials

When everything appears to be working, this page documents the methods available for use to interface with Alfresco.

http://wiki.alfresco.com/wiki/Alfresco_PHP_API 

Also, make sure your PHP server displays errors.  When i first started using it, i did not set display errors and failed to realize that my paths were wrong…. The quickest way to avoid this is when you write your include statement make sure they look like this

require_once "Alfresco/Service/Repository.php";
require_once "Alfresco/Service/WebService/AlfrescoWebService.php";

and so on….

Again, PM me your email and ill send you some code I have worked with.  Its out of date but its a start. 

Adam

sonanaren
Champ in-the-making
Champ in-the-making
Adam,

You are a life saver, it worked and i am really happy. Need some more thing to do.

Will work on my requirement and get back to you in issues. Meantime can you please send my the same code which you promised.

Did you developed the API, awesome work.

sonanaren
Champ in-the-making
Champ in-the-making
Adam,

Do u have any sample for the below.

1. Creating Groups
2. Associating users to groups
3. Associating groups to spaces and permission for the same
4. Removing of users from spaces
5. Creating spaces

Meantime i am also working on the same. await your reply.