cancel
Showing results for 
Search instead for 
Did you mean: 

[SOLVED] Access CIFS server from web script

tim-erwin
Champ in-the-making
Champ in-the-making
[context]It sometimes happens that a Microsoft Office document cannot be opened in write mode from a CIFS share because some other user supposedly has opened it already. However, the latter is not the case, Alfresco blocks the file erroneously. This bug has not been fixed since ages, so we want to at least be able to work around that by clearing the FileStateCache for the affected share. For that we want to build a web-script so the function is easily accessible.[/context]

How can I access the cifsServer bean from a web-script? The cifsServerConfig bean would also work. I have the following context configuration:

    <bean id="webscript.bla.fileStates.get"
          class="bla.FileStatesList"
          parent="webscript">
          <property name="cifsServerBean" ref="cifsServer" />
    </bean>


Sadly, I get "org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'cifsServer' is defined". Same for cifsServerConfig. When from the same file where those two beans are defined (file-servers-context.xml) I choose "fileServerConfiguration", it works - but doesn't help me as from that config I don't get access to the running jlan server.
4 REPLIES 4

tim-erwin
Champ in-the-making
Champ in-the-making
Another thing that bugs me with those cifs beans is that I don't seem to get the bean I'm expecting when referencing "fileServerConfiguration". Its definition says

<bean id="fileServerConfiguration"
         parent="fileServerConfigurationBase"
         factory-bean="fileServerConfigurationFactory"
         factory-method="createFileServerConfiguration">

The <a href="http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/jav...">respective code</a> is

public ServerConfigurationBean createFileServerConfiguration()
{
    return new ServerConfigurationBean();
}

So I'm expecting a <em>ServerConfigurationBean</em> but do get something that implements <em>FileServerConfigMBean</em> and <em>ExtendedServerConfigurationAccessor</em>. Can't identify what exactly it is, though. Seems like I'm missing something here…

kaynezhang
World-Class Innovator
World-Class Innovator
Alfresco cifs server is implemented using subsystem,it has its own isolated Spring Application Context.
If you want to get cifsServerBean ,please get it like this :

import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.extensions.webscripts.AbstractWebScript;
import org.springframework.extensions.webscripts.WebScriptRequest;
import org.springframework.extensions.webscripts.WebScriptResponse;
import org.alfresco.filesys.CIFSServerBean;
import org.alfresco.jlan.server.config.ServerConfiguration;

public class FileServerStatusWebScript extends AbstractWebScript implements ApplicationContextAware{
      private ApplicationContext applicationContext;
      
       @Override
       public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
       {
           this.applicationContext = applicationContext;
       }
      
       public void execute(WebScriptRequest req, WebScriptResponse res) throws IOException
       {
           ChildApplicationContextFactory subsystem = (ChildApplicationContextFactory)applicationContext.getBean("fileServers");
          

           CIFSServerBean cifsServer = (CIFSServerBean)  subsystem.getApplicationContext().getBean("cifsServer");//get cifs server bean
          
           ServerConfiguration sc = cifsServer.getConfiguration(); //get configuration
                // do what you want to do

       }
}

tim-erwin
Champ in-the-making
Champ in-the-making
Awesome! Sounds as if that's exactly what I need. Unfortunately, I cannot try it out right now. I'll let you know if it works asap.

tim-erwin
Champ in-the-making
Champ in-the-making
Your solution works perfectly. Thanks a lot!