简体   繁体   English

Office加载项开发 - 格式错误的GET URL(_host_Info = ...)

[英]Office Add-In Development - Malformed GET URL (_host_Info=…)

I am currently developing a MS Word Office Addin using the JavaScript interface provided by Microsoft. 我目前正在使用Microsoft提供的JavaScript界面​​开发MS Word Office Addin。 I made a test implementation using a Django backend, where everything worked fine. 我使用Django后端进行了测试实现,其中一切正常。

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. 但是对于最终产品,我必须将功能与现有的Java Backend集成,后者运行在多个配置中,这些配置是我无法控制的。 Consisting of Vaadin for the UI and mostly Tomcat (but not always) as a Servlet Container. 由用户界面的Vaadin组成,主要是Tomcat(但并不总是)作为Servlet容器。

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. 我遇到了一个问题,即在Word中运行的IFrame会将不需要的和格式错误的_host_info附加到请求URL,其中包含un-urlencoded管道符。 eg: Tomcat Log: 例如:Tomcat Log:

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

This malformed URL produces the following exception: 此格式错误的URL会产生以下异常:

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

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. 据我所知,我无法控制是否将此参数附加到URL,因为在Addin的Manifest文件中我只指定了如下所示的源URL,并且信息会自动添加。

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

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. 博客文章中提到了查询主机信息,但它似乎不应该是URL的一部分。

  • 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? 有没有办法可以阻止Office加载项附加: ?_ host_Info = Word | Win32 | 16.01 | en-US HTTP / 1.1到请求?

  • If not, is there a correct way to filte/ignore that part of the URL with Tomcat? 如果没有,是否有正确的方法来使用Tomcat过滤/忽略该部分URL? Since the whole app has been running correctly with my Apache Webserver & Django Backend, where the URL was received too, but it worked. 由于整个应用程序已经使用我的Apache Webserver和Django Backend正确运行,其中也收到了URL,但它确实有效。

As for question two, I've already tried to implement a Servlet filter that should remove the parameter in question. 至于问题二,我已经尝试实现一个应该删除相关参数的Servlet过滤器。 But since it relies on the same Java library to parse the URL to look at it, the same exception is thrown. 但由于它依赖于相同的Java库来解析URL以查看它,因此抛出了相同的异常。

> 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)

Update: 更新:

The following Quick & Dirty Hack acts as a workaround of the problem. 以下Quick&Dirty Hack可作为问题的解决方法。 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];
    }
}

Update 2/ Feb17: 更新2 / Feb17:

With more recent Tomcat updates the workaround above no longer suffices. 随着最近的Tomcat更新,上面的解决方法不再足够。 As noted in the comments, the versions 7.0.73 , 8.0.39 , 8.5.7 have a stricter URL policy. 正如评论指出的那样,版本7.0.73,8.0.39,8.5.7有更严格的URL策略。 Therefore there is no solution to use the versions of tomcat for hosting office add-ins without additional tooling. 因此,没有解决方案可以使用tomcat版本来托管办公室加载项而无需额外的工具。 I really hope this situation changes soon because such a small, probably useless string can use such problems with deployments. 我真的希望这种情况很快就会发生变化,因为这样一个小的,可能无用的字符串可以在部署时使用这些问题。

UPDATE: The API is now available for use: 更新:API现在可供使用:

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

console.log(Office.context.platform); 的console.log(Office.context.platform); //example: PC, MAC, IOS, null (for stand alone website) //示例:PC,MAC,IOS,null(对于独立网站)

Possible values for host are: Word Excel PowerPoint Outlook OneNote Project Access 主机的可能值包括:Word Excel PowerPoint Outlook OneNote项目访问

Possible values for platform are: PC OfficeOnline Mac iOS Android Universal 平台的可能值包括:PC OfficeOnline Mac iOS Android Universal


We recently removed the query parameters from the URL in light of the issues noted in single page applications. 我们最近根据单页面应用程序中提到的问题从URL中删除了查询参数。 the _host_info_ is no longer appended for add-ins opened in the browser (Office Online). 对于在浏览器中打开的加载项(Office Online),不再附加_host_info_。

@Matthias: For this issue, adding office-js tag would be more accurate. @Matthias:对于这个问题,添加office-js标签会更准确。 I couldn't append given the size limit for tags. 鉴于标签的大小限制,我无法追加。

If you have an apache with mod_rewrite enabled in front of your tomcat, it's possible to add this dirty apache rule to infly reencode the outlook request : 如果你的tomcat前面有一个启用了mod_rewrite的apache,可以添加这个脏的apache规则来重新编码outlook请求:

 RewriteCond %{QUERY_STRING} (.*)_host_Info=(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*)\\|(.*) RewriteRule ^(.*) "$1?%1_host_Info=%2\\%7c%3\\%7c%4\\%7c%5\\%7c%6\\%7c%7" [QSD,PT] 

I hope this can help 我希望这可以提供帮助

This change of the URL also wreaks havoc in Angular if you are playing with the urlRouteProvider at all. 如果你正在使用urlRouteProvider,这个URL的更改也会在Angular中造成严重破坏。 It appears to create a digest loop because it is location changing event to fire inside Angular which exceeds the 10 loop limit of the digest. 它似乎创建了一个摘要循环,因为它是在Angular内部触发的位置更改事件,超过了摘要的10循环限制。 :( :(

We had a similar problem to this one. 我们遇到了类似的问题。

Our solution was to downgrade our tomcat versión from 8.0.39 to 8.0.30. 我们的解决方案是将我们的tomcatversión从8.0.39降级到8.0.30。

Look also this: |' 看看这个: |' in query parameters? 在查询参数?

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM