1

我目前正在用我的应用程序实现 WOPI。我们的域已被Microsoft列入白名单。在实施时,我目前面临两个问题,如下所述:

  1. 尝试将内容验证为 JSON 时引发异常:“解析值时遇到意外字符。” 我正在发送我的响应“Value=application/octet-stream”,但我不明白为什么服务器试图将流解析为 JSON。
  2. 在来自“iframe”的每个新请求之后,都会在 JAVA 中启动一个新会话。

以下是更多详细信息:

我当前的网址是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/静态ip.docx&access_token=DEADBEEFDEADBEEFDEADBEEF&access_token_ttl=1532765580679的设置url

我的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();
            }
        }
    }

附上测试帧图像在此处输入图像描述

在此处输入图像描述

4

2 回答 2

1

您看到的错误出现在 CheckFileInfo 请求上,该请求应该以 JSON 形式返回。您提供的 Java 代码段用于 getFile 请求,该请求是从 Office Online 服务器发出的单独调用。您应该查看 https://wopi.readthedocs.io/projects/wopirest/en/latest/以了解如何编写您的实现。

于 2018-07-27T12:09:52.700 回答
0

一种想法是您可能需要更具体地设置 Content-Type 标头而不是您发送的应用程序/八位字节流?

此外,您还应该返回很多其他标头值,其中一些可能也很重要:

https://wopi.readthedocs.io/projects/wopirest/en/latest/common_headers.html#common-headers

于 2018-07-27T17:51:59.360 回答