cancel
Showing results for 
Search instead for 
Did you mean: 

AVMRemote is null, if used outside ServletContext

kapil_k
Champ on-the-rise
Champ on-the-rise
How do I write a standalone (outside servlet context) client java program, that can list the avm repo directory map?

I used the repoDirMap.jsp from RivetLogic as a starting point? The JSP works fine (from within the servlet context), but when i try to write a standaline Java program I get AVMRemote as null (e.g. on calling: List list = avmRemote.getStores());

Code:
public class AVMDemo {
   public static void main(String[] args) throws Exception {
      String avmPath = "v:\\alfrescowww–admin\\VERSION\\v-1\\DATA\\www\\avm_webapps\\ROOT\\";

      
      String mountPoint = "v:\\";
       final JNDIPath jndiPath = new JNDIPath(mountPoint, avmPath);
       avmPath = jndiPath.getAvmPath();
       System.out.println("avmPath: " + avmPath);

AVMFileDirContext.getAVMRemote();

      List list = avmRemote.getStores();  // avmRemot is Null here
      Map<String, AVMNodeDescriptor> nodes = avmRemote.getDirectoryListing(-1, avmPath);
              
         for (Map.Entry<String, AVMNodeDescriptor> node : nodes.entrySet()) {
            String nodeKey = node.getKey();

            AVMNodeDescriptor nodeValue = node.getValue();
           
            if (nodeValue.isDirectory() ) {
               System.out.println("Directory: ");
               System.out.println("/" + nodeKey + "<br>");

//               repoDirMap(path + "/" + nodeKey, "", pageContext, out);
            }
              
         }
      
   }
}

OUTPUT:
avmPath: alfrescowww–admin:/www/avm_webapps/ROOT/
Exception in thread "main" java.lang.NullPointerException
   at com.gl.alfresco.demo.AVMDemo.main(AVMDemo.java:37)

I think the issue is in getting AVMRemote initialized correctly.
Please advise how to go about this.

Thanks,
Kapil
3 REPLIES 3

pmonks
Star Contributor
Star Contributor
Since v2.1, Web Scripts (http://wiki.alfresco.com/wiki/Web_Scripts) are the recommended way to access the Alfresco repository (whether DM or AVM or both) from an external process.

For accessing the AVM specifically, the "avmbrowse" example Web Script (available at http://wiki.alfresco.com/wiki/Web_Scripts_Examples#WCM_Folder_Browse) is a good place to start.

kapil_k
Champ on-the-rise
Champ on-the-rise
Thanks for the reply.
Yes, WebScripts is really cool stuff and I will be definitely be trying it out.

However, for some scenarios, I would still like to use the AVMRemote directly. It should be easy to write a standalone java client that can use AVMRemote. I think I am missing spring configuration or something (which the rivetlogic example uses inherently, but is not documented).
Any help will be greatly appreciated.

Thanks,
Kapil

rivetlogic
Champ on-the-rise
Champ on-the-rise
I think you're missing the Spring configuration, see below:

    <bean id="avmRemote" class="org.alfresco.repo.remote.AVMRemoteImpl">
        <property name="avmRemoteTransport">
            <ref bean="avmRemoteTransport"/>
        </property>
    </bean>

    <bean id="avmRemoteTransport" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl">
            <value>rmi://localhost:50500/avm</value>
        </property>
        <property name="serviceInterface">
            <value>org.alfresco.service.cmr.remote.AVMRemoteTransport</value>
        </property>
        <property name="refreshStubOnConnectFailure">
            <value>true</value>
        </property>
    </bean>

   <bean id="avmSyncService" class="org.alfresco.repo.remote.AVMSyncServiceClient">
       <property name="avmSyncServiceTransport">
          <ref bean="avmSyncServiceTransport"/>
       </property>
   </bean>

    <bean id="avmSyncServiceTransport" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl">
            <value>rmi://localhost:50500/avmsync</value>
        </property>
        <property name="serviceInterface">
            <value>org.alfresco.service.cmr.remote.AVMSyncServiceTransport</value>
        </property>
        <property name="refreshStubOnConnectFailure">
            <value>true</value>
        </property>
    </bean>   

    <bean id="authenticationService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
        <property name="serviceUrl">
            <value>rmi://localhost:50500/authentication</value>
        </property>
        <property name="serviceInterface">
            <value>org.alfresco.service.cmr.security.AuthenticationService</value>
        </property>
        <property name="refreshStubOnConnectFailure">
            <value>true</value>
        </property>
    </bean>

Hope that helps.

–Sumer