如何在 Alfresco 中执行并行 CMIS 请求? [英] How to perform a parallel CMIS requests in Alfresco?

查看:40
本文介绍了如何在 Alfresco 中执行并行 CMIS 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个 CMIS 请求,需要并行执行.但是当我尝试它时(使用 CompletableFutire 或 stream().parallel(),我得到了:

I have several CMIS requests and need to do them in parallel. But when I try it (using CompletableFutire or stream().parallel(), I got:

 java.util.concurrent.ExecutionException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext

对于我所做的查询:

 @Autowired
    @Qualifier("searchService")
    private org.alfresco.service.cmr.search.SearchService searchService;
....
 searchService.query(searchParameters);

我做错了什么?以下代码是我尝试并行执行 CMIS 的尝试之一:

What am I doing wrong? The following code is one of my attempt to perform CMIS in parallel:

    List<CompletableFuture<Form14Row>> requests =  Arrays.asList(setUpRow(1,beginnigString, endString, docType, NDBaseDocumentModel.DOC_KIND_GOST_R, searchParameters, "ГОСТ Р"),
                setUpRow(2,beginnigString, endString, docType, NDBaseDocumentModel.DOC_KIND_GOST, searchParameters, "ГОСТ") );
        CompletableFuture<Void> allRequests = CompletableFuture.allOf(
                requests.toArray(new CompletableFuture[requests.size()])
        );
        CompletableFuture<List<Form14Row>> allPageContentsFuture = allRequests.thenApply(v -> {
            return requests.stream()
                    .map(pageContentFuture -> pageContentFuture.join())
                    .collect(Collectors.toList());
        });

        //java.util.concurrent.ExecutionException: net.sf.acegisecurity.AuthenticationCredentialsNotFoundException: A valid SecureContext was not provided in the RequestContext
        try {
            List<Form14Row> rowss = allPageContentsFuture.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

...
    private CompletableFuture<Form14Row> setUpRow(Integer index, String beginnigString, String endString, String docType, String docKind, SearchParameters searchParameters, String groupPosition) {
        return CompletableFuture.supplyAsync(() -> {
            String cql = "SELECT p.cmis:objectId  FROM  ecmcnddoc:common_attr_aspect  AS d JOIN ecmcnddoc:biblio_attr_aspect AS p ON d.cmis:objectId = p.cmis:objectId JOIN ecmcnddoc:reg_attr_aspect AS s  ON s.cmis:objectId = p.cmis:objectId JOIN ecmcnddoc:spec_attr_aspect AS asp ON asp.cmis:objectId = p.cmis:objectId WHERE p.cmis:objectTypeId='D:" + docType + "' AND d.ecmcnddoc:doc_kind_cp_ecmcdict_value='" + docKind + "' AND p.ecmcnddoc:biblio_fond='" + NDBaseDocumentModel.BIBLIO_FUND + "' AND s.ecmcnddoc:doc_reg_date >= TIMESTAMP  '" + beginnigString + "T00:00:00.000+00:00' AND s.ecmcnddoc:doc_reg_date <= TIMESTAMP  '" + endString + "T00:00:00.000+00:00' AND (asp.ecmcnddoc:doc_status='draft' OR asp.ecmcnddoc:doc_status='actual')";
            searchParameters.setQuery(cql);
            ResultSet rs = customSearchService.query(searchParameters); // Exception here
            Form14Row isoRow = new Form14Row();
            isoRow.setCount(rs.length());
            isoRow.setIndex(index);
            isoRow.setKindName(groupPosition);
            return isoRow;
        });
    }

串行执行时一切正常

推荐答案

安全上下文绑定到主线程并且不会传播到子线程,您需要设置一个.也许您可以尝试修改此代码段:

Security context is binded to main thread and is not propagated to children threads, you would need to set one. Maybe you could try to adapt this snippet:

CompletableFuture.runAsync(() -> {
    try {
        AuthenticationUtil.pushAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser(userName);
        // Do your stuff...
    } finally {
        AuthenticationUtil.popAuthentication();
    }
});

这篇关于如何在 Alfresco 中执行并行 CMIS 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆