javascript - 显示未经验证的文档

标签 javascript java alfresco cmis opencmis

我目前正在开发一个 java/jee 应用程序,使用 alfresco 作为 ged 和 spring 作为框架。我想在没有身份验证要求的情况下在导航器中显示一个文件。那么我该怎么做呢。顺便说一句,我有 2 个模块我的项目:通过休息调用进行通信的前端和后端。从后端我试图传递对象的字节数组但不幸的是我收到它作为字符串所以我无法使用它。那么有什么解决这个问题的建议吗?

   public Map<String, Object> getCourrierDetails(String idCourrier) throws Exception {
        Map<String, Object> courriersDetails = runtimeService.getVariables(idCourrier);
courriersDetails.put("idCourrier", idCourrier);
        DocumentDaoImpl dao=new DocumentDaoImpl();

        Document docCmis = (Document) dao.getDocument("workspace://SpacesStore/73871a36-9a6c-42c6-b3e3-7d68362fe9c0");

        byte[] myByteArray = readContent(docCmis.getContentStream().getStream());


        ByteArrayResource resource = new ByteArrayResource(myByteArray) {
            @Override
            public String getFilename() {
                return docCmis.getContentStreamFileName();
            }
        };
        System.out.println(resource.getFilename());
        //courriersDetails.put("resources", myByteArray);
        System.out.println(courriersDetails.get("resources")+" rrrr");
        //courriersDetails.put("contentStream",docCmis.getContentStream().getStream());
        return courriersDetails;
    }

最佳答案

假设您的前端和后端是自定义的,并且您的后端与 Alfresco 通信,您需要做的就是编写一个驻留在后端的代理。

代理可以使用可以访问内容的预配置“服务帐户”与 Alfresco 建立 session 。这样,使用您的自定义 webapp 的人就不会使用他们自己的凭据从 Alfresco 获取对象。相反,使用服务帐户,网络应用程序将其流式传输给请求者。

例如,在我的一个项目中,我有一个 AssetService,它使用 CMIS 从给定 ID 的内容中获取 InputStream:

public InputStream download(String assetId) {
    CmisObject obj = session.getObject(assetId);
    Document doc = null;
    if (obj.getBaseTypeId().equals(BaseTypeId.CMIS_DOCUMENT)) {
        doc = (Document) obj;
    }
    return doc.getContentStream().getStream();
}

然后,我的 Controller 只要求 Assets 服务获取一些关于它的信息,以便轻松设置一些有用的 header ,然后它从 Assets 服务获取输入流并返回:

@RequestMapping(value = "/api/asset/{assetId:.+}/download/{name}", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> downloadAsset(
        @PathVariable("assetId") String assetId,
        @PathVariable("name") String name) {

    // get the asset so we can get some info about it
    Asset asset = assetService.getAsset(assetId);

    // set the http headers (mimetype and length at a minimum)
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.parseMediaType(asset.getMimetype()));
    httpHeaders.setContentLength(asset.getLength());

    // get the content stream
    InputStream inputStream = assetService.download(assetId);
    InputStreamResource inputStreamResource = new InputStreamResource(inputStream);

    return new ResponseEntity<InputStreamResource>(inputStreamResource, httpHeaders, HttpStatus.OK);
}

此示例在 Spring Boot 应用程序中使用了 Spring MVC,但如果需要,您当然可以使用普通的旧 servlet 执行类似的操作。

关于javascript - 显示未经验证的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44284007/

相关文章:

java - 无法使用 cmis 中的版本更新文档

postgresql - 安装 amp 文件后 Alfresco 社区损坏

javascript - 将数据从可编辑表单保存到数据库

javascript - 在 Vuejs 和 Laravel 中上传文件以及动态输入字段

javascript - 导入和导出 JS 库

java - 当应用服务器需要重启时,针对哪个文件类型改变?

java - 无法在项目 mongo-demo 上执行目标 io.thorntail :thorntail-maven-plugin:2. 2.0.Final:package (default)

javascript - Sequelize - 从具有 hasMany 关系的现有实例创建新的关系记录

java - 如何在条形图 javafx 顶部显示条形图值

java - 禁用用户主文件夹创建