我目前正在开发一个 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/