Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit a559328

Browse files
Edward Burnsyaminikb
authored andcommitted
Fixes #22079 (#22081)
modified: appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/WebTest.java - Change AAsyncDispatchToC case to correctly match specified behavior. - Add BIncludeDispatchServletNamedDispatcher to combine include, async, and named dispatcher cases. - Add these tests to assertions. modified: appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/descriptor/web.xml - Add BIncludeDispatchServletNamedDispatcher new file: appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/servlet/BIncludeDispatchServletNamedDispatcher.java - combines include, async, and named dispatcher cases. modified: appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/servlet/DispatchServlet.java - Dispatch async to ServletC rather than TestServlet. - Added logging. deleted: appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/servlet/TestServlet.java - No need for this. modified: appserver/web/web-core/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java - The actual bug fix! If DispatcherType is ASYNC, overwrite the mapping reference with the one from the original request.
1 parent 1365c33 commit a559328

File tree

6 files changed

+157
-94
lines changed

6 files changed

+157
-94
lines changed

appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/WebTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ public static void main(String[] args) {
8787
extensionMatch &&
8888
pathMatch)? stat.PASS : stat.FAIL));
8989

90-
boolean asyncMatch = webTest.run("GET", 200, false, "/AAsyncDispatchToC", ".*ServletC.MappingImpl\\{matchValue=ServletC.*pattern=/ServletC.*servletName=ServletC,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING: null.*INCLUDE_MAPPING: null.*ASYNC_MAPPING:.*MappingImpl\\{matchValue=AAsyncDispatchToC.*pattern=/AAsyncDispatchToC.*servletName=AAsyncDispatchToC.*mappingMatch=EXACT}.*");
90+
boolean asyncMatch1 = webTest.run("GET", 200, false, "/AAsyncDispatchToC", ".*ServletC.MappingImpl\\{matchValue=AAsyncDispatchToC.*pattern=/AAsyncDispatchToC.*servletName=AAsyncDispatchToC,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING: null.*INCLUDE_MAPPING: null.*ASYNC_MAPPING:.*MappingImpl\\{matchValue=AAsyncDispatchToC.*pattern=/AAsyncDispatchToC.*servletName=AAsyncDispatchToC.*mappingMatch=EXACT}.*");
91+
92+
boolean asyncMatch2 = webTest.run("GET", 200, false, "/BIncludeDispatchServletNamedDispatcher", ".*In.ServletC.MappingImpl\\{matchValue=BIncludeDispatchServletNamedDispatcher,.pattern=/BIncludeDispatchServletNamedDispatcher,.servletName=BIncludeDispatchServletNamedDispatcher,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.null.*ASYNC_MAPPING:.MappingImpl\\{matchValue=BIncludeDispatchServletNamedDispatcher,.pattern=/BIncludeDispatchServletNamedDispatcher,.servletName=BIncludeDispatchServletNamedDispatcher,.mappingMatch=EXACT\\}.*");
9193

9294
stat.addStatus(TEST_NAME + "-async",
93-
asyncMatch ? stat.PASS : stat.FAIL);
95+
asyncMatch1 &&
96+
asyncMatch2 ? stat.PASS : stat.FAIL);
9497

9598
boolean forwardMatch1 = webTest.run("GET", 200, false, "/AForwardToB", ".*ServletC.MappingImpl\\{matchValue=ServletC,.*pattern=/ServletC,.*servletName=ServletC,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING:.MappingImpl\\{matchValue=AForwardToB,.pattern=/AForwardToB,.servletName=AForwardToB,.mappingMatch=EXACT\\}.*INCLUDE_MAPPING:.null.*ASYNC_MAPPING:.null.*");
9699
boolean forwardMatch2 = webTest.run("GET", 200, false, "/BForwardToC", ".*ServletC.MappingImpl\\{matchValue=ServletC,.*pattern=/ServletC,.*servletName=ServletC,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING:.MappingImpl\\{matchValue=BForwardToC,.pattern=/BForwardToC,.servletName=BForwardToC,.mappingMatch=EXACT\\}.*INCLUDE_MAPPING:.null.*ASYNC_MAPPING:.null.*");

appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/descriptor/web.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,15 @@
9191
<servlet-name>AAsyncDispatchToC</servlet-name>
9292
<url-pattern>/AAsyncDispatchToC</url-pattern>
9393
</servlet-mapping>
94-
94+
<servlet>
95+
<servlet-name>BIncludeDispatchServletNamedDispatcher</servlet-name>
96+
<servlet-class>BIncludeDispatchServletNamedDispatcher</servlet-class>
97+
<async-supported>true</async-supported>
98+
</servlet>
99+
<servlet-mapping>
100+
<servlet-name>BIncludeDispatchServletNamedDispatcher</servlet-name>
101+
<url-pattern>/BIncludeDispatchServletNamedDispatcher</url-pattern>
102+
</servlet-mapping>
95103
<!-- getNamedDispatcher cases -->
96104
<servlet>
97105
<servlet-name>BForwardToCNamedDispatcher</servlet-name>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* https://oss.oracle.com/licenses/CDDL+GPL-1.1
12+
* or LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
41+
import java.io.IOException;
42+
import java.io.PrintWriter;
43+
import javax.servlet.AsyncContext;
44+
import javax.servlet.RequestDispatcher;
45+
import javax.servlet.ServletException;
46+
import javax.servlet.http.HttpServlet;
47+
import javax.servlet.http.HttpServletRequest;
48+
import javax.servlet.http.HttpServletResponse;
49+
import javax.servlet.http.HttpServletMapping;
50+
51+
public class BIncludeDispatchServletNamedDispatcher extends HttpServlet {
52+
53+
/**
54+
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
55+
* methods.
56+
*
57+
* @param request servlet request
58+
* @param response servlet response
59+
* @throws ServletException if a servlet-specific error occurs
60+
* @throws IOException if an I/O error occurs
61+
*/
62+
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
63+
throws ServletException, IOException {
64+
request.getServletContext().log(this.getClass().getSimpleName() + " "
65+
+ request.getHttpServletMapping());
66+
HttpServletMapping forwardMapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.FORWARD_MAPPING);
67+
request.getServletContext().log(this.getClass().getSimpleName() + " FORWARD_MAPPING attribute: "
68+
+ forwardMapping);
69+
HttpServletMapping includeMapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.INCLUDE_MAPPING);
70+
request.getServletContext().log(this.getClass().getSimpleName() + " INCLUDE_MAPPING attribute: "
71+
+ includeMapping);
72+
HttpServletMapping asyncMapping = (HttpServletMapping) request.getAttribute(AsyncContext.ASYNC_MAPPING);
73+
request.getServletContext().log(this.getClass().getSimpleName() + " ASYNC_MAPPING attribute: "
74+
+ asyncMapping);
75+
RequestDispatcher rd = request.getServletContext().getNamedDispatcher("fa5raP");
76+
rd.include(request, response);
77+
}
78+
79+
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
80+
/**
81+
* Handles the HTTP <code>GET</code> method.
82+
*
83+
* @param request servlet request
84+
* @param response servlet response
85+
* @throws ServletException if a servlet-specific error occurs
86+
* @throws IOException if an I/O error occurs
87+
*/
88+
@Override
89+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
90+
throws ServletException, IOException {
91+
processRequest(request, response);
92+
}
93+
94+
/**
95+
* Handles the HTTP <code>POST</code> method.
96+
*
97+
* @param request servlet request
98+
* @param response servlet response
99+
* @throws ServletException if a servlet-specific error occurs
100+
* @throws IOException if an I/O error occurs
101+
*/
102+
@Override
103+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
104+
throws ServletException, IOException {
105+
processRequest(request, response);
106+
}
107+
108+
/**
109+
* Returns a short description of the servlet.
110+
*
111+
* @return a String containing servlet description
112+
*/
113+
@Override
114+
public String getServletInfo() {
115+
return "Short description";
116+
}// </editor-fold>
117+
118+
}

appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/servlet/DispatchServlet.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,31 @@
4040

4141
import java.io.IOException;
4242
import javax.servlet.AsyncContext;
43+
import javax.servlet.RequestDispatcher;
4344
import javax.servlet.annotation.WebServlet;
4445
import javax.servlet.http.HttpServlet;
46+
import javax.servlet.http.HttpServletMapping;
4547
import javax.servlet.http.HttpServletRequest;
4648
import javax.servlet.http.HttpServletResponse;
4749

48-
@WebServlet(asyncSupported = true, value = "/DispatchServlet", loadOnStartup = 1)
50+
@WebServlet(asyncSupported = true, name="fa5raP", value = "/DispatchServlet", loadOnStartup = 1)
4951
public class DispatchServlet extends HttpServlet {
5052

51-
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException{
52-
AsyncContext asyncContext = req.startAsync();
53+
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
54+
request.getServletContext().log(this.getClass().getSimpleName() + " "
55+
+ request.getHttpServletMapping());
56+
HttpServletMapping forwardMapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.FORWARD_MAPPING);
57+
request.getServletContext().log(this.getClass().getSimpleName() + " FORWARD_MAPPING attribute: "
58+
+ forwardMapping);
59+
HttpServletMapping includeMapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.INCLUDE_MAPPING);
60+
request.getServletContext().log(this.getClass().getSimpleName() + " INCLUDE_MAPPING attribute: "
61+
+ includeMapping);
62+
HttpServletMapping asyncMapping = (HttpServletMapping) request.getAttribute(AsyncContext.ASYNC_MAPPING);
63+
request.getServletContext().log(this.getClass().getSimpleName() + " ASYNC_MAPPING attribute: "
64+
+ asyncMapping);
65+
66+
AsyncContext asyncContext = request.startAsync();
5367
asyncContext.setTimeout(0);
54-
asyncContext.dispatch("/TestServlet");
68+
asyncContext.dispatch("/ServletC");
5569
}
5670
}

appserver/tests/appserv-tests/devtests/web/servlet-4.0/mappingDiscovery/servlet/TestServlet.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

appserver/web/web-core/src/main/java/org/apache/catalina/core/ApplicationDispatcher.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,13 @@ private ServletRequest wrapRequest(State state) {
10751075
this.mappingForDispatch = computeNamedDispatchHttpServletMapping(context, hcurrent);
10761076
}
10771077
//END OF github/javaee/glassfish/issues/21846
1078-
1078+
1079+
//START OF github/javaee/glassfish/issues/22079
1080+
if (DispatcherType.ASYNC.equals(state.dispatcherType)) {
1081+
this.mappingForDispatch = hcurrent.getHttpServletMapping();
1082+
}
1083+
//END OF github/javaee/glassfish/issues/22079
1084+
10791085
wrapper = new ApplicationHttpRequest
10801086
(hcurrent, context, crossContext, mappingForDispatch, state.dispatcherType);
10811087
} else {

0 commit comments

Comments
 (0)