我当前正在使用我的应用程序实现WOPI。我们的域已被Microsoft列入白名单。在实施过程中,我目前面临以下两个问题:
更多详细信息:
我当前的网址是https://onenote.officeapps-df.live.com/hosting/WopiTestFrame.aspx?ui=en-US&rs=en-US&dchat=1&hid=26D7CA2A10F60A68720106BF599F84B9&&WOPISrc=https://domain/wopiEditor/files/73346e47-697b-11e6-a8bc-c26cd8f74b91/courses/independentConcepts/concept_adminGlo_5/assets/Setting静态ip.docx&access_token = DEADBEEFDEADBEEFDEADBEEF&access_token_ttl = 1532765580679的网址
我的Java代码如下:
public void getFile(HttpServletRequest request, HttpServletResponse response, String name) {
Println.getInstance().log(request.getSession().getId() + "re" + request.getRequestURI());
InputStream fis = null;
OutputStream toClient = null;
try {
String path = getFilePath(request) + name;
File file = new File(path);
String filename = file.getName();
// XWPFDocument xDoc = new XWPFDocument(OPCPackage.open(fis));
fis = new BufferedInputStream(new FileInputStream(path));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
response.reset();
response.addHeader("Content-Disposition",
"attachment;filename=" + new String(filename.getBytes("utf-8"), "ISO-8859-1"));
response.addHeader("Content-Length", "" + file.length());
response.addHeader("Content-Type", "" + "application/octet-stream");
//Println.getInstance().log(file.length() + "l" + file);
toClient = new BufferedOutputStream(response.getOutputStream());
response.setContentType("application/octet-stream");
toClient.write(buffer);
toClient.flush();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
try {
fis.close();
toClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
您看到的错误是在CheckFileInfo请求上,该请求应该以JSON的形式返回。您提供的Java代码段是用于getFile请求的,该请求是从Office Online服务器进行的单独调用。您应该查看https://wopi.readthedocs.io/projects/wopirest/en/latest/,了解如何编写实现。
答案 1 :(得分:0)
一个想法是,也许您需要更具体地设置Content-Type标头,而不是要发送的应用程序/八位字节流?
您还应该返回很多其他标头值,其中一些也可能很重要:
https://wopi.readthedocs.io/projects/wopirest/en/latest/common_headers.html#common-headers