Office加载项开发-格式错误的GET URL(_host_Info = ...) [英] Office Add-In Development - Malformed GET URL (_host_Info=...)

查看:118
本文介绍了Office加载项开发-格式错误的GET URL(_host_Info = ...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Microsoft提供的JavaScript界面​​开发MS Word Office加载项.我使用Django后端进行了测试实现,一切正常.

I am currently developing a MS Word Office Addin using the JavaScript interface provided by Microsoft. I made a test implementation using a Django backend, where everything worked fine.

但是对于最终产品,我必须将功能与以多种配置运行的现有Java Backend集成在一起,而这超出了我的控制范围.由UI的Vaadin组成,主要是Tomcat(但并非总是如此)作为Servlet容器.

However for the final product I have to integrate functionality with an existing Java Backend that runs in multiple configurations, which are out of my control. Consisting of Vaadin for the UI and mostly Tomcat (but not always) as a Servlet Container.

我遇到了一个问题,即在Word中运行的IFrame会将不需要的且格式错误的_host_info附加到请求URL,该URL包含未编码的管道字符. 例如:Tomcat日志:

I've run into the problem that the IFrame that runs inside Word, appends an unwanted and malformed _host_info to the request URL, that contains un-urlencoded pipe characters. e.g: Tomcat Log:

"GET /myapp/?_host_Info=Word|Win32|16.01|en-US HTTP/1.1" 200 2101

此格式错误的URL会产生以下异常:

This malformed URL produces the following exception:

java.lang.RuntimeException: Invalid location URI received from client.
... full stack trace at bottom of the post...
Caused by: java.net.URISyntaxException: Illegal character in query at index          45: https://localhost:8443/myapp/?_host_Info=Word|Win32|16.01|en-US

据我所知,我无法控制是否将此参数附加到URL,因为在Addin的清单文件中,我仅指定源URL,如下所示,并且信息会自动添加.

As far as I know, I have no control, on whether or not to append this Parameter to the URL, since in the Manifest File of the Addin I only specify the source URL like below, and the info gets added automatically.

<SourceLocation DefaultValue="https://localhost:8443/myapp/ " />

检查文档我没有在那里找到这种行为,所以我可能会缺少一些东西. 博客文章,但似乎它不应该是URL的一部分.

Checking the Documentation I didn't find this behaviour in there, so i might be missing something. Querying the host info is mentioned in this blog post, but it seems it should not be part of the URL.

  • 有没有一种方法可以阻止Office加载项的追加: ?_ host_Info = Word | Win32 | 16.01 | en-US HTTP/1.1 到请求?

  • Is there a way I can stop the Office Add-In from appending: ?_host_Info=Word|Win32|16.01|en-US HTTP/1.1 to the request?

如果没有,是否存在使用Tomcat过滤/忽略URL的那部分的正确方法?由于整个应用程序均已在我的Apache Webserver&中正常运行Django Backend,也可以接收URL,但是它可以工作.

If not, is there a correct way to filte/ignore that part of the URL with Tomcat? Since the whole app has been running correctly with my Apache Webserver & Django Backend, where the URL was received too, but it worked.

对于第二个问题,我已经尝试实现一个Servlet过滤器,该过滤器应删除有问题的参数.但是,由于它依赖于相同的Java库来解析URL来查看它,因此会抛出相同的异常.

As for question two, I've already tried to implement a Servlet filter that should remove the parameter in question. But since it relies on the same Java library to parse the URL to look at it, the same exception is thrown.

> May 23, 2016 11:04:51 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [MyUIServlet] in context with path [/word-to-moxis] threw exception [com.vaadin.server.ServiceException: java.lang.RuntimeException: Invalid location URI received from client] with root cause
java.net.URISyntaxException: Illegal character in query at index h(invalidated link because of 10 reputation / two links allowed policy)ttps://localhost:8443/myapp/?_host_Info=Word|Win32|16.01|en-US
    at java.net.URI$Parser.fail(URI.java:2848)
    at java.net.URI$Parser.checkChars(URI.java:3021)
    at java.net.URI$Parser.parseHierarchical(URI.java:3111)
    at java.net.URI$Parser.parse(URI.java:3053)
    at java.net.URI.<init>(URI.java:588)
    at com.vaadin.server.Page.init(Page.java:651)
    at com.vaadin.ui.UI.doInit(UI.java:679)
    at com.vaadin.server.communication.`UIInitHandler`.getBrowserDetailsUI(UIInitHandler.java:214)

更新:

以下快速& Dirty Hack充当了该问题的解决方法.对于他们为什么选择以这种方式对信息进行编码仍然感到困惑:

The following Quick & Dirty Hack acts as a workaround of the problem. Still baffled as to why they chose to encode the information that way:

public class AddinServletRequestWrapper extends HttpServletRequestWrapper {

    Map<String, String[]> parameterMap;

    public AddinServletRequestWrapper(HttpServletRequest originalRequest) {
        super(originalRequest);
        parameterMap = new HashMap<String, String[]>(originalRequest.getParameterMap());
        parameterMap.remove("_host_Info");
    }

    @Override
    public String getParameter(String name) {
        // TODO: Improve
        String[] value = parameterMap.get(name);
        if (value == null || value.length == 0)
            return null;
        if(name == "v-loc"){
            return value[0].replace('|', '_');
        }

        return value[0];
    }
}

更新2月2日:

随着Tomcat的更新,上面的解决方法已不再足够.如评论中所述,版本 7.0.73 8.0.39 8.5.7 具有更严格的URL策略.因此,如果没有其他工具,就无法使用tomcat版本来托管Office加载项.我真的希望这种情况能尽快改变,因为这么小的字符串(可能没用的字符串)可以在部署中使用此类问题.

With more recent Tomcat updates the workaround above no longer suffices. As noted in the comments, the versions 7.0.73, 8.0.39, 8.5.7 have a stricter URL policy. Therefore there is no solution to use the versions of tomcat for hosting office add-ins without additional tooling. I really hope this situation changes soon because such a small, probably useless string can use such problems with deployments.

推荐答案

更新: 该API现在可供使用:

UPDATE: The API is now available for use:

console.log(Office.context.host); //示例:Excel

console.log(Office.context.host); //example: Excel

console.log(Office.context.platform); //示例:PC,MAC,IOS,空(用于独立网站)

console.log(Office.context.platform); //example: PC, MAC, IOS, null (for stand alone website)

主机的可能值为: 单词 电子表格 微软幻灯片软件 外表 OneNote 项目 访问

Possible values for host are: Word Excel PowerPoint Outlook OneNote Project Access

平台的可能值为: 个人电脑 在线办公 苹果电脑 的iOS 安卓 通用

Possible values for platform are: PC OfficeOnline Mac iOS Android Universal

鉴于单页应用程序中提到的问题,我们最近从URL中删除了查询参数. _host_info_不再附加到在浏览器(Office Online)中打开的加载项.

We recently removed the query parameters from the URL in light of the issues noted in single page applications. the _host_info_ is no longer appended for add-ins opened in the browser (Office Online).

@Matthias:对于此问题,添加office-js标记会更准确.给定标签的大小限制,我无法追加.

@Matthias: For this issue, adding office-js tag would be more accurate. I couldn't append given the size limit for tags.

这篇关于Office加载项开发-格式错误的GET URL(_host_Info = ...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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