You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@chemistry.apache.org by "Joseph Vychtrle (JIRA)" <ji...@apache.org> on 2011/03/23 00:54:05 UTC

[jira] [Updated] (CMIS-336) Local binding with JcrServiceFactory

     [ https://issues.apache.org/jira/browse/CMIS-336?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Joseph Vychtrle updated CMIS-336:
---------------------------------

    Description: 
Hey, there is something wrong, because the loop in JcrServiceFactory is searching for properties starting with jcr.*, but right after in RepositoryFactoryImpl it is searched for "org.apache.jackrabbit.repository.home" in the same collection of properties, that doesn't make sense. even if org.apache.jackrabbit.repository.home is there, it doesn't start with PREFIX_JCR_CONFIG so it is put into jcrConfig collection that goes to RepositoryFactoryImpl.getRepository()

{code:title=JcrServiceFactory.java|borderStyle=solid}
 private void readConfiguration(Map<String, String> parameters) {
        Map<String, String> map = new HashMap<String, String>();
        List<String> keys = new ArrayList<String>(parameters.keySet());
        Collections.sort(keys);

/* the loop is searching for properties starting with jcr.* */
 
        for (String key : keys) {
            if (key.startsWith(PREFIX_JCR_CONFIG)) {
                String jcrKey = key.substring(PREFIX_JCR_CONFIG.length());
                String jcrValue = replaceSystemProperties(parameters.get(key));
                map.put(jcrKey, jcrValue);
            }

            else if (MOUNT_PATH_CONFIG.equals(key)) {
                mountPath = parameters.get(key);
                log.debug("Configuration: " + MOUNT_PATH_CONFIG + '=' + mountPath);
            }

            else {
                log.warn("Configuration: unrecognized key: " + key);
            }
        }

        jcrConfig = Collections.unmodifiableMap(map);
        log.debug("Configuration: jcr=" + jcrConfig);
    }
{code}

But here the parameter Map is empty {} and it returns null; because it is searching for RepositoryFactoryImpl.REPOSITORY_HOME, which is org.apache.jackrabbit.repository.home

{code:title=RepositoryFactoryImpl.java|borderStyle=solid}
/* parameters = jcrConfig */
public Repository getRepository(Map parameters) throws RepositoryException {
        if (parameters == null) {
            return getRepository(null, Collections.emptyMap());
        } else if (parameters.containsKey(REPOSITORY_HOME)) {
            String home = parameters.get(REPOSITORY_HOME).toString();
            return getRepository(home, parameters);
        } else if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) {
            Object parameter = parameters.get(JcrUtils.REPOSITORY_URI);
            try {
                URI uri = new URI(parameter.toString().trim());
                String scheme = uri.getScheme();
                if (("file".equalsIgnoreCase(scheme)
                        || "jcr-jackrabbit".equalsIgnoreCase(scheme))
                        && uri.getAuthority() == null) {
                    File file = new File(uri.getPath());
                    if (file.isFile()) {
                        return null; // Not a (possibly missing) directory
                    } else {
                        return getRepository(file.getPath(), parameters);
                    }
                } else {
                    return null; // not a file: or jcr-jackrabbit: URI
                }
            } catch (URISyntaxException e) {
                return null; // not a valid URI
            }
        } else {
            return null; // unknown or insufficient parameters
        }
    }
{code}


{code:xml} 
<dependencies>

		<dependency>
			<groupId>javax.jcr</groupId>
			<artifactId>jcr</artifactId>
			<version>2.0</version>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>org.apache.jackrabbit</groupId>
			<artifactId>jackrabbit-core</artifactId>
			<version>2.2.4</version>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>org.apache.jackrabbit</groupId>
			<artifactId>jackrabbit-api</artifactId>
			<version>2.2.4</version>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.5.11</version>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>5.14</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
		
		<dependency>
			<groupId>org.apache.chemistry.opencmis</groupId>
			<artifactId>chemistry-opencmis-server-jcr</artifactId>
			<version>0.3.0-incubating-SNAPSHOT</version>
			<classifier>classes</classifier>
		</dependency>

		<dependency>
			<groupId>org.apache.chemistry.opencmis</groupId>
			<artifactId>chemistry-opencmis-client-bindings</artifactId>
			<version>0.3.0-incubating-SNAPSHOT</version>
		</dependency>

		<dependency>
			<groupId>org.apache.chemistry.opencmis</groupId>
			<artifactId>chemistry-opencmis-client-api</artifactId>
			<version>0.3.0-incubating-SNAPSHOT</version>
		</dependency>

		<dependency>
			<groupId>org.apache.chemistry.opencmis</groupId>
			<artifactId>chemistry-opencmis-client-impl</artifactId>
			<version>0.3.0-incubating-SNAPSHOT</version>
		</dependency>
	
	</dependencies>
{code} 

  was:
The problem is that classloader doesn't see JcrServiceFactory to load it up, even though it is on the classpath

{code:title=cmisTest.java|borderStyle=solid}
SessionFactory factory = SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String, String>();

// user credentials
parameters.put(SessionParameter.USER, "username");
parameters.put(SessionParameter.PASSWORD, "password");

// connection settings
parameters.put(SessionParameter.BINDING_TYPE, BindingType.LOCAL.value());
parameters.put(SessionParameter.LOCAL_FACTORY, JcrServiceFactory.class.getName());
parameters.put(SessionParameter.REPOSITORY_ID, "myRepository");

// create session
org.apache.chemistry.opencmis.client.api.Session session = factory.createSession(parameters);
{code}
{code:title=CmisLocalSpi.java|borderStyle=solid}
      // create and initialize factory
      factory = (CmisServiceFactory) Class.forName(serviceFactoryClassname).newInstance();
      factory.init(parameters);
  } catch (Exception e) {
      throw new CmisConnectionException("Factory cannot be created!", e);
 }
{code}

org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: Factory cannot be created!
	at org.apache.chemistry.opencmis.client.bindings.spi.local.CmisLocalSpi.getSpiInstance(CmisLocalSpi.java:96)
	at org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingsHelper.getSPI(CmisBindingsHelper.java:81)
	at org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingImpl.clearAllCaches(CmisBindingImpl.java:172)
	at org.apache.chemistry.opencmis.client.bindings.impl.CmisBindingImpl.<init>(CmisBindingImpl.java:95)
	at org.apache.chemistry.opencmis.client.bindings.CmisBindingFactory.createCmisLocalBinding(CmisBindingFactory.java:154)
	at org.apache.chemistry.opencmis.client.runtime.CmisBindingHelper.createLocalBinding(CmisBindingHelper.java:96)
	at org.apache.chemistry.opencmis.client.runtime.CmisBindingHelper.createBinding(CmisBindingHelper.java:53)
	at org.apache.chemistry.opencmis.client.runtime.SessionImpl.connect(SessionImpl.java:561)
	at org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl.createSession(SessionFactoryImpl.java:61)
	at repository.RepoTest.createCmisServer(RepoTest.java:143)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:640)
	at org.testng.internal.Invoker.invokeMethod(Invoker.java:627)
	at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:799)
	at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1103)
	at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:137)
	at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:121)
	at org.testng.TestRunner.runWorkers(TestRunner.java:1098)
	at org.testng.TestRunner.privateRun(TestRunner.java:727)
	at org.testng.TestRunner.run(TestRunner.java:581)
	at org.testng.SuiteRunner.runTest(SuiteRunner.java:315)
	at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:310)
	at org.testng.SuiteRunner.privateRun(SuiteRunner.java:272)
	at org.testng.SuiteRunner.run(SuiteRunner.java:221)
	at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:40)
	at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:83)
	at org.testng.internal.thread.ThreadUtil$CountDownLatchedRunnable.run(ThreadUtil.java:151)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: JcrServiceFactory
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
	at org.apache.chemistry.opencmis.client.bindings.spi.local.CmisLocalSpi.getSpiInstance(CmisLocalSpi.java:93)
	... 32 more

{color:red} The problem is, that the chemistry-opencmis-server-jcr - classes.jar really is on the classpath, I can see that via maven and debugger{color} 

$ jar tf /opt/m2/repository/org/apache/chemistry/opencmis/chemistry-opencmis-server-jcr/0.3.0-incubating-SNAPSHOT/chemistry-opencmis-server-jcr-0.3.0-incubating-SNAPSHOT-classes.jar 
META-INF/
META-INF/MANIFEST.MF
org/
org/apache/
org/apache/chemistry/
org/apache/chemistry/opencmis/
org/apache/chemistry/opencmis/jcr/
org/apache/chemistry/opencmis/jcr/JcrRepository.class
org/apache/chemistry/opencmis/jcr/JcrConverter.class
org/apache/chemistry/opencmis/jcr/TypeManager$1.class
org/apache/chemistry/opencmis/jcr/JcrService.class
org/apache/chemistry/opencmis/jcr/Util.class
org/apache/chemistry/opencmis/jcr/JcrRepository$1.class
org/apache/chemistry/opencmis/jcr/JcrBinary.class
org/apache/chemistry/opencmis/jcr/JcrServiceFactory.class
org/apache/chemistry/opencmis/jcr/TypeManager.class
META-INF/LICENSE
META-INF/DEPENDENCIES
META-INF/NOTICE
META-INF/maven/
META-INF/maven/org.apache.chemistry.opencmis/
META-INF/maven/org.apache.chemistry.opencmis/chemistry-opencmis-server-jcr/
META-INF/maven/org.apache.chemistry.opencmis/chemistry-opencmis-server-jcr/pom.xml
META-INF/maven/org.apache.chemistry.opencmis/chemistry-opencmis-server-jcr/pom.properties
repository.properties                                      

{code:xml}
<dependencies>

	<dependency>
		<groupId>javax.jcr</groupId>
		<artifactId>jcr</artifactId>
		<version>2.0</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.apache.jackrabbit</groupId>
		<artifactId>jackrabbit-core</artifactId>
		<version>2.2.4</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.apache.jackrabbit</groupId>
		<artifactId>jackrabbit-api</artifactId>
		<version>2.2.4</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.slf4j</groupId>
		<artifactId>slf4j-log4j12</artifactId>
		<version>1.5.11</version>
		<scope>compile</scope>
	</dependency>

	<dependency>
		<groupId>org.testng</groupId>
		<artifactId>testng</artifactId>
		<version>5.14</version>
		<type>jar</type>
		<scope>compile</scope>
	</dependency>
	
	<dependency>
		<groupId>org.apache.chemistry.opencmis</groupId>
		<artifactId>chemistry-opencmis-server-jcr</artifactId>
		<version>0.3.0-incubating-SNAPSHOT</version>
		<classifier>classes</classifier>
	</dependency>

	<dependency>
		<groupId>org.apache.chemistry.opencmis</groupId>
		<artifactId>chemistry-opencmis-client-bindings</artifactId>
		<version>0.3.0-incubating-SNAPSHOT</version>
	</dependency>

	<dependency>
		<groupId>org.apache.chemistry.opencmis</groupId>
		<artifactId>chemistry-opencmis-client-api</artifactId>
		<version>0.3.0-incubating-SNAPSHOT</version>
	</dependency>

	<dependency>
		<groupId>org.apache.chemistry.opencmis</groupId>
		<artifactId>chemistry-opencmis-client-impl</artifactId>
		<version>0.3.0-incubating-SNAPSHOT</version>
	</dependency>

</dependencies>
{code}

    Environment:     (was: java 1.6, maven 3)
        Summary: Local binding with JcrServiceFactory  (was: java.lang.ClassNotFoundException: JcrServiceFactory)

> Local binding with JcrServiceFactory
> ------------------------------------
>
>                 Key: CMIS-336
>                 URL: https://issues.apache.org/jira/browse/CMIS-336
>             Project: Chemistry
>          Issue Type: Bug
>          Components: opencmis-server-jcr
>    Affects Versions: OpenCMIS 0.3.0
>            Reporter: Joseph Vychtrle
>              Labels: ClassNotFoundException
>
> Hey, there is something wrong, because the loop in JcrServiceFactory is searching for properties starting with jcr.*, but right after in RepositoryFactoryImpl it is searched for "org.apache.jackrabbit.repository.home" in the same collection of properties, that doesn't make sense. even if org.apache.jackrabbit.repository.home is there, it doesn't start with PREFIX_JCR_CONFIG so it is put into jcrConfig collection that goes to RepositoryFactoryImpl.getRepository()
> {code:title=JcrServiceFactory.java|borderStyle=solid}
>  private void readConfiguration(Map<String, String> parameters) {
>         Map<String, String> map = new HashMap<String, String>();
>         List<String> keys = new ArrayList<String>(parameters.keySet());
>         Collections.sort(keys);
> /* the loop is searching for properties starting with jcr.* */
>  
>         for (String key : keys) {
>             if (key.startsWith(PREFIX_JCR_CONFIG)) {
>                 String jcrKey = key.substring(PREFIX_JCR_CONFIG.length());
>                 String jcrValue = replaceSystemProperties(parameters.get(key));
>                 map.put(jcrKey, jcrValue);
>             }
>             else if (MOUNT_PATH_CONFIG.equals(key)) {
>                 mountPath = parameters.get(key);
>                 log.debug("Configuration: " + MOUNT_PATH_CONFIG + '=' + mountPath);
>             }
>             else {
>                 log.warn("Configuration: unrecognized key: " + key);
>             }
>         }
>         jcrConfig = Collections.unmodifiableMap(map);
>         log.debug("Configuration: jcr=" + jcrConfig);
>     }
> {code}
> But here the parameter Map is empty {} and it returns null; because it is searching for RepositoryFactoryImpl.REPOSITORY_HOME, which is org.apache.jackrabbit.repository.home
> {code:title=RepositoryFactoryImpl.java|borderStyle=solid}
> /* parameters = jcrConfig */
> public Repository getRepository(Map parameters) throws RepositoryException {
>         if (parameters == null) {
>             return getRepository(null, Collections.emptyMap());
>         } else if (parameters.containsKey(REPOSITORY_HOME)) {
>             String home = parameters.get(REPOSITORY_HOME).toString();
>             return getRepository(home, parameters);
>         } else if (parameters.containsKey(JcrUtils.REPOSITORY_URI)) {
>             Object parameter = parameters.get(JcrUtils.REPOSITORY_URI);
>             try {
>                 URI uri = new URI(parameter.toString().trim());
>                 String scheme = uri.getScheme();
>                 if (("file".equalsIgnoreCase(scheme)
>                         || "jcr-jackrabbit".equalsIgnoreCase(scheme))
>                         && uri.getAuthority() == null) {
>                     File file = new File(uri.getPath());
>                     if (file.isFile()) {
>                         return null; // Not a (possibly missing) directory
>                     } else {
>                         return getRepository(file.getPath(), parameters);
>                     }
>                 } else {
>                     return null; // not a file: or jcr-jackrabbit: URI
>                 }
>             } catch (URISyntaxException e) {
>                 return null; // not a valid URI
>             }
>         } else {
>             return null; // unknown or insufficient parameters
>         }
>     }
> {code}
> {code:xml} 
> <dependencies>
> 		<dependency>
> 			<groupId>javax.jcr</groupId>
> 			<artifactId>jcr</artifactId>
> 			<version>2.0</version>
> 			<scope>compile</scope>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.apache.jackrabbit</groupId>
> 			<artifactId>jackrabbit-core</artifactId>
> 			<version>2.2.4</version>
> 			<scope>compile</scope>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.apache.jackrabbit</groupId>
> 			<artifactId>jackrabbit-api</artifactId>
> 			<version>2.2.4</version>
> 			<scope>compile</scope>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.slf4j</groupId>
> 			<artifactId>slf4j-log4j12</artifactId>
> 			<version>1.5.11</version>
> 			<scope>compile</scope>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.testng</groupId>
> 			<artifactId>testng</artifactId>
> 			<version>5.14</version>
> 			<type>jar</type>
> 			<scope>compile</scope>
> 		</dependency>
> 		
> 		<dependency>
> 			<groupId>org.apache.chemistry.opencmis</groupId>
> 			<artifactId>chemistry-opencmis-server-jcr</artifactId>
> 			<version>0.3.0-incubating-SNAPSHOT</version>
> 			<classifier>classes</classifier>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.apache.chemistry.opencmis</groupId>
> 			<artifactId>chemistry-opencmis-client-bindings</artifactId>
> 			<version>0.3.0-incubating-SNAPSHOT</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.apache.chemistry.opencmis</groupId>
> 			<artifactId>chemistry-opencmis-client-api</artifactId>
> 			<version>0.3.0-incubating-SNAPSHOT</version>
> 		</dependency>
> 		<dependency>
> 			<groupId>org.apache.chemistry.opencmis</groupId>
> 			<artifactId>chemistry-opencmis-client-impl</artifactId>
> 			<version>0.3.0-incubating-SNAPSHOT</version>
> 		</dependency>
> 	
> 	</dependencies>
> {code} 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira