openCMIS Local binding - JcrServiceFactory with jackRabbit implementation
Hey, there is something wrong with the third alternative, because the loop in JcrServiceFactory
is searching for properties starting with jcr.* (others are not passed along), but right after in RepositoryFactoryImpl
(Jackrabbit impl) it is searched for "org.apache.jackrabbit.repository.home" in the collection of properties that was passed along... 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 not put into jcrConfig
collection that goes to RepositoryFactoryImpl.getRepository()
It would make sense if Map<String, String> map = null;
because there is if (parameters == null)
condition in RepositoryFactoryImpl
, but this does not
It happens in the init method
JcrServiceFactory.java
private TypeManager typeManager;
private Map<String, String> jcrConfig;
private String mountPath;
private JcrRepository jcrRepository;
@Override
public void init(Map<String, String> parameters) {
typeManager = new TypeManager();
readConfiguration(parameters);
jcrRepository = new JcrRepository(acquireJcrRepository(jcrConfig), mountPath, typeManager);
}
Caused by: org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException: No JCR repository factory for configured parameters
at org.apache.chemistry.opencmis.jcr.JcrServiceFactory.acquireJcrRepository(JcrServiceFactory.java:95)
at org.apache.chemistry.opencmis.jcr.JcrServiceFactory.init(JcrServiceFactory.java:61)
at org.apache.chemistry.opencmis.client.bindings.spi.local.CmisLocalSpi.getSpiInstance(CmisLocalSpi.java:94)
... 34 more
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);
}
But here the parameter Map is empty {} and it returns null; because it is searching for RepositoryFactor开发者_如何学PythonyImpl.REPOSITORY_HOME, which is org.apache.jackrabbit.repository.home
RepositoryFactoryImpl.java
/* 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
}
}
<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>
The answer is right in the loop I complained about :-)
String jcrKey = key.substring(PREFIX_JCR_CONFIG.length());
It's a substring, so it cuts jcr. of and the rest goes on...
parameters.put("jcr.org.apache.jackrabbit.repository.home", repositoryHome);
It's a tricky and one kinda needs to figure out all this from debugging.
you need to configure your 'repository.properties' at 'WEB-INF/classes' with below entry.
jcr.org.apache.jackrabbit.repository.home={user.home}\jcr-repository (your repository location).
Cheers.
精彩评论