HOWTO Alfresco PHP Library and xUbuntu

I tried to install Alfresco PHP Library and install it on my kubuntu developing box and it's really very easy to get it running! Instalation procedure for windows is described in Alfresco wiki, but there are some differencies.

I tried to install Alfresco PHP Library and install it on my kubuntu developing box and it’s really very easy to get it running! Instalation procedure for windows is described in Alfresco wiki, but there are some differencies.

To get it running it’s needed to install apache and php:

sudo apt-get install apache2 libapache2-mod-php5

Then you need to download PHP Library from Sourceforge. After that you can unpack it somewhere; good place is for example /usr/share/php/alfresco-php-library. Now it’s not bad to set virtual directory to that directory. So edit your /etc/apache2/conf.d/alias file and add something like this:

Alias /Alfresco/ /usr/share/php/alfresco-php-library/

<Directory /usr/share/php/alfresco-php-library/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Also including this directory automaticaly (/etc/php5/apache2/php.ini) should be cool:

include_path = „.:/usr/share/php/alfresco-php-library“

Now you need to restart apache:

/etc/init.d/apache2 restart

And edit configuration file in alfresco-php-library/Examples/config.php.

$repositoryUrl = "http://localhost:8080/alfresco/api";
$userName = "admin";
$password = "admin";

After all that you can try to open web browser and point it to http://localhost/Alfresco/Examples/SimpleBrowse/ and it should work 😎


Image and video hosting by TinyPic

Sending content to java webscript via POST method

Yesterday I stucked on problem of getting data from WebScriptRequest, which were sent by POST method. There is some bug in Apache Tomcat, so there is a simple workaround described for example here. My task was to create webscript, which tries to find a file in repository (or create it, if it doesn't exist) and to write content inside – data of POST request.

Yesterday I stucked on problem of getting data from WebScriptRequest, which were sent by POST method. There is some bug in Apache Tomcat, so there is a simple workaround described for example here. My task was to create webscript, which tries to find a file in repository (or create it, if it doesn’t exist) and to write content inside – data of POST request.

My webscript is Java backed, so only description in WEB-INF/classes/alfresco/templates/client/webscripts/org/alfresco/archivace is needed:

<webscript>
<shortname>SaveModif file</shortname>
<description>Ulozi dorucena data do *.modif.xml</description>
<url>/archivace/savemodif?nodeRef={noderef}</url>
<authentication>user</authentication>
<transaction>required</transaction>
</webscript>

Also definition in web-scripts-application-context.xml:

<bean id=“webscript.org.alfresco.archivace.savemodif.post“ class=“cz.shmoula.webscripts.SaveModif“ parent=“webscript“>
<property name=“authenticationComponent“ ref=“AuthenticationComponent“/>
<property name=“nodeService“ ref=“NodeService“/>
<property name=“searchService“ ref=“SearchService“/>
<property name=“fileFolderService“ ref=“FileFolderService“/>
<property name=“contentService“ ref=“ContentService“/>
</bean>

Now let’s get Node object itself:

// try to get DescriptionNode
Node xmlNode = getDescriptionNode(nodeRef);

// if DescriptionNode doesn’t exist, create one
if (xmlNode == null) {
String path = noda.getName();
String filename = path.substring(0, path.lastIndexOf(„.“)) + „.modif.xml“;
NodeRef spaceRef = nodeService.getPrimaryParent(noda.getNodeRef()).getParentRef();
xmlNode = createDescriptionNode(spaceRef, filename);
}

At this time in xmlNode is Node object – either existing one, or created one, so let’s write that request content inside:

ContentWriter writer = contentService.getWriter(xmlNode.getNodeRef(), ContentModel.PROP_CONTENT, true);
writer.putContent(req.getContent().getInputStream());

Simple, but sometimes it doesnt work. Why? Due to that bug mentioned in perex. So how are data sent through POST method? Let’s try it with wget:

wget –post-data=’pokus‘ –http-user=admin –http-password=admin http://localhost:8080/alfresco/service/archivace/savemodif?nodeRef=workspace://SpacesStore/91919928-3709-4e2e-a829-b0be46976e42

Captured request looks like this

Image and video hosting by TinyPic

As you can see, everything looks ok. But getContent() in our webscript is empty. Why? there is no content – there are just parameters, due to application/x-www-form-urlencoded content type. So req.getParameterNames() returns String[] array in which are in our case two parameters: {{nodeRef}, {pokus}}. This is not what we want, because length ot these parameter names may be limited (2M?). So let’s use mentioned advice – change content-type:

wget –post-data=’pokus‘ –header=’Content-Type: text/xml‘ –http-user=admin –http-password=admin http://localhost:8080/alfresco/service/archivace/savemodif?nodeRef=workspace://SpacesStore/91919928-3709-4e2e-a829-b0be46976e42

And now it works! 🙂 Sniffed request looks like before, just content-type header line had changed:

Image and video hosting by TinyPic

Now is possible to send inputStream of content to Writer:

writer.putContent(req.getContent().getInputStream());

At this time req.getParameterNames() has just one parameter – {{nodeRef}} and content is really saved in data field.