cancel
Showing results for 
Search instead for 
Did you mean: 

How to connect alfresco_server_A from WAR on Server_B

vasutech
Champ in-the-making
Champ in-the-making
Hi,

I want to decouple the clients from alfresco server. Currently I am using RMI to connect to alfresco from other webapplication and stand alone applications, but I have a problem with the acegi thread local issue of bad credentials.

Can any body give me a clean way to connect to alfresco from webapplications running on various servers and use JCR API.

My Environment:

JDK 5.5
Tomcat 5.5
Sun Solaris
Alfresco 1.4
oracle 9i

I have set up alfresco on the above mentioned environment.
I have enabled JCR RMI.
I am able to connect to the alfresco server using a java stand alone application and other web applications running on ther servers using RMI.

I am getting the acegi security error about bad credentials ,seems to be an issue since 2005.
Is there any other way of connecting to the alfresco server to use  JCR API. I have five web applications running on various webservers and need to use alfresco as a content server and should be able to connect.
Any solution will be appreciated.

Currently all the five webapplications use documentum as content server. Need to switch to alfresco.

Complete stack trace of the error:
creation Exception is org.apache.jackrabbit.rmi.client.RemoteRepositoryException: Error unmarshaling return; nested exception is:
   java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled): Error unmarshaling return; nested exception is:
   java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled)
org.apache.jackrabbit.rmi.client.RemoteRepositoryException: Error unmarshaling return; nested exception is:
   java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled): Error unmarshaling return; nested exception is:
   java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled)
   at org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.java:132)
   at org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.java:173)
   at net.att.jcrrmi.AttCollateral.createCollateral(AttCollateral.java:202)
   at net.att.jcrrmi.AttCollateral.main(AttCollateral.java:36)
Caused by: java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
   java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled)
   at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
   at sun.rmi.server.UnicastRef.invoke(Unknown Source)
   at org.apache.jackrabbit.rmi.server.ServerNode_Stub.setProperty(Unknown Source)
   at org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.java:127)
   … 3 more
Caused by: java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled)
   at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
   at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
   at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
   at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
   at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
   at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
   at java.io.ObjectInputStream.readClassDesc(Unknown Source)
   at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
   at java.io.ObjectInputStream.readObject0(Unknown Source)
   at java.io.ObjectInputStream.readObject(Unknown Source)
   … 7 more
java.rmi.UnmarshalException: Error unmarshaling return; nested exception is:
   java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled)
   at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
   at sun.rmi.server.UnicastRef.invoke(Unknown Source)
   at org.apache.jackrabbit.rmi.server.ServerNode_Stub.setProperty(Unknown Source)
   at org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.java:127)
   at org.apache.jackrabbit.rmi.client.ClientNode.setProperty(ClientNode.java:173)
   at net.att.jcrrmi.AttCollateral.createCollateral(AttCollateral.java:202)
   at net.att.jcrrmi.AttCollateral.main(AttCollateral.java:36)
Caused by: java.lang.ClassNotFoundException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException (no security manager: RMI class loader disabled)
   at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
   at sun.rmi.server.LoaderHandler.loadClass(Unknown Source)
   at java.rmi.server.RMIClassLoader$2.loadClass(Unknown Source)
   at java.rmi.server.RMIClassLoader.loadClass(Unknown Source)
   at sun.rmi.server.MarshalInputStream.resolveClass(Unknown Source)
   at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
   at java.io.ObjectInputStream.readClassDesc(Unknown Source)
   at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
   at java.io.ObjectInputStream.readObject0(Unknown Source)
   at java.io.ObjectInputStream.readObject(Unknown Source)
   … 7 more

—————————————–

package net.att.jcrrmi;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Calendar;
import java.util.Date;

import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.Value;
import javax.jcr.Workspace;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.jcr.version.Version;
import javax.jcr.version.VersionHistory;
import javax.jcr.version.VersionIterator;

public class AttCollateral {

    public static void main(String[] args) throws Exception {
        AttCollateral work = new AttCollateral();
        Repository repository = RepositoryFactory.getJcrRepository();
        Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
        try {
            work.createCollateral(session);
            work.accessCollateral(session);
            work.browseAllCollateral(session);
            work.searchCollateral(session);
            work.exportAllCollateral(session);
            work.createVersion(session);
            session.logout();
            Session session1 = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
            work.browseVersionHistory(session1);

        } finally {
            session.logout();
        }

    }

    public void browseVersionHistory(Session session) throws RepositoryException {
        Node rootNode = session.getRootNode();
        Node entry1 = rootNode.getNode("app:company_home/collateral:collateralHome/collateral:ctl1");

        // retrieve the history for this collateral
        VersionHistory versionHistory = entry1.getVersionHistory();
        VersionIterator versionIterator = versionHistory.getAllVersions();
        // for each version, output the node as it was versioned
        System.out.println("Displaying all versions…………");
        while (versionIterator.hasNext()) {
            Version version = versionIterator.nextVersion();
            NodeIterator nodeIterator = version.getNodes();

            while (nodeIterator.hasNext()) {
                Node versionedNode = nodeIterator.nextNode();
                System.out.println(" Version: " + version.getName());
                System.out.println(" Created: " + version.getCreated().getTime());
                outputContentNode(versionedNode);
            }
        }

        System.out.println("Testing Permissions:");

        // check for JCR 'read' permission
        session.checkPermission("app:company_home/collateral:collateralHome/collateral:ctl1", "read");
        System.out.println("Session has 'read' permission on app:company_home/collateral:collateralHome/collateral:ctl1");

    }

    private static void outputContentNode(Node node) throws RepositoryException {
        // output common content properties
        System.out.println(" Node " + node.getUUID());
        System.out.println("  name: " + node.getProperty("collateral:name").getString());

        // output properties specific to collateral bundle
        if (node.getPrimaryNodeType().getName().equals("collateral:bundle")) {
            System.out.println("  author: " + node.getProperty("collateral:author").getString());
            System.out.println("  active: " + node.getProperty("collateral:active").getString());
            System.out.println("  language: " + node.getProperty("collateral:language").getString());
            System.out.println("  fileName: " + node.getProperty("collateral:fileName").getString());
            node.getProperties();

            // output multi-value property
            Property segmentProperty = node.getProperty("collateral:segments");
            Value[] segments = segmentProperty.getValues();
            for (Value segment : segments) {
                System.out.println("  segment: " + segment.getString());
            }
        }
    }

    public void createVersion(Session session) throws RepositoryException {
        Node rootNode = session.getRootNode();
        Node entry1 = rootNode.getNode("app:company_home/collateral:collateralHome/collateral:ctl1");

        // enable versioning capability
        // entry1.addMixin("mix:versionable");
        // no need to do above line as the content is versionable by
        // definition
        // update the properties and content
        entry1.checkout();
        entry1.setProperty("collateral:name", "name_modified_2");
        entry1.setProperty("collateral:language", "UNKNOWN_LANGUAGE_JUNTA");
        Value[] segments = entry1.getProperty("collateral:segments").getValues();
        Value[] newSegments = new Value[segments.length + 1];
        System.arraycopy(segments, 0, newSegments, 0, segments.length);
        newSegments[segments.length] = session.getValueFactory().createValue("SEGMENT_NEW");
        entry1.setProperty("collateral:segments", newSegments);

        entry1.checkin();

        session.save();
        System.out.println("Versioned collateral Page 1");
        Node entryVersioned = rootNode.getNode("app:company_home/collateral:collateralHome/collateral:ctl1");
        outputContentNode(entryVersioned);
    }

    public void exportAllCollateral(Session session) throws Exception {
        // export content (system view format)
        File systemView = new File("systemview.xml");
        FileOutputStream systemViewOut = new FileOutputStream(systemView);
        session.exportSystemView("/app:company_home/collateral:collateralHome", systemViewOut, false, false);

        // export content (document view format)
        File docView = new File("docview.xml");
        FileOutputStream docViewOut = new FileOutputStream(docView);
        session.exportDocumentView("/app:company_home/collateral:collateralHome", docViewOut, false, false);

        System.out.println("Collateral exported");
    }

    public void searchCollateral(Session session) throws RepositoryException {
        System.out.println("Search results:");
        Workspace workspace = session.getWorkspace();
        QueryManager queryManager = workspace.getQueryManager();
        Query query = queryManager.createQuery("//app:company_home/collateral:collateralHome/*[@collateral:name = 'myFirstCTL']", Query.XPATH);

        QueryResult result = query.execute();
        NodeIterator it = result.getNodes();
        while (it.hasNext()) {
            Node n = it.nextNode();
            outputContentNode(n);
        }
    }

    public void browseAllCollateral(Session session) throws RepositoryException {
        Node rootNode = session.getRootNode();
        Node collateralHome = rootNode.getNode("app:company_home/collateral:collateralHome");
        System.out.println("collateral browser:");
        NodeIterator entries = collateralHome.getNodes();
        while (entries.hasNext()) {
            Node entry = entries.nextNode();
            outputContentNode(entry);
        }
    }

    public void accessCollateral(Session session) throws RepositoryException {
        Node rootNode = session.getRootNode();
        Node collateralHome = rootNode.getNode("app:company_home/collateral:collateralHome");
        Node direct = session.getNodeByUUID(collateralHome.getUUID());
        System.out.println("Found COLLATERAL root correctly: " + collateralHome.equals(direct));

        // access a collateral property directly from root node
        Node entry1 = rootNode.getNode("app:company_home/collateral:collateralHome/collateral:ctl1");
        String title = entry1.getProperty("collateral:name").getString();
        System.out.println("Found collateral with name: " + title);
        Calendar created = entry1.getProperty("collateral:createDate").getDate();
        System.out.println("Found collateral with create date: " + created.getTime());
    }

    public void createCollateral(Session session) throws RepositoryException {
        try {
            System.out.println("Creating Collateral…");
            Node rootNode = session.getRootNode();
            System.out.println("Root node: path=" + rootNode.getPath() + ", type=" + rootNode.getPrimaryNodeType().getName());
            Node companyHome = rootNode.getNode("app:company_home");
            System.out.println("Company home node: path=" + companyHome.getPath() + ", type=" + companyHome.getPrimaryNodeType().getName());

            // remove the COLLATERAL structure if it already exists
            try {
                Node collateralHome = companyHome.getNode("collateral:collateralHome");
                collateralHome.remove();
                System.out.println("Existing collateralHome found and removed");
            } catch (PathNotFoundException e) {
                // doesn't exist, no need to remove
            }

            // create the root COLLATERAL folder
            System.out.println("create the root Collateral folder");
            Node collateralHome = companyHome.addNode("collateral:collateralHome", "cm:folder");
            collateralHome.setProperty("cm:name", "Collateral Home Folder");
            collateralHome.setProperty("cm:description", "All collaterals will reside here");

            // create first collateral
            Node ctl1 = collateralHome.addNode("collateral:ctl1", "collateral:bundle");
            ctl1.setProperty("collateral:name", "myFirstCTL");
            ctl1.setProperty("collateral:number", 1);
            ctl1.setProperty("collateral:description", "My first collateral");
            ctl1.setProperty("collateral:fileName", "ctl.pdf");
            ctl1.setProperty("collateral:imageName", "ctl.jpg");
            InputStream isimage = new BufferedInputStream(new FileInputStream("C:\\Documents and Settings\\vasutech\\My Documents\\My Pictures\\agent1.jpg"));
            InputStream isfile = new BufferedInputStream(new FileInputStream("C:\\Documents and Settings\\vasutech\\My Documents\\PDF-NOT-AVAILABLE.pdf"));
            ctl1.setProperty("collateral:fileContent", isfile);
            ctl1.setProperty("collateral:imageContent", isimage);
            ctl1.setProperty("collateral:portfolios", new String[] { "portfolio1" });
            ctl1.setProperty("collateral:segments", new String[] { "segment1", "segment2" });
            ctl1.setProperty("collateral:deliveryTypes", new String[] { "email", "print" });
            ctl1.setProperty("collateral:updateFlag", "none");
            ctl1.setProperty("collateral:language", "english");
            ctl1.setProperty("collateral:active", true);
            ctl1.setProperty("collateral:author", "sn2647");
            ctl1.setProperty("collateral:createDate", new Date().getTime());
            ctl1.setProperty("collateral:effectiveDate", new Date().getTime());
            ctl1.setProperty("collateral:expiryDate", new Date().getTime());

            session.save();
            System.out.println("collateral created");
        } catch (Exception e) {
            System.out.println("creation Exception is " + e);
            e.printStackTrace();
        }
    }

}

Thanks,
Vasutech.
1 REPLY 1

bindiya
Champ in-the-making
Champ in-the-making
Use JackRabbit RMI approach to connect Alfresco from remote server.

Bindiya
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.