Java – Office add in development – malformed get URL (_host_info =…)

I am currently developing MS Word office addin using the JavaScript interface provided by Microsoft I used Django backend to test the implementation, and everything was normal

But for the final product, I have to integrate functionality into the existing Java backend running in multiple configurations beyond my control It consists of vaadin of user interface, mainly Tomcat (but not always) as servlet container

I encountered a problem that iframe running in word will be unnecessary and malformed_ host_ Info is attached to the request URL, which contains the UN urlencoded pipeline character For example: Tomcat log:

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

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

As far as I know, I can't control whether to attach this parameter to the URL, because in the manifest file of addin, I only specify the source URL as shown below, and the information will be added automatically

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

I didn't find this behavior there, so I might miss something Querying host information is mentioned in this blog post, but it seems that it should not be part of the URL

>Is there any way to prevent office add ins from attaching:_ host_ Info = word | Win32 | 16.01 | zh CN http / 1.1 request? > If not, is there a correct way to use Tomcat to filter / ignore that part of the URL? Since the whole application has used my Apache webserver & Django backend, I also received the URL, but it is valid

As for question 2, I have tried to implement a servlet filter that should delete related parameters But because it relies on the same Java library to parse the URL to see it, it throws the same exception

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

to update:

The following quick & dirty hack can solve the problem Still confused is why they chose to encode information in this 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:

With the recent Tomcat update, the above solution is no longer sufficient As mentioned in the comments, version 7.0 73,8.0. 39,8.5. 7 has a more stringent URL policy Therefore, no solution can use the Tomcat version to host office add ins without additional tools I really hope this situation will change soon, because such a small, possibly useless string can be used in deployment

Solution

to update:

Console log(Office.context.host); // Example: Excel

Console log(Office.context.platform); // Example: PC, MAC, IOS, null (for independent websites)

The possible values of the host are: Microsoft slide software appearance project access in OneNote

The possible value of the platform is: the popularity of personal computer officeonline Apple Computer IOS Android

We recently removed the query parameters from the URL according to the problems mentioned in the single page application Add ins that open in the browser (Office Online) are no longer attached_ host_ info_.

@Matthias: for this problem, adding the office JS tag will be more accurate Due to the size limit of the label, I can't append it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>