cancel
Showing results for 
Search instead for 
Did you mean: 

Determine which sandbox is previewed

leviter
Champ in-the-making
Champ in-the-making
Hi,

I've created a very simple webapp which is doing a lookup of the ROOT node of a web project on the staging sandbox using the AVMRemote. The name of the sandbox and path are now hardcoded…

How can I created a more dynamic lookup? How can I for instance determine the sandbox which is previewed?

I want it to work just as well when I do a preview in a user's sandbox and not always take the staging sandbox! … but don't know how.

Please help.
4 REPLIES 4

arielb
Champ in-the-making
Champ in-the-making
there's a magic function to do the translation for you.

ServletContext.getRealPath() will provide a cifs path structure.  you can use the org.alfresco.util.JNDIPath class to translate that into an avmpath.

also please note that org.alfresco.web.forms.ServletContextFormDataFunctions can be used to parse xml documents within the repo generated by forms.  let me know if there are other high level apis you'd like exposed within the web client.  the tentative plan is to provide jsp tags/functions for making common operations easier.

leviter
Champ in-the-making
Champ in-the-making
Thanks a lot for responding!

Is the code supposed to work when it is incorporated in my own webapp (not running within Alfresco)?

I created a very quick example to see if it would work, but I'm getting a NullPointerException at org.alfresco.util.JNDIPath.<init>(JNDIPath.java:72).

My code looks like this:


   ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext("alfresco/clt-context.xml");
   final AVMRemote remote = (AVMRemote) ctx.getBean("avmRemote");

   AuthenticationService auth = (AuthenticationService) ctx.getBean("authenticationService");
   auth.authenticate("admin", "admin".toCharArray());

    String ticket = auth.getCurrentTicket();
    ClientTicketHolder.SetTicket(ticket);

    ServletContext servletContext = this.getServletContext();
   String path = servletContext.getRealPath("/");
   System.out.println("REAL PATH FOR '/' IS : " + path);
   
   String avmPath = "";
   
   try {
      JNDIPath jndiPath = new JNDIPath(AVMFileDirContext.getAVMFileDirMountPoint(), path);
        avmPath = jndiPath.getAvmPath();
   } catch (Exception e) {
      e.printStackTrace();
   }
   System.out.println("AVM PATH FOR '/' IS : " + avmPath);

What am I doing wrong?

jcox
Champ in-the-making
Champ in-the-making
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

lfaggioli
Champ in-the-making
Champ in-the-making
Hi,

I followed your instructions, but still I cannot make AVMRemote working…

Basically, the problem is in the AVMFileDirContext.getAVMFileDirMountPoint() call - If I call it within the Alfresco Site Preview then everything works fine (I get z:\) - but if I call it within a tomcat where alfresco is not deployed on, then I get null, and of course then I cannot get the jndiPath

In other words, I'm not able to see the live site at all 😞

Any suggestion?

Thanks a lot for your time!
luca
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.