为Jackrabbit启用搜索索引时获得NullPointerException

时间:2012-02-15 11:49:49

标签: junit lucene jackrabbit

我目前正在开发积极使用长耳兔的应用程序。这是我第一次使用长耳兔的经历。我使用基于h2的配置进行junit测试。在我的repository.xml中禁用了Lucene搜索,唯一的问题是日志文件中的以下异常:

ERROR org.apache.jackrabbit.core.security.user.MembershipCache  - Failed to retrieve membership references of 21232f29-7a57-35a7-8389-4a0e4a801fc3. 
javax.jcr.RepositoryException: no search manager configured for this workspace

所有单元测试都通过了。当我开始测试使用UserManager.findAuthorizables的功能时,我必须在repository.xml中启用SearchIndex 现在所有测试都失败,令人沮丧的是NullPointerException:

java.lang.NullPointerException
    at org.apache.jackrabbit.core.query.lucene.MultiScorer.nextDoc(MultiScorer.java:68)
    at org.apache.lucene.search.ConjunctionScorer.<init>(ConjunctionScorer.java:42)
    at org.apache.lucene.search.ConjunctionScorer.<init>(ConjunctionScorer.java:33)
    at org.apache.lucene.search.BooleanScorer2$2.<init>(BooleanScorer2.java:173)
    at org.apache.lucene.search.BooleanScorer2.countingConjunctionSumScorer(BooleanScorer2.java:173)
    at org.apache.lucene.search.BooleanScorer2.makeCountingSumScorerSomeReq(BooleanScorer2.java:234)
    at org.apache.lucene.search.BooleanScorer2.makeCountingSumScorer(BooleanScorer2.java:211)
    at org.apache.lucene.search.BooleanScorer2.<init>(BooleanScorer2.java:101)
    at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:328)
    at org.apache.jackrabbit.core.query.lucene.ChildAxisQuery$ChildAxisWeight.scorer(ChildAxisQuery.java:334)
    at org.apache.jackrabbit.core.query.lucene.ChildAxisQuery$ChildAxisWeight.scorer(ChildAxisQuery.java:332)
    at org.apache.jackrabbit.core.query.lucene.DescendantSelfAxisQuery$DescendantSelfAxisWeight.scorer(DescendantSelfAxisQuery.java:395)
    at org.apache.jackrabbit.core.query.lucene.LuceneQueryHits.<init>(LuceneQueryHits.java:52)
    at org.apache.jackrabbit.core.query.lucene.JackrabbitIndexSearcher.evaluate(JackrabbitIndexSearcher.java:107)
    at org.apache.jackrabbit.core.query.lucene.JackrabbitIndexSearcher.execute(JackrabbitIndexSearcher.java:85)
    at org.apache.jackrabbit.core.query.lucene.SearchIndex.executeQuery(SearchIndex.java:814)
    at org.apache.jackrabbit.core.query.lucene.SingleColumnQueryResult.executeQuery(SingleColumnQueryResult.java:74)
    at org.apache.jackrabbit.core.query.lucene.QueryResultImpl.getResults(QueryResultImpl.java:275)
    at org.apache.jackrabbit.core.query.lucene.SingleColumnQueryResult.<init>(SingleColumnQueryResult.java:66)
    at org.apache.jackrabbit.core.query.lucene.QueryImpl.execute(QueryImpl.java:134)
    at org.apache.jackrabbit.core.query.QueryImpl$1.perform(QueryImpl.java:132)
    at org.apache.jackrabbit.core.query.QueryImpl$1.perform(QueryImpl.java:129)
    at org.apache.jackrabbit.core.session.SessionState.perform(SessionState.java:216)
    at org.apache.jackrabbit.core.query.QueryImpl.execute(QueryImpl.java:128)
    at org.apache.jackrabbit.core.security.user.IndexNodeResolver.findNode(IndexNodeResolver.java:73)
    at org.apache.jackrabbit.core.security.user.UserManagerImpl.getAuthorizable(UserManagerImpl.java:465)
    at org.apache.jackrabbit.core.security.user.UserManagerImpl.setPrincipal(UserManagerImpl.java:698)
    at org.apache.jackrabbit.core.security.user.UserManagerImpl.createUser(UserManagerImpl.java:558)
    at org.apache.jackrabbit.core.security.user.UserManagerImpl.createUser(UserManagerImpl.java:541)
    at org.apache.jackrabbit.core.security.user.UserManagerImpl.createAdmin(UserManagerImpl.java:948)
    at org.apache.jackrabbit.core.security.user.UserManagerImpl.getAuthorizable(UserManagerImpl.java:426)
    at org.apache.jackrabbit.core.DefaultSecurityManager.createSystemUsers(DefaultSecurityManager.java:613)
    at org.apache.jackrabbit.core.DefaultSecurityManager.init(DefaultSecurityManager.java:204)
    at org.apache.jackrabbit.core.RepositoryImpl.initSecurityManager(RepositoryImpl.java:463)
    at org.apache.jackrabbit.core.RepositoryImpl.<init>(RepositoryImpl.java:324)
    at org.apache.jackrabbit.core.RepositoryImpl.create(RepositoryImpl.java:582)
    at org.apache.jackrabbit.core.TransientRepository$2.getRepository(TransientRepository.java:232)
    at org.apache.jackrabbit.core.TransientRepository.startRepository(TransientRepository.java:280)
    at org.apache.jackrabbit.core.TransientRepository.login(TransientRepository.java:376)
    at ru.e.e.s.s.BaseJackrabbitRelatedTests.startRepository(BaseJackrabbitRelatedTests.java:81)
    at ru.e.e.s.s.BaseJackrabbitRelatedTests.setUp(BaseJackrabbitRelatedTests.java:64)
    at ru.e.e.s.s.i.p.JackrabbitIdentityRepositoryTests.setUp(JackrabbitIdentityRepositoryTests.java:28)
    ...

这是我的repository.xml,它使用默认搜索索引配置:

<?xml version="1.0"?> 
<!DOCTYPE Repository PUBLIC "-//The Apache Software Foundation//DTD Jackrabbit 2.0//EN" "http://jackrabbit.apache.org/dtd/repository-2.0.dtd">
<Repository>
    <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
        <param name="driver" value="org.h2.Driver"/>
        <param name="url" value="jdbc:h2:memFS:test"/>
    </FileSystem>
    <DataStore class="org.apache.jackrabbit.core.data.FileDataStore"/>
    <Security appName="Jackrabbit">
        <SecurityManager class="org.apache.jackrabbit.core.DefaultSecurityManager" workspaceName="security">
            <WorkspaceAccessManager class="org.apache.jackrabbit.core.security.simple.SimpleWorkspaceAccessManager"/> 
        </SecurityManager>
        <AccessManager class="org.apache.jackrabbit.core.security.DefaultAccessManager" />
        <LoginModule class="org.apache.jackrabbit.core.security.authentication.DefaultLoginModule">
            <param name="adminId" value="admin"/>
            <param name="anonimousId" value=""/>
        </LoginModule>
    </Security>
    <Workspaces rootPath="${rep.home}/workspaces" defaultWorkspace="default"/>
    <Workspace name="${wsp.name}">
        <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
            <param name="driver" value="org.h2.Driver"/>
            <param name="url" value="jdbc:h2:memFS:testWsp"/>
        </FileSystem>
        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
            <param name="driver" value="org.h2.Driver"/>
            <param name="url" value="jdbc:h2:mem:itemState"/>
        </PersistenceManager>
        <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
            <param name="path" value="${wsp.home}/index"/>
            <param name="extractorPoolSize" value="2"/>
        </SearchIndex>
    </Workspace>
    <Versioning rootPath="${rep.home}/version">
        <FileSystem class="org.apache.jackrabbit.core.fs.db.DbFileSystem">
            <param name="driver" value="org.h2.Driver"/>
            <param name="url" value="jdbc:h2:memFS:test/version"/>
        </FileSystem>
        <PersistenceManager class="org.apache.jackrabbit.core.persistence.pool.H2PersistenceManager">
            <param name="driver" value="org.h2.Driver"/>
            <param name="url" value="jdbc:h2:mem:version;db_close_delay=10"/>
        </PersistenceManager>
    </Versioning>
    <SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
        <param name="path" value="${rep.home}/repository/index"/>
        <param name="extractorPoolSize" value="2"/>
    </SearchIndex>
</Repository>

存储库启动代码:

public abstract class BaseJackrabbitRelatedTests {
    protected static Repository testRepository;
    protected static Credentials adminCredentials;
    private Session keepAliveSession;

    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
        cleanRepository();
        testRepository = new TransientRepository(JACKRABBIT_CONFIGURATION_FILE, JACKRABBIT_REPOSITORY_PATH);
        adminCredentials = new SimpleCredentials(JACKRABBIT_USERNAME, JACKRABBIT_PASSWORD.toCharArray());
    }

    private static void cleanRepository() throws Exception {
        FileUtils.deleteQuietly(new File(JACKRABBIT_REPOSITORY_PATH));
    }

    @Before
    public void setUp() throws Exception {
        startRepository();
        ...
    }

    private void startRepository() throws Exception {
        if (keepAliveSession == null) {
            keepAliveSession = testRepository.login(adminCredentials, JACKRABBIT_DEFAULT_WORKSPACE);
        }
    }
    ...
}

我在Jackrabbit 2.3.4上发现了这个问题。我试图使用最近发布的2.4.0 - 没有成功 看来jackrabbit无法创建LoginModule配置部分中列出的用户。但为什么?我错过了什么?

2 个答案:

答案 0 :(得分:1)

我的错误。
我检查了我的常春藤存储库,发现apache lucene是由较新版本 3.3.0 发布的。 Jackrabbit的发行使用 lucene 3.0.3
当我发表“长大熊猫友好”时,lucene版本的测试开始传递。

答案 1 :(得分:0)

我知道这个问题太老了。但是我会为遇到此错误的新手回答。

如果要使用存储库的搜索功能,则需要手动配置它。如果无法在工作空间中找到搜索管理器的配置,则表示 workspace.xml 中的 SearchIndex 标签无效。

这是操作方法:

打开文件./jackrabbit/workspaces/your_workspace/worspace.xml 在

之间添加或激活以下内容
<SearchIndex class="org.apache.jackrabbit.core.query.lucene.SearchIndex">
    <param name="path" value="${wsp.home}/index"/>
    <param name="extractorPoolSize" value="2"/>
</SearchIndex>

然后重新启动实例。

注意:我建议您从工作空间.xml中的repository.xml复制 SearchIndex 标记。