cancel
Showing results for 
Search instead for 
Did you mean: 

NullPointer@uploading a file from local system to alfresco

amit_wmw
Champ in-the-making
Champ in-the-making
Hello,

Below is the code I have written to upload a file from my local system to Alfresco repository..
####################################################

package org.alfresco.sample;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.BufferedInputStream;

import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.repo.content.RoutingContentService;



public class FirstJCRClient

{

public static void main(String[] args) throws Exception
{
// access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
Repository repository = (Repository)context.getBean("JCR.Repository");

// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

try
{
// first, access the company home
Node rootNode = session.getRootNode();
Node companyHome = rootNode.getNode("app:company_home");

FirstJCRClient t= new FirstJCRClient();
t.tCheckin();

}

catch (Exception e)
{
e.printStackTrace();
}
finally
{
session.logout();
System.exit(0);
}
}
public void tCheckin()
{
try{
NodeRef root= new NodeRef(".+://.+/." + "companyHome");

System.out.println("Inside tcheckin-1");
// NodeRef companyHome = getRepositoryContext().getCompanyHome();
File file=new File("C:/Test/Test.doc");
System.out.println("Inside tcheckin-2");
FileFolderService fileFolderService = new FileFolderServiceImpl();
System.out.println("Inside tcheckin-3");
FileInfo fileinfo = fileFolderService.create(root, file.getName(), ContentModel.TYPE_CONTENT);
System.out.println("Inside tcheckin-4");
NodeRef fileRef = fileinfo.getNodeRef();
System.out.println("Inside tcheckin-5");
InputStream contentStream=new BufferedInputStream(new FileInputStream(file), 1025);
ContentService contentService= new RoutingContentService();
ContentWriter writer = contentService.getWriter(fileRef, ContentModel.PROP_CONTENT, true);
writer.putContent(contentStream);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

####################################################################

And below is the error I am getting while executing..

##########################################################33
Error:
———-
10:54:01,245 WARN [remoting.rmi.RmiRegistryFactoryBean] Could not detect RMI registry - creating new one
10:54:04,945 WARN [alfresco.util.OpenOfficeConnectionTester] A connection to OpenOffice could not be established.
10:54:10,499 INFO [domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.
10:54:11,157 INFO [domain.schema.SchemaBootstrap] No changes were made to the schema.
10:54:13,110 INFO [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: C:\Alfresco\alf_data
10:54:13,182 INFO [admin.patch.PatchExecuter] Checking for patches to apply …
10:54:13,301 INFO [repo.module.ModuleServiceImpl] Found 0 module(s).
10:54:13,405 ERROR [alfresco.smb.protocol] Error accessing Win32 NetBIOS, check DLL is on the path
10:54:13,419 INFO [service.descriptor.DescriptorService] Alfresco JVM - v1.6.0_07-b06; maximum heap size 63.563MB
10:54:13,419 WARN [service.descriptor.DescriptorService] Alfresco JVM - WARNING - maximum heap size 63.563MB is less than recommended 512MB
10:54:13,419 INFO [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 2.1.0 (482) schema 64 - Installed version 2.1.0 (482) schema 64
Inside tcheckin-1
Inside tcheckin-2
Inside tcheckin-3
java.lang.NullPointerException
at org.alfresco.repo.model.filefolder.FileFolderServiceImpl.isFolder(FileFolderServiceImpl.java:255)
at org.alfresco.repo.model.filefolder.FileFolderServiceImpl.create(FileFolderServiceImpl.java:673)
at org.alfresco.sample.FirstJCRClient.tCheckin(FirstJCRClient.java:112)
at org.alfresco.sample.FirstJCRClient.main(FirstJCRClient.java:87)

##########################################################33
Its failing exactly at this line of my code "FileInfo fileinfo = fileFolderService.create(root, file.getName(), ContentModel.TYPE_CONTENT);".

Please if you can provide some suggestions here, will be of much appreciation!

Thanks
Amit.
22 REPLIES 22

mrogers
Star Contributor
Star Contributor
The following statement will cause problems:
new FileFolderServiceImpl();  

There's lots of initialisation missing here.   You need to either grab the FileFolderService bean from spring.   Or access it through the repository's service registry.

amit_wmw
Champ in-the-making
Champ in-the-making
Thanks!

How we can get access to FileFolderServiceImpl through "service registry"?

rgds-
Amit

calle
Champ in-the-making
Champ in-the-making
Either you use the service registrys getter method:
org.alfresco.service.ServiceRegistry.getFileFolderService();

Or you inject it in your spring bean configuration, for example
<bean id="yourBean" class="org.xyz.yourBean">
      <property name="fileFolderService">
         <ref bean="FileFolderService" />
      </property>
</bean>
in a *-context.xml file.

Which you decide to use depends on the context you are in.

//Carl

amit_wmw
Champ in-the-making
Champ in-the-making
Thanks…

I modified my code as per your suggestion but got Null pointer @ getFileFolderService()–> getService(). I debugged but found nothing relevent. Can you please suggest?


##################################################################
This is the modified code. Note: modified piece of code is in red color

package org.alfresco.sample;

import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;

import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.BufferedInputStream;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.repo.content.RoutingContentService;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.service.ServiceRegistry.*;
import org.alfresco.repo.service.ServiceDescriptorRegistry;




public class FirstJCRClient

{

public static void main(String[] args) throws Exception
{
// access the Alfresco JCR Repository (here it's via programmatic approach, but it could also be injected)
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
Repository repository = (Repository)context.getBean("JCR.Repository");


// login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));

try
{
// first, access the company home
Node rootNode = session.getRootNode();
Node companyHome = rootNode.getNode("app:company_home");

FirstJCRClient t= new FirstJCRClient();
t.tCheckin();

}

catch (Exception e)
{
e.printStackTrace();
}
finally
{
session.logout();
System.exit(0);
}
}
public void tCheckin()
{
try{
NodeRef root= new NodeRef(".+://.+/." + "companyHome");

System.out.println("Inside tcheckin-1");
// NodeRef companyHome = getRepositoryContext().getCompanyHome();
File file=new File("C:/Test/test.doc");
System.out.println("Inside tcheckin-2");
ServiceRegistry SR=new ServiceDescriptorRegistry();
FileFolderService fileFolderService = SR.getFileFolderService();

System.out.println("Inside tcheckin-3");
FileInfo fileinfo = fileFolderService.create(root, file.getName(), ContentModel.TYPE_CONTENT);
System.out.println("Inside tcheckin-4");
NodeRef fileRef = fileinfo.getNodeRef();
System.out.println("Inside tcheckin-5");
InputStream contentStream=new BufferedInputStream(new FileInputStream(file), 1025);
ContentService contentService= new RoutingContentService();
ContentWriter writer = contentService.getWriter(fileRef, ContentModel.PROP_CONTENT, true);
writer.putContent(contentStream);
}
catch (Exception e)
{
e.printStackTrace();

}
}
}
#########################################
Error

18:04:34,949 WARN  [remoting.rmi.RmiRegistryFactoryBean] Could not detect RMI registry - creating new one
18:04:37,349 WARN  [alfresco.util.OpenOfficeConnectionTester] A connection to OpenOffice could not be established.
18:04:40,762 INFO  [domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.
18:04:42,243 INFO  [domain.schema.SchemaBootstrap] No changes were made to the schema.
18:04:44,332 INFO  [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: C:\Alfresco\alf_data
18:04:44,737 INFO  [admin.patch.PatchExecuter] Checking for patches to apply …
18:04:44,955 INFO  [repo.module.ModuleServiceImpl] Found 0 module(s).
18:04:45,080 ERROR [alfresco.smb.protocol] Error accessing Win32 NetBIOS, check DLL is on the path
18:04:45,095 INFO  [service.descriptor.DescriptorService] Alfresco JVM - v1.5.0_16-b02; maximum heap size 63.563MB
18:04:45,095 WARN  [service.descriptor.DescriptorService] Alfresco JVM - WARNING - maximum heap size 63.563MB is less than recommended 512MB
18:04:45,095 INFO  [service.descriptor.DescriptorService] Alfresco started (Community Network): Current version 2.1.0 (482) schema 64 - Installed version 2.1.0 (482) schema 64
Inside tcheckin-1
Inside tcheckin-2
java.lang.NullPointerException
                at org.alfresco.repo.service.ServiceDescriptorRegistry.getService(ServiceDescriptorRegistry.java:115)
   at org.alfresco.repo.service.ServiceDescriptorRegistry.getFileFolderService(ServiceDescriptorRegistry.java:300)
   at org.alfresco.sample.FirstJCRClient.tCheckin(FirstJCRClient.java:79)
   at org.alfresco.sample.FirstJCRClient.main(FirstJCRClient.java:55)

##############################################3

Thanks
Amit.

mrogers
Star Contributor
Star Contributor
Same problem,  but this time you have an uninitialised ServiceRegistry.
You need to get the "ServiceRegistry" from spring not create it yourself.

Your "repository" variable has a getServiceRegistry() method.   Try to use that instead.

sangireddi
Champ in-the-making
Champ in-the-making
HI

I am also trying for this one .But few  changes i made but not succeed Plz help me
MY SOURCE:


package com.mis.checkin;


import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;


import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.BufferedInputStream;

import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.repo.content.RoutingContentService;

import org.alfresco.service.ServiceRegistry.*;
import org.alfresco.repo.service.ServiceDescriptorRegistry;

public class CheckIn {
   public static  ApplicationContext context;
   public static Node companyHome;
   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      // Session session=null;
      try
       {
           System.out.println("In main ");
       context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
       Repository repository = (Repository)context.getBean("JCR.Repository");
       // /home/chander/apps/eswar/alfrescoLabs3b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco
       // login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
       Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
      
      System.out.println("Session Id "+session.getUserID());
           // first, access the company home
           Node rootNode = session.getRootNode();
            companyHome = rootNode.getNode("app:company_home");
           
           CheckIn t= new CheckIn();
           t.tCheckin();

           }

           catch (Exception e)
           {
           e.printStackTrace();
           }
           finally
           {
          //    session.logout();
           System.exit(0);
           }
           }
           public void tCheckin()
           {
           try{
        
             NodeRef root= JCRNodeRef.getNodeRef(companyHome);//".+://.+/." + "companyHome");
           //   NodeRef root= new NodeRef(".+://.+/." + companyHome);
           System.out.println("Inside tcheckin-1 :"+root.getId());
      
           // NodeRef companyHome = getRepositoryContext().getCompanyHome();
           File file=new File("/home/chander/DcmQR.java");
           System.out.println("Inside tcheckin-2 :");
           ServiceRegistry registry = (ServiceRegistry)context.getBean(ServiceRegistry.SERVICE_REGISTRY);
           FileFolderService fileFolderService = registry.getFileFolderService();
          // ServiceRegistry SR=repository.getServiceRegistry();//new ServiceDescriptorRegistry();
         //  FileFolderService fileFolderService = SR.getFileFolderService();
          
         //  FileFolderService fileFolderService = new FileFolderServiceImpl();
           System.out.println("Inside tcheckin-3"+file.getName());
           FileInfo fileinfo = fileFolderService.create(root, file.getName(), ContentModel.TYPE_CONTENT);
           System.out.println("Inside tcheckin-4"+fileinfo.getName());
           NodeRef fileRef = fileinfo.getNodeRef();//workspace://SpacesStore/3ed55c5e-8b07-4037-8e34-2df98afac74c
         
           System.out.println("Content data :"+fileinfo.getContentData());
          
           System.out.println("Inside tcheckin-5 :"+fileRef.isNodeRef(fileRef.getId()));
          InputStream contentStream=new BufferedInputStream(new FileInputStream(file));
           ContentService contentservice= new RoutingContentService();
           File xmlfile1=new File(System.getProperty("/home/chander/eswar.txt"));
          
           FileOutputStream fos = new FileOutputStream(xmlfile1.toString());
            ByteArrayOutputStream baos = new ByteArrayOutputStream();

            while (true) {
                int data = contentStream.read();

                if (data == -1) {
                     System.out.println("data." + baos.size());
                    break;
                }
                baos.write((byte) data);
            }
            baos.writeTo(fos);
            System.out.println("baos.at storage…….." + baos.size());

            fos.flush();
            fos.close();
            //        baos.reset();
            System.out.println("File created in  directory…");
     
  
   
           System.out.println("Inside tcheckin-5 :"+contentservice.toString());
           ContentWriter writer = contentservice.getWriter(fileRef, ContentModel.PROP_CONTENT, true);        
           writer.putContent(contentStream);
           }          
           catch (Exception e)
           {
           e.printStackTrace();
           }
   }

}


ERROR LOG:


In main
12:21:52,116  INFO  [config.xml.XMLConfigService$PropertyConfigurer] Loading properties file from class path resource [alfresco/file-servers.properties]
12:21:54,332  WARN  [alfresco.mbeans.VirtServerRegistry] WCM virtualization disabled (alfresco-jmxrmi.password and/or alfresco-jmxrmi.access isn't on classpath)
12:22:01,086  ERROR [transform.swf.PDFToSWFContentTransformer] Failed to start SWF2PDF transformer:
Execution result:
   os:         Linux
   command:    pdf2swf -V
   succeeded:  false
   exit code:  1
   out:       
   err:        java.io.IOException: pdf2swf: not found
12:22:01,925  INFO  [domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.
12:22:03,263  INFO  [domain.schema.SchemaBootstrap] No changes were made to the schema.
12:22:06,572 UserSmiley Frustratedystem INFO  [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: /home/chander/apps/eswar/alfrescoLabs3b/alf_data
12:22:06,713 UserSmiley Frustratedystem INFO  [admin.patch.PatchExecuter] Checking for patches to apply …
12:22:07,310 UserSmiley Frustratedystem INFO  [admin.patch.PatchExecuter] No patches were required.
12:22:07,324 UserSmiley Frustratedystem INFO  [repo.module.ModuleServiceImpl] Found 0 module(s).
12:22:07,582 UserSmiley Frustratedystem ERROR [alfresco.smb.protocol] Failed to get local domain/workgroup name, using default of WORKGROUP
12:22:07,582 UserSmiley Frustratedystem ERROR [alfresco.smb.protocol] (This may be due to firewall settings or incorrect <broadcast> setting)
12:22:07,790 UserSmiley Frustratedystem WARN  [alfresco.util.OpenOfficeConnectionTester] An initial OpenOffice connection could not be established.
12:22:07,804 UserSmiley Frustratedystem INFO  [service.descriptor.DescriptorService] Alfresco JVM - v1.5.0_14-b03; maximum heap size 433.813MB
12:22:07,804 UserSmiley Frustratedystem WARN  [service.descriptor.DescriptorService] Alfresco JVM - WARNING - maximum heap size 433.813MB is less than recommended 512MB
12:22:07,805 UserSmiley Frustratedystem INFO  [service.descriptor.DescriptorService] Alfresco started (Labs): Current version 3.0.0 (b 1164) schema 131 - Installed version 3.0.0 (b 1164) schema 131
Session Id admin
Inside tcheckin-1 :a433799e-aefc-4a9c-8667-da24f310b8b8
Inside tcheckin-2 :
Inside tcheckin-3DcmQR.java
Inside tcheckin-4DcmQR.java
Content data :contentUrl=|mimetype=text/plain|size=0|encoding=UTF-8|locale=en_US_
Inside tcheckin-5 :false
java.lang.NullPointerException
   at java.io.File.<init>(File.java:194)
   at com.mis.checkin.CheckIn.tCheckin(CheckIn.java:105)
   at com.mis.checkin.CheckIn.main(CheckIn.java:64)



Please make me correct and is there any configurations need?

sangireddi
Champ in-the-making
Champ in-the-making
Sorry …. plz ignore fileoutputstream logic that is just for testing only…

i have another doubt .. is it model for file/folder needed to run this java application. I have custom-repository.properties and custom-repository-context.xml if any other things needed plz tell me in detail

Thank in advance

sangireddi
Champ in-the-making
Champ in-the-making
Hi Please see these Modifications i dont whether i am in right way or not But now I am getting Bad credentials presented eventhough i tryied to use authenticationService for ServiceRegistry still i am getting same error.


package com.mis.checkin;


import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;


import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.BufferedInputStream;

import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.service.cmr.dictionary.InvalidTypeException;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.repo.content.RoutingContentService;

import org.alfresco.service.ServiceRegistry.*;
import org.alfresco.repo.service.ServiceDescriptorRegistry;
import org.alfresco.service.cmr.security.AuthenticationService;
public class CheckIn {
   public static  ApplicationContext context;
   public static Node companyHome;
   /**
    * @param args
    */
   public static void main(String[] args) {
      // TODO Auto-generated method stub
      // Session session=null;
      try
       {
           System.out.println("In main ");
       context = new ClassPathXmlApplicationContext("classpath:alfresco/application-context.xml");
       Repository repository = (Repository)context.getBean("JCR.Repository");
       // /home/chander/apps/eswar/alfrescoLabs3b/tomcat/webapps/alfresco/WEB-INF/classes/alfresco
       // login to workspace (here we rely on the default workspace defined by JCR.Repository bean)
      Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
   
      System.out.println("Session Id "+session.getUserID());
           // first, access the company home
           Node rootNode = session.getRootNode();
            companyHome = rootNode.getNode("app:company_home");           
           CheckIn t= new CheckIn();
           t.tCheckin();

           }

           catch (Exception e)
           {
           e.printStackTrace();
           }
           finally
           {
          //    session.logout();
           System.exit(0);
           }
           }
           public void tCheckin()
           {
           try{
        
             NodeRef root= JCRNodeRef.getNodeRef(companyHome);//".+://.+/." + "companyHome");
              //NodeRef root= new NodeRef(".+://.+/." + "companyHome");
           System.out.println("Inside tcheckin-1 :"+root.getId());
      
           // NodeRef companyHome = getRepositoryContext().getCompanyHome();
           File file=new File("/home/chander/DcmQR.java");
           System.out.println("Inside tcheckin-2 :");
           ServiceRegistry registry = (ServiceRegistry)context.getBean(ServiceRegistry.SERVICE_REGISTRY);
           FileFolderService fileFolderService = registry.getFileFolderService();

          
        //  AuthenticationService authenticationService = registry.getAuthenticationService();
         //  authenticationService.authenticate("admin", "admin".toCharArray());

          // ServiceRegistry SR=repository.getServiceRegistry();//new ServiceDescriptorRegistry();
         //  FileFolderService fileFolderService = SR.getFileFolderService();
          
         //  FileFolderService fileFolderService = new FileFolderServiceImpl();
           System.out.println("Inside tcheckin-3"+file.getName());
           FileInfo fileinfo = fileFolderService.create(root, file.getName(), ContentModel.TYPE_CONTENT);
           System.out.println("Inside tcheckin-4"+fileinfo.getName());
           NodeRef fileRef = fileinfo.getNodeRef();
           System.out.println("Inside tcheckin-5 :"+fileRef.getId());
           InputStream contentStream=new BufferedInputStream(new FileInputStream(file));
         
           ContentService contentservice=registry.getContentService();
        //   ContentService contentservice= new RoutingContentService();
           System.out.println("Inside tcheckin-5 :"+contentservice.toString());
           ContentWriter writer = contentservice.getWriter(fileRef, ContentModel.PROP_CONTENT, true);         //here I am getting error as bad credentials
           String contentUrl = writer.getContentUrl();           
            System.out.println("contentUrl :"+contentUrl);
          
           writer.putContent(contentStream);
           }          
           catch (Exception e)
           {
           e.printStackTrace();
           }
   }

}


ERROR LOG:

In main
15:54:58,721  INFO  [config.xml.XMLConfigService$PropertyConfigurer] Loading properties file from class path resource [alfresco/file-servers.properties]
15:55:00,052  WARN  [alfresco.mbeans.VirtServerRegistry] WCM virtualization disabled (alfresco-jmxrmi.password and/or alfresco-jmxrmi.access isn't on classpath)
15:55:03,832  ERROR [transform.swf.PDFToSWFContentTransformer] Failed to start SWF2PDF transformer:
Execution result:
   os:         Linux
   command:    pdf2swf -V
   succeeded:  false
   exit code:  1
   out:       
   err:        java.io.IOException: pdf2swf: not found
15:55:04,635  INFO  [domain.schema.SchemaBootstrap] Schema managed by database dialect org.hibernate.dialect.MySQLInnoDBDialect.
15:55:11,143  INFO  [domain.schema.SchemaBootstrap] No changes were made to the schema.
15:55:18,481 UserSmiley Frustratedystem INFO  [repo.admin.ConfigurationChecker] The Alfresco root data directory ('dir.root') is: /home/chander/apps/eswar/alfrescoLabs3b/alf_data
15:55:18,532 UserSmiley Frustratedystem INFO  [admin.patch.PatchExecuter] Checking for patches to apply …
15:55:18,868 UserSmiley Frustratedystem INFO  [admin.patch.PatchExecuter] No patches were required.
15:55:18,876 UserSmiley Frustratedystem INFO  [repo.module.ModuleServiceImpl] Found 0 module(s).
15:55:19,177 UserSmiley Frustratedystem ERROR [alfresco.smb.protocol] Failed to get local domain/workgroup name, using default of WORKGROUP
15:55:19,177 UserSmiley Frustratedystem ERROR [alfresco.smb.protocol] (This may be due to firewall settings or incorrect <broadcast> setting)
15:55:19,358 UserSmiley Frustratedystem WARN  [alfresco.util.OpenOfficeConnectionTester] An initial OpenOffice connection could not be established.
15:55:19,364 UserSmiley Frustratedystem INFO  [service.descriptor.DescriptorService] Alfresco JVM - v1.5.0_14-b03; maximum heap size 433.813MB
15:55:19,365 UserSmiley Frustratedystem WARN  [service.descriptor.DescriptorService] Alfresco JVM - WARNING - maximum heap size 433.813MB is less than recommended 512MB
15:55:19,366 UserSmiley Frustratedystem INFO  [service.descriptor.DescriptorService] Alfresco started (Labs): Current version 3.0.0 (b 1164) schema 131 - Installed version 3.0.0 (b 1164) schema 131
Session Id admin
Inside tcheckin-1 :a433799e-aefc-4a9c-8667-da24f310b8b8
Inside tcheckin-2 :
Inside tcheckin-3DcmQR.java
Inside tcheckin-4DcmQR.java
Inside tcheckin-5 :efddcc31-90fd-4be9-8684-7c09478faf1c
Inside tcheckin-5 Smiley Surprisedrg.alfresco.repo.content.RoutingContentService@2ac02d83
net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
   at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(DaoAuthenticationProvider.java:290)
   at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
   at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
   at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
   at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.model.ml.MLContentInterceptor.invoke(MLContentInterceptor.java:131)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:245)
   at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:166)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy27.getWriter(Unknown Source)
   at com.mis.checkin.CheckIn.tCheckin(CheckIn.java:105)
   at com.mis.checkin.CheckIn.main(CheckIn.java:61)

amit_wmw
Champ in-the-making
Champ in-the-making
Hello All

I finally got remedy for this issue 🙂 Thanks for your suggestions and helps!

sangi,

For your problem; suggess you do the following modifications:

1) Change the way you are getting access to company home in Noderef:
ServiceRegistry serviceRegistry = (ServiceRegistry) context.getBean("ServiceRegistry");

// Get root node for default store: SpacesStore
NodeRef rootNodeRef = serviceRegistry.getNodeService().getRootNode(new StoreRef("workspace://SpacesStore"));
// Find children of root node with association name "app:company_home" (must be one)

List<NodeRef> nodes = (List<NodeRef>) serviceRegistry.getSearchService().selectNodes(rootNodeRef, "app:company_home", null,serviceRegistry.getNamespaceService(), false);

if (nodes.size() == 0) {
throw new AlfrescoRuntimeException("Unable to find store path: app:company_home");
}

NodeRef companyHome = nodes.get(0);

2) Get FileFolderService from spring:
FileFolderService fileFolderService = (FileFolderService) context.getBean("fileFolderService");

And then use it like below:

FileInfo fileinfo = fileFolderService.create(companyHome, file.getName(), ContentModel.TYPE_CONTENT);

3) Get ContentService also from spring:
ContentService contentService = (ContentService) context.getBean("contentService");

regards-
Amit.