openCMIS 本地绑定 - JcrServiceFactory 与 jackRabbit 实现
嘿,第三种替代方案有问题,因为JcrServiceFactory
中的循环正在搜索以 jcr.* 开头的属性(其他属性不会传递),但紧接着在 RepositoryFactoryImpl
(Jackrabbit impl) 中搜索“org.jcr.*”。 apache.jackrabbit.repository.home”在传递的属性集合中......这没有意义。即使 org.apache.jackrabbit.repository.home 存在,它也不会以 PREFIX_JCR_CONFIG
开头,因此它不会放入 jcrConfig
集合中,该集合会转到 RepositoryFactoryImpl .getRepository()
如果 Map
因为RepositoryFactoryImpl
中存在if(parameters == null)
条件,但是这并不是
发生在init方法
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);
}
中而是这里参数Map为空{},返回null;因为它正在搜索RepositoryFactoryImpl.REPOSITORY_HOME,即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>
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 RepositoryFactoryImpl.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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
答案就在我抱怨的循环中:-)
它是一个子字符串,所以它会削减jcr。其余的继续...
这是一个棘手的问题,需要通过调试来弄清楚所有这些。
The answer is right in the loop I complained about :-)
It's a substring, so it cuts jcr. of and the rest goes on...
It's a tricky and one kinda needs to figure out all this from debugging.
您需要使用以下条目在“WEB-INF/classes”处配置“repository.properties”。
jcr.org.apache.jackrabbit.repository.home={user.home}\jcr-repository(您的存储库位置)。
干杯。
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.