Skip to content

Commit 6eee256

Browse files
committed
Demonstrate include-code usage
Closes gh-17161
1 parent 0fecaf4 commit 6eee256

File tree

3 files changed

+80
-24
lines changed

3 files changed

+80
-24
lines changed

docs/modules/ROOT/pages/servlet/architecture.adoc

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,7 @@ In this case, the `Filter` typically writes the `HttpServletResponse`.
2929
The power of the `Filter` comes from the `FilterChain` that is passed into it.
3030

3131
.`FilterChain` Usage Example
32-
[tabs]
33-
======
34-
Java::
35-
+
36-
[source,java,role="primary"]
37-
----
38-
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
39-
// do something before the rest of the application
40-
chain.doFilter(request, response); // invoke the rest of the application
41-
// do something after the rest of the application
42-
}
43-
----
44-
45-
Kotlin::
46-
+
47-
[source,kotlin,role="secondary"]
48-
----
49-
fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
50-
// do something before the rest of the application
51-
chain.doFilter(request, response) // invoke the rest of the application
52-
// do something after the rest of the application
53-
}
54-
----
55-
======
32+
include-code::./FilterChainUsage[tag=dofilter,indent=0]
5633

5734
Since a `Filter` impacts only downstream `Filter` instances and the `Servlet`, the order in which each `Filter` is invoked is extremely important.
5835

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.docs.servlet.servletfiltersreview;
18+
19+
import java.io.IOException;
20+
21+
import jakarta.servlet.Filter;
22+
import jakarta.servlet.FilterChain;
23+
import jakarta.servlet.ServletException;
24+
import jakarta.servlet.ServletRequest;
25+
import jakarta.servlet.ServletResponse;
26+
27+
/**
28+
* Demos FilterChain Usage.
29+
* @author Rob Winch
30+
*/
31+
public class FilterChainUsage implements Filter {
32+
33+
// tag::dofilter[]
34+
@Override
35+
public void doFilter(ServletRequest request, ServletResponse response,
36+
FilterChain chain) throws IOException, ServletException {
37+
// do something before the rest of the application
38+
chain.doFilter(request, response); // invoke the rest of the application
39+
// do something after the rest of the application
40+
}
41+
// end::dofilter[]
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2002-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.kt.docs.servlet.servletfiltersreview
18+
19+
import jakarta.servlet.*
20+
import java.io.IOException
21+
22+
/**
23+
* Demos FilterChain Usage.
24+
* @author Rob Winch
25+
*/
26+
class FilterChainUsage : Filter {
27+
28+
// tag::dofilter[]
29+
@Throws(IOException::class, ServletException::class)
30+
override fun doFilter(request: ServletRequest?, response: ServletResponse?, chain: FilterChain) {
31+
// do something before the rest of the application
32+
chain.doFilter(request, response) // invoke the rest of the application
33+
// do something after the rest of the application
34+
}
35+
// end::dofilter[]
36+
37+
}

0 commit comments

Comments
 (0)