cancel
Showing results for 
Search instead for 
Did you mean: 

Need Code Help - Versioning

thaneshk
Champ in-the-making
Champ in-the-making
Hi I am using two servlets, one to process CheckOut and the other to process Check In. I am currenlty using the CheckOutCheckInService

This is my code for CheckOutServlet





package com.xpflow.dam.poc.repository;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

//import javax.faces.context.FacesContext;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.repo.coci.CheckOutCheckInServiceImpl;
import org.alfresco.repo.coci.WorkingCopyAspect;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.model.ContentModel;
import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.repo.content.MimetypeMap;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.version.NodeServiceImpl;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.TestWithUserUtils;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.ui.common.Utils;

import com.xpflow.dam.common.AlfrescoUtils;

public class CheckoutServlet extends HttpServlet {
   
   
   @Override
   protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
      doPost(arg0, arg1);
   }
   
   
   private static final String TEST_VALUE_NAME = "myDocument.doc";
   private static final String TEST_VALUE_2 = "testValue2";
   private static final String TEST_VALUE_3 = "testValue3";
   private static final QName PROP_NAME_QNAME = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "name");
   private static final QName PROP2_QNAME = ContentModel.PROP_DESCRIPTION;
   private static final String CONTENT_1 = "This is some content";
   private static final String CONTENT_2 = "This is the cotent modified.";

   @Override
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      UserTransaction trx = AlfrescoUtils.getTransaction();
      try {
         trx.begin();
      } catch (Exception e1) {
         e1.printStackTrace();
         throw new ServletException(e1);
      }

      javax.jcr.Session jcrSession = null;
      
      try {
         String fileName = request.getParameter("name");
         Repository repository = AlfrescoUtils.getJCRRepository();

         System.out.println("repository=" + repository);
         jcrSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
         System.out.println("jcrSession=" + jcrSession);

         ServiceRegistry registry = AlfrescoUtils.getServiceRegistry();
         
         
         
         //CheckOutCheckInServiceImpl checkoutService = new CheckOutCheckInServiceImpl();
            
         NodeService nodeService = registry.getNodeService();
         
         CheckOutCheckInService check = registry.getCheckOutCheckInService();
         
         VersionService version = registry.getVersionService();
         
         ContentService contentService = registry.getContentService();
         
         CopyService copy = registry.getCopyService();
         
         //userNodeRef = TestWithUserUtils.getCurrentUser(registry.getAuthenticationService());
         
         
         Node root = jcrSession.getRootNode();
         System.out.println("root = " + root);
         Node xpflowNode = root.getNode("app:company_home/cm:xpflow-dam");
         //Node xpflowdam = rootNode.getNode("app:company_home/cm:xpflow-dam");

         Node contentNode = xpflowNode.getNode("cm:" + fileName);

         /*if (contentNode.isCheckedOut()) {
            System.out.println("Content is already Checked Out");
            response.setContentType("text/html");
            response.getWriter().println("Content is already Checked Out");
         } else {*/
            OutputStream outStream = response.getOutputStream();
            System.out.println("Content is going to Checked Out");
            
            NodeRef nodeRef = JCRNodeRef.getNodeRef(contentNode);
            NodeRef rootNodeRef = JCRNodeRef.getNodeRef(xpflowNode);
            
            //NodeRef nodeRef1;
            
            
            
            /*System.out.println("Printing First Values of Main Node");
            System.out.println(nodeRef);
            
            System.out.println(nodeRef.getStoreRef());
            
            System.out.println(nodeRef.getId());
            
            System.out.println(contentNode.getVersionHistory());*/
            
            //System.out.println(nodeService.getgetChildAssocs(nodeRef));
            
            //nodeService.get
            
            //version.getVersionHistory(nodeRef);
            
            
            
            
            
            
            //NodeRef workingCopyRef;
            
            //check.checkout(nodeRef);
            
            //workingCopyRef
            
            //System.out.println(workingCopyRef);
            
            //String nodeName = contentNode.getProperty("cm:name").toString();
            //System.out.println(nodeName);
            //Node workingNode = xpflowNode.addNode(nodeName, "xpf:asset");
            //workingNode.setProperty("cm:name", contentNode.getProperty("cm:name").toString());
            //System.out.println(contentNode.getProperty("cm:name").toString());
            //workingNode.setProperty("cm:description", contentNode.getProperty("cm:description").toString());
            //workingNode.setProperty("cm:title", contentNode.getProperty("cm:title").toString());
            //workingNode.setProperty("xpf:delete", contentNode.getProperty("xpf:delete").toString());
            //workingNode.setProperty("xpf:thumbnail", contentNode.getProperty("xpf:thumbnail").toString());*/
            
            
            //contentNode.addMixin("mix:versionable");
            
            //Node workingNode = root.add
            
            //check.checkout(nodeRef);
            
            //contentNode.checkout();
            
            
            /** Own Code */            
            
         
            
            
            NodeRef workingCopy = check.checkout(nodeRef);
            
            
            
            
            
            System.out.println("NodeRef:" + workingCopy);
            
            
            
            System.out.println(nodeService.getProperty(workingCopy, ContentModel.PROP_CONTENT));
            
            /**String url = workingCopy.toString();
            
            System.out.println("CONTENT NODE");
            
            System.out.println("NODEEEE::: "+ contentNode);
            
            System.out.println("NodePATH:::" + nodeService.getPath(nodeRef));
            
            System.out.println("WORKING NODE");
            
            System.out.println("WORKINNODEPATH:" +nodeService.getPath(workingCopy));
            
            //nodeService.getProperty(workingCopy,CONTENT_MODEL.);**/
            
            //NodeRef workingCopy2 = check.getWorkingCopy(nodeRef);
            
            //System.out.println(workingCopy2);
            
            //nodeService.get
            
            //Node test = xpflowNode.get);
            
            
            ContentWriter tempWriter = contentService.getWriter(workingCopy, ContentModel.PROP_CONTENT, false);
            //assertNotNull(tempWriter);
            //tempWriter.putContent(CONTENT_2);
            String contentUrl = tempWriter.getContentUrl();
            
            System.out.println(contentUrl);
            
            ContentData contentdata = (ContentData)nodeService.getProperty(workingCopy,ContentModel.PROP_CONTENT);
            
            System.out.println(contentdata);
            
            String contentURL = contentdata.getContentUrl();
                  
            
            //ContentReader tempWriter = contentService.getReader(workingCopy, ContentModel.PROP_CONTENT);
            //assertNotNull(tempWriter);
            //tempWriter.putContent(CONTENT_2);
            
            //String contentUrl = "";
            System.out.println(contentURL);
            
            
                  
            
            /*nodeService.setProperty(workingCopy, PROP_NAME_QNAME, TEST_VALUE_2);
            nodeService.setProperty(workingCopy, PROP2_QNAME, TEST_VALUE_3);
              ;
            Map<String, Serializable> versionProperties3 = new HashMap<String, Serializable>();
            versionProperties3.put(Version.PROP_DESCRIPTION, "description");
            versionProperties3.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
            NodeRef content = check.checkin(workingCopy, versionProperties3, contentUrl, true);*/
            
            
            
            /** Own Code */
            
            

            InputStream in = contentNode.getProperty("cm:content").getStream();

            MimetypeMap mimeTypeMap = (MimetypeMap) AlfrescoUtils.getAlfrescoBean("mimetypeService");
            String mimetype = mimeTypeMap.guessMimetype(fileName);

            response.setContentType(mimetype);
            response.setHeader("Content-Disposition", "attachment; filename="+ fileName);

            byte[] buf = new byte[1024];
            int count = 0;
            while ((count = in.read(buf)) >= 0) {
               outStream.write(buf, 0, count);
            }
            outStream.flush();
            
            //workingNode.checkin();
            
            //workingNode.save();
            
            //contentNode.checkin();

            contentNode.save();
            jcrSession.save();
         //}
         trx.commit();
         
         System.out.println("Transaction Committed");

      } catch (Exception e) {
         e.printStackTrace();
         try {
            trx.rollback();
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      } finally {
         try {
            jcrSession.logout();
         } catch (Throwable tt) {
         }
      }

   }
}


This is my code for CheckIn servlet

package com.xpflow.dam.poc.repository;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

//import javax.faces.context.FacesContext;
import javax.jcr.Node;
import javax.jcr.Repository;
import javax.jcr.SimpleCredentials;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.transaction.NotSupportedException;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;

import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.repo.coci.CheckOutCheckInServiceImpl;
import org.alfresco.repo.coci.CheckOutCheckInServiceImplTest;
import org.alfresco.repo.coci.WorkingCopyAspect;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.model.ContentModel;
import org.alfresco.jcr.api.JCRNodeRef;
import org.alfresco.repo.content.MimetypeMap;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.transaction.TransactionUtil;
import org.alfresco.repo.version.NodeServiceImpl;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeRefTest;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.TestWithUserUtils;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.servlet.DownloadContentServlet;
import org.alfresco.web.ui.common.Utils;

import com.xpflow.dam.common.AlfrescoUtils;

public class CheckInTest extends HttpServlet {
   
   
   @Override
   protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
      doPost(arg0, arg1);
   }
   
   
   private static final String TEST_VALUE_NAME = "myDocument.doc";
   private static final String TEST_VALUE_2 = "testValue2";
   private static final String TEST_VALUE_3 = "testValue3";
   private static final QName PROP_NAME_QNAME = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "name");
   private static final QName PROP2_QNAME = ContentModel.PROP_DESCRIPTION;
   private static final String CONTENT_1 = "This is some content";
   private static final String CONTENT_2 = "This is the cotent modified.";

   @Override
   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      AlfrescoUtils.setServletContext(getServletContext());
      UserTransaction trx = AlfrescoUtils.getTransaction();
      try {
         trx.begin();
      } catch (Exception e1) {
         e1.printStackTrace();
         throw new ServletException(e1);
      }

      javax.jcr.Session jcrSession = null;
      
      try {
         String fileName = request.getParameter("name");
         Repository repository = AlfrescoUtils.getJCRRepository();

         System.out.println("repository=" + repository);
         jcrSession = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
         System.out.println("jcrSession=" + jcrSession);

         ServiceRegistry registry = AlfrescoUtils.getServiceRegistry();
         
         
         
         //CheckOutCheckInServiceImpl checkoutService = new CheckOutCheckInServiceImpl();
            
         NodeService nodeService = registry.getNodeService();
         
         CheckOutCheckInService check = registry.getCheckOutCheckInService();
         
         VersionService version = registry.getVersionService();
         
         ContentService contentService = registry.getContentService();
         
         CopyService copy = registry.getCopyService();
         
         TransactionService transactionService = registry.getTransactionService();
         //userNodeRef = TestWithUserUtils.getCurrentUser(registry.getAuthenticationService());
         
         
         Node root = jcrSession.getRootNode();
         System.out.println("root = " + root);
         Node xpflowNode = root.getNode("app:company_home/cm:xpflow-dam");
         //Node xpflowdam = rootNode.getNode("app:company_home/cm:xpflow-dam");

         Node contentNode = xpflowNode.getNode("cm:" + fileName);
         //Node contentNode = xpflowNode.getNode();

         /*if (contentNode.isCheckedOut()) {
            System.out.println("Content is already Checked Out");
            response.setContentType("text/html");
            response.getWriter().println("Content is already Checked Out");
         } else {*/
            //OutputStream outStream = response.getOutputStream();
            System.out.println("Content is going to Checked In");
            
            NodeRef nodeRef = JCRNodeRef.getNodeRef(contentNode);
            NodeRef rootNodeRef = JCRNodeRef.getNodeRef(xpflowNode);
            
            //NodeRef nodeRef1;
            
            //xpflowNode.getNode("")
            // version.get
            
            System.out.println(nodeRef);
            
            System.out.println(nodeRef.getStoreRef());
            
            System.out.println(nodeRef.getId());
            
            
            NodeRef workingCopy = check.getWorkingCopy(nodeRef);
            
            
            
            System.out.println(workingCopy);
            
            //ContentData contentdata = (ContentData)nodeService.getProperty(workingCopy,ContentModel.PROP_CONTENT);
            
            //System.out.println(contentdata);
            
            //String contentUrl = contentdata.getContentUrl();
                  
            
            ContentReader tempWriter = contentService.getReader(workingCopy, ContentModel.PROP_CONTENT);
            //assertNotNull(tempWriter);
            //tempWriter.putContent(CONTENT_2);
            String contentUrl = tempWriter.getContentUrl();
            //String contentUrl = "";
            System.out.println(contentUrl);
                      
            
            Map<String, Serializable> versionProperties3 = new HashMap<String, Serializable>();
            versionProperties3.put(Version.PROP_DESCRIPTION, "description");
            versionProperties3.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
            NodeRef content = check.checkin(workingCopy, versionProperties3, contentUrl);
            
            
                        
            //contentNode.save();
            //jcrSession.save();
         //}
         trx.commit();

      } catch (Exception e) {
         e.printStackTrace();
         try {
            trx.rollback();
         } catch (Exception e1) {
            e1.printStackTrace();
         }
      } finally {
         try {
            jcrSession.logout();
         } catch (Throwable tt) {
         }
      }

   }
}

I am getting this error



[exec] 15:40:51,636 INFO  [STDOUT] workspace://SpacesStore
     [exec] 15:40:51,636 INFO  [STDOUT] 0c7cfd5f-c09c-11da-bdf8-4be1ead37feb
     [exec] 15:40:51,676 INFO  [STDOUT] workspace://SpacesStore/13681405-c09c-11da-bdf8-4be1ead37feb
     [exec] 15:40:51,676 INFO  [STDOUT] net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
     [exec] 15:40:51,686 INFO  [STDOUT]    at net.sf.acegisecurity.providers.dao.DaoAuthenticationProvider.authenticate(DaoAuthenticationProvider.java:290)
     [exec] 15:40:51,686 INFO  [STDOUT]    at net.sf.acegisecurity.providers.ProviderManager.doAuthentication(ProviderManager.java:159)
     [exec] 15:40:51,686 INFO  [STDOUT]    at net.sf.acegisecurity.AbstractAuthenticationManager.authenticate(AbstractAuthenticationManager.java:49)
     [exec] 15:40:51,686 INFO  [STDOUT]    at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:372)
     [exec] 15:40:51,686 INFO  [STDOUT]    at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
     [exec] 15:40:51,686 INFO  [STDOUT]    at $Proxy73.getReader(Unknown Source)
     [exec] 15:40:51,686 INFO  [STDOUT]    at com.xpflow.dam.poc.repository.CheckInTest.doPost(CheckInTest.java:170)
     [exec] 15:40:51,686 INFO  [STDOUT]    at com.xpflow.dam.poc.repository.CheckInTest.doGet(CheckInTest.java:73)
     [exec] 15:40:51,686 INFO  [STDOUT]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
     [exec] 15:40:51,686 INFO  [STDOUT]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 15:40:51,686 INFO  [STDOUT]    at com.xpflow.admin.access.RequestServiceHandler.doFilter(RequestServiceHandler.java:69)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:407)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
     [exec] 15:40:51,686 INFO  [STDOUT]    at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
     [exec] 15:40:51,686 INFO  [STDOUT]    at java.lang.Thread.run(Thread.java:595)


This is a custom application. When i bring in the checkin method into the CheckOut Servlet it works fine. So i know its working. Not sure why i am getting this error.

Help Appreciated.
5 REPLIES 5

anweber
Champ in-the-making
Champ in-the-making
Hello,

  I obtain the same exception (bad credentials) when I try to checkin a file  but it's not in the same context.  There is an extract of my code :


    private static void testCheckInFile(ServiceRegistry serviceRegistry) throws Exception{
        NodeService nodeService = serviceRegistry.getNodeService();

        // authenticate
        AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
        authenticationService.authenticate("admin", "admin".toCharArray());
       
        // get the store
        StoreRef storeRef = new StoreRef(
                StoreRef.PROTOCOL_WORKSPACE,
                "SpacesStore"
                );
        if (!nodeService.exists(storeRef))
        {
            return;
        }
        CheckOutCheckInService checkOutCheckInService= serviceRegistry.getCheckOutCheckInService();
       
        NodeRef companyHomeNode = getCompanyHome(nodeService, storeRef);
       
        if (companyHomeNode == null)return;
       
        NodeRef fileNodeRef = getNodeByPath(serviceRegistry, companyHomeNode, "testContent:testVersionedTextFile");
        if (fileNodeRef == null){
           System.out.println(" node created for versioned file not found");
        }
        else {
           System.out.println(" node created for versioned file found : " + fileNodeRef);
            Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
            versionProperties.put(Version.PROP_DESCRIPTION, "checkin made by test program");
            versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
           
           NodeRef workingCopy = checkOutCheckInService.getWorkingCopy(fileNodeRef);
           ContentData contentData;
           String contentUrl;
           contentData = (ContentData)nodeService.getProperty(workingCopy,ContentModel.PROP_CONTENT);
           contentUrl = contentData.getContentUrl();
           System.out.println("content Url :" + contentUrl);
           checkOutCheckInService.checkin(workingCopy, versionProperties, contentUrl );
        }                   
    }  


  This produce the following exception stack :


Exception in thread "main" 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:170)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy45.cancelCheckout(Unknown Source)
   at org.alfresco.example.MySimpleExampleWithContent.testCancelCheckoutFile(MySimpleExampleWithContent.java:763)
   at org.alfresco.example.MySimpleExampleWithContent.access$0(MySimpleExampleWithContent.java:726)
   at org.alfresco.example.MySimpleExampleWithContent$1.doWork(MySimpleExampleWithContent.java:109)
   at org.alfresco.repo.transaction.TransactionUtil.executeInTransaction(TransactionUtil.java:168)
   at org.alfresco.repo.transaction.TransactionUtil.executeInUserTransaction(TransactionUtil.java:74)
   at org.alfresco.example.MySimpleExampleWithContent.main(MySimpleExampleWithContent.java:113)

   Your problem is probably not related to the servlet environment.  May be, the way we obtain the reference of the "workingCopy" is relevent : we both use the "getWorkingCopy" method.  When you test the checkin in your checkoutServlet, you obtain the reference of the "workingCopy" as the result of the "checkout" method.

   I hope this will help.  Of course, I am interested by the solution.

         Regards,

                    Andre

andy
Champ on-the-rise
Champ on-the-rise
Hi

Make sure you use the pattern:

Authenticate …
try
{
     stuff
}
finally
{
     clear authentication
}




Post 1:
Seems to be another method that gives the problem??


Post 2:
I am not sure about mixing the JCR session with the Alfresco API.

An any case, there should be a security filter setting up authentication base on a ticket or redirecting for login.



BTW, you can use the authentication service to print out the name of the current  user.

Regards

Andy

anweber
Champ in-the-making
Champ in-the-making
Hi,

   I am sure the authentication is correct : I use the same pattern for this test than for other tests that work.

   If I modifiy the "public-services-context.xml" file as it :

    <bean id="CheckoutCheckinService" class="org.springframework.aop.framework.ProxyFactoryBean">
       <property name="proxyInterfaces">
          <value>org.alfresco.service.cmr.coci.CheckOutCheckInService</value>
       </property>
       <property name="target"><ref bean="checkOutCheckInService"/></property>
       <property name="interceptorNames">
          <list>
              <idref local="CheckoutCheckinService_transaction" />
                <idref local="exceptionTranslator" />
                <!–  idref bean="CheckoutCheckinService_security" / commented by AWE –>
             <idref local="CheckoutCheckinService_descriptor" />
          </list>
       </property>
    </bean>


Then my code works!  I obtain the checkin of my node with correct information about the modifier (here it is made by "admin").  Maybe there is problem in the bean "CheckoutCheckinService_security".

   Regards,

           Andre

anweber
Champ in-the-making
Champ in-the-making
Hi

Please, consider this test.  The following code works :


   private static void testCheckOutCheckInFile(ServiceRegistry serviceRegistry) throws Exception{
        NodeService nodeService = serviceRegistry.getNodeService();
        CheckOutCheckInService checkOutCheckInService= serviceRegistry.getCheckOutCheckInService();

        // authenticate
        AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
        authenticationService.authenticate("admin", "admin".toCharArray());
       
        // get the store
        StoreRef storeRef = new StoreRef(
                StoreRef.PROTOCOL_WORKSPACE,
                "SpacesStore"
                );
        if (!nodeService.exists(storeRef))
        {
            return;
        }
       
        NodeRef companyHomeNode = getCompanyHome(nodeService, storeRef);
       
        if (companyHomeNode == null)return;
       
        NodeRef fileNodeRef = getNodeByPath(serviceRegistry, companyHomeNode, "testContent:testVersionedTextFile");
        if (fileNodeRef == null){
           System.out.println(" node created for versioned file not found");
        }
        else {
           System.out.println(" node created for versioned file : " + fileNodeRef);
           NodeRef workingCopy = checkOutCheckInService.checkout(fileNodeRef);
           // workingCopy = checkOutCheckInService.getWorkingCopy(fileNodeRef);
           
            Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
            versionProperties.put(Version.PROP_DESCRIPTION, "checkin made by test program");
            versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
           checkOutCheckInService.checkin(workingCopy, versionProperties);

        }                         
    }
   

but if I uncomment the line            "// workingCopy = checkOutCheckInService.getWorkingCopy(fileNodeRef);", then I obtain the exception "Exception in thread "main" net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
".

   It seems that the "getWorkingCopy" method do not return a good reference.


  More interesting : if I modify this code like this :


           System.out.println(" node created for versioned file : " + fileNodeRef);
           NodeRef workingCopy = checkOutCheckInService.checkout(fileNodeRef);
            NodeRef workingCopy2 = checkOutCheckInService.getWorkingCopy(fileNodeRef);
           if (workingCopy != workingCopy2){
              System.out.println("workingCopy != workingCopy2");
           }
           else {
              System.out.println("workingCopy == workingCopy2");
           }
            Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
            versionProperties.put(Version.PROP_DESCRIPTION, "checkin made by test program");
            versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
           checkOutCheckInService.checkin(workingCopy, versionProperties);


   I obtain the following output :

workingCopy != workingCopy2
Exception in thread "main" 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:170)
   at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:37)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:170)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:176)
   at $Proxy45.checkin(Unknown Source)
   at org.alfresco.example.MySimpleExampleWithContent.testCheckOutCheckInFile(MySimpleExampleWithContent.java:843)
   at org.alfresco.example.MySimpleExampleWithContent.access$0(MySimpleExampleWithContent.java:804)
   at org.alfresco.example.MySimpleExampleWithContent$1.doWork(MySimpleExampleWithContent.java:112)
   at org.alfresco.repo.transaction.TransactionUtil.executeInTransaction(TransactionUtil.java:168)
   at org.alfresco.repo.transaction.TransactionUtil.executeInUserTransaction(TransactionUtil.java:74)
   at org.alfresco.example.MySimpleExampleWithContent.main(MySimpleExampleWithContent.java:116)

   Notice that the exception occurs during the execution of the call to checkOutCheckInService.checkin().  Then it seems that the call to checkOutCheckInService.getWorkingCopy() will disturb the next (we do not use here the reference returned by getWorkingCopy as an argument to checkin).




   Regards,

           Andre

anweber
Champ in-the-making
Champ in-the-making
Hi,

     I still have the same problem : if I call "checkOutCheckInService.checkin()" after a call to "checkOutCheckInService.getWorkingCopy()", I obtain an exception : net.sf.acegisecurity.BadCredentialsException: Bad credentials presented during the excecution of "checkOutCheckInService.checkin()".  It occurs even when I do not use the nodeRef returned by checkOutCheckInService.getWorkingCopy()".

There is an extract of my code.  The problem occurs if I uncomment the call to "checkOutCheckInService.getWorkingCopy()".  Of course, it's not usefull here but in real cases where we do not already have the reference of the "working copy".


          System.out.println(" node created for versioned file : " + fileNodeRef);
           NodeRef workingCopy = checkOutCheckInService.checkout(fileNodeRef);
           /* if I uncomment the following lines of code, I obtain an exception during the execution
            *   Exception in thread "main" net.sf.acegisecurity.BadCredentialsException: Bad credentials presented
               at ec.ep.dit.isp.sp.alfrescoeval.TestApiWithVisualChecks.testCheckOutCheckInFile(TestApiWithVisualChecks.java:812)
            *   (this is the line where I call the "checkin" method).
            *
            NodeRef workingCopy2 = checkOutCheckInService.getWorkingCopy(fileNodeRef);
           if (!workingCopy.equals(workingCopy2)){
              System.out.println("workingCopy != workingCopy2");
           }
           else {
              System.out.println("workingCopy == workingCopy2");
           }
           */
            Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
            versionProperties.put(Version.PROP_DESCRIPTION, "checkin made by test program");
            versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
           checkOutCheckInService.checkin(workingCopy, versionProperties);

     Could you help me, please.

              Regards,

                      Andre