-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply a workaround for servlet path and path info (#369)
Apply a workaround for servlet path and path info If a servlet is mapped to the root then forwarding is used. In this case the servlet path becomes the path info and path info is null. To be able to make Vaadin servlet logic work in a proper way the HttpServletRequest instance is replaced with a wrapper which returns expected values for the servlet path and path info. Fixes #331
- Loading branch information
Denis
authored
Nov 2, 2018
1 parent
59c1ee8
commit 75c67ae
Showing
7 changed files
with
106 additions
and
107 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
...-spring/src/main/java/com/vaadin/flow/spring/DispatcherServletRegistrationBeanConfig.java
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
vaadin-spring/src/main/java/com/vaadin/flow/spring/ForwardingRequestWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2000-2018 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.spring; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletRequestWrapper; | ||
|
||
import org.springframework.web.util.UrlPathHelper; | ||
|
||
import com.vaadin.flow.server.VaadinServlet; | ||
|
||
/** | ||
* Creates an {@link HttpServletRequestWrapper} instance which returns | ||
* appropriate {@code servletPath} and {@code pathInfo} (which are expected by | ||
* {@link VaadinServlet}) in case forwarding is enforced. | ||
* | ||
* @see <a href="https://jira.spring.io/browse/SPR-17457">Spring issue</a> | ||
* | ||
* @author Vaadin Ltd | ||
* | ||
*/ | ||
public class ForwardingRequestWrapper extends HttpServletRequestWrapper { | ||
|
||
private UrlPathHelper urlPathHelper = new UrlPathHelper(); | ||
|
||
public ForwardingRequestWrapper(HttpServletRequest request) { | ||
super(request); | ||
} | ||
|
||
@Override | ||
public String getServletPath() { | ||
String pathInfo = super.getPathInfo(); | ||
if (pathInfo == null) { | ||
// the path where a ServletForwardingController is registered is not | ||
// a real servlet path | ||
return ""; | ||
} else { | ||
return super.getServletPath(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getPathInfo() { | ||
String pathInfo = super.getPathInfo(); | ||
if (pathInfo == null) { | ||
// this uses getServletPath() and should work both with and without | ||
// clearServletPath | ||
pathInfo = urlPathHelper.getPathWithinServletMapping(this); | ||
} | ||
return pathInfo; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters