cancel
Showing results for 
Search instead for 
Did you mean: 

Getting error while creating space in alfresco using java api

vijayd
Champ in-the-making
Champ in-the-making
Hi,

I am trying to create sapce in company home, I am able to start a session but not able to create a space.
Getting following error :
{http://schemas.xmlsoap.org/soap/envelope/}Server.userException

Can anybody help me to solve this error.
I am using 5.0.a community version.
5 REPLIES 5

kaynezhang
World-Class Innovator
World-Class Innovator
More detailed information is needed, please paste you code here.

vijayd
Champ in-the-making
Champ in-the-making
//this is the code to create the space.   

public Reference createSpace(String spacename) throws Exception {

      Reference space = null;
      Predicate predicate = null;

      // Create the space if it is not already existent
      createSession();
      try {
         // Therefore a reference to the maybe not existent space is required

         space = new Reference(STORE, null, getCompanyHome().getPath()
               + "/cm:" + normilizeNodeName(spacename));

         predicate = new Predicate(new Reference[] { space }, STORE, null);
         getRepositoryService().get(predicate);

      } catch (Exception e1) {
         ParentReference companyHome = getCompanyHome();

         // Set Company Home as the parent space
         companyHome.setChildName(Constants.createQNameString(
               Constants.NAMESPACE_CONTENT_MODEL,
               normilizeNodeName(spacename)));

         // Set the space's property name
         NamedValue[] properties = new NamedValue[] { Utils
               .createNamedValue(Constants.PROP_NAME, spacename) };

         // Create the space using CML (Content Manipulation Language)
         CMLCreate create = new CMLCreate("1", companyHome, null, null,
               null, Constants.TYPE_FOLDER, properties);
         CML cml = new CML();
         cml.setCreate(new CMLCreate[] { create });

         // Execute the CML create statement
         try {
            getRepositoryService().update(cml);

            // To limit the access
            getAccessControlService()
                  .setInheritPermission(predicate, false);
         }

         catch (AxisFault af) {
            System.out.println(af.getFaultCode());
         } catch (Exception e2) {
            System.err.println("Can not create the space.");
            // throw e2;
         }
      }
      return space;

   }


//this is code to create session
public void createSession() {

      server_host = "127.0.0.1";
      server_port = "8080";
      server_username = "admin";
      server_password = "admin";

      try {
         System.out.println("Starting Session");

         if (AuthenticationUtils.getAuthenticationDetails() == null) {

            // setSessionProperties();
            System.out.println("Connecting to: " + "http://" + server_host
                  + ":" + server_port + "/alfresco in AlfrescoUtil");
            System.out.println("User: " + server_username + "Smiley Tongueassword"
                  + server_password);
            WebServiceFactory.setEndpointAddress("http://" + server_host
                  + ":" + server_port + "/alfresco/api");

            AuthenticationUtils.startSession(server_username,
                  server_password);

            System.out.println("Session Created");

         }
      } catch (Exception e) {
         System.err
               .println("Can not initiate session with Alfresco server.");
         e.printStackTrace();
      }

   }



I am able to start session, but not able to create space.

kaynezhang
World-Class Innovator
World-Class Innovator
Why are you still using native webservice?,it is deprecated in 5.0.Please use opencmis api instead.

vijayd
Champ in-the-making
Champ in-the-making
Thank you very very much kaynezhang.
Now I am using opencmis api.
They are working fine.
Really thank you very very much.

kaynezhang
World-Class Innovator
World-Class Innovator
You are welcome ,good luck.