-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Documents proper order for Servlet Filtters.
Fixes gh-3244
- Loading branch information
1 parent
9ea11b3
commit 430607c
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
...OT/pages/spring-cloud-gateway-server-mvc/working-with-servlets-and-filters.adoc
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,30 @@ | ||
[[working-with-servlets-and-filters]] | ||
= Working with Servlets and Servlet Filters | ||
|
||
Spring Cloud Gateway Server MVC is built for Servlet-stack web applications built on the Servlet API and deployed to Servlet containers. If your applications uses Servlets or Servlet Filters you may need to take care in their ordering. | ||
|
||
Because of the way Servlet Containers handle request parameters, when a Spring WebMVC application receives a content type of `application/x-www-form-urlencoded`, Servlet containers combine those with query parameters into "request" parameters. A special `FormFilter` bean is included in Spring Cloud Gateway Server MVC to rebuild the form body for downstream applications. Any Servlet Filter that reads request parameters before the filter chain is run will need to be ordered *before* `FormFilter`. See the example below. | ||
|
||
.MyFilter.java | ||
[source,java] | ||
---- | ||
import jakarta.servlet.Filter; | ||
import org.springframework.cloud.gateway.server.mvc.filter.FormFilter; | ||
import org.springframework.core.Ordered; | ||
class MyFilter implements Filter, Ordered { | ||
@Override | ||
public int getOrder() { | ||
return FormFilter.FORM_FILTER_ORDER - 1; | ||
} | ||
@Override | ||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) | ||
throws IOException, ServletException { | ||
// ... | ||
filterChain.doFilter(request, response); | ||
// ... | ||
} | ||
} | ||
---- |
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