Leviter,
If you really want to use the JNDI path you fetched from getRealPath()
directly as a valid file system path, then you'll need to create a CIFS
mount so that when Java goes to look for your file, that "file system"
will actually be there. Because you didn't create a CIFS mount (or you
didn't create one in the place indicated near the end of the config file
$VIRTUAL_TOMCAT_HOME/conf/alfresco-virtserver.properties),
you're getting null pointer exceptions. While using a CIFS mount
is a nice way of working around a webapp that relies on a file
system, it has a few disadvantages. For one thing, you don't have
access to the full AVMRemote API, and for another, it creates another
out-of-band config to get right.
However, you could avoid *all* reliance on CIFS mounts if you translate
the JNDI path you've gotten back from getRealPath() into an AVM path.
If you did this, you could then use AVMRemote to fetch whatever you
want (and have the full power of the remote API at your disposal,
not just what's exposed in CIFS). This is the technique I prefer.
The JNDI names used to reference all assets in the AVM begin
with a string whose value you can fetch via the static method:
org.alfresco.jndi.AVMFileDirContext.getAVMFileDirMountPoint()
This mount point can then be used to parse the jndi path
you get from the servlet method getRealPath() to produce
an AVM version & AVM path that can be passed as args
to AVMRemote using:
org.alfresco.util.JNDIPath
This class is available within:
$VIRTUAL_TOMCAT_HOME/common/lib/alfresco-jndi-client.jar
Therefore, it is already in their classpath, so you can use it from
within your webapp.
Here's the constructor:
public JNDIPath(String mount_point, String jndi_path)
Therefore you could say:
String mount_point =
org.alfresco.jndi.AVMFileDirContext.getAVMFileDirMountPoint();
String real_path = whatever the servlet method getRealPath() says
JNDIPath p = new JNDIPath(mount_point, real_path );
Now do whatever you want with 'p.getAvmVersion()' and 'p.getAvmPath()'
EXAMPLE:
On UNIX, if the constructor args are:
mount_point == /media/alfresco/cifs/v
jndi_path == /media/alfresco/cifs/v/mysite/VERSION/v-1/DATA/www/avm_webapps/ROOT
Or in Windows, if the constructor args are:
mount_point == v:
jndi_path == v:/mysite/VERSION/v-1/DATA/www/avm_webapps/ROOT
Then:
getAvmVersion() == -1
getAvmPath() == mysite:/www/avm_webapps/ROOT
From here, you can use the values returned by
getAvmVersion() and getAvmPath() to query AVMRemote.
Note that the value for the JNDI mount point is configured in:
$VIRTUAL_TOMCAT_HOME/conf/alfresco-virtserver.properties
The property on Windows is:
alfresco.virtserver.cifs.avm.versiontree.win
The property on UNIX is:
alfresco.virtserver.cifs.avm.versiontree.unix