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

Commit 264335d

Browse files
Edward Burnsarindam-bandyopadhyay
authored andcommitted
Integrate fix for getServletName return null, #21846 (#22007)
1 parent 6cad931 commit 264335d

File tree

6 files changed

+307
-12
lines changed

6 files changed

+307
-12
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,25 +87,32 @@ 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=.*,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING: null.*INCLUDE_MAPPING: null.*ASYNC_MAPPING:.*MappingImpl\\{matchValue=AAsyncDispatchToC.*pattern=/AAsyncDispatchToC.*servletName=AAsyncDispatchToC.*mappingMatch=EXACT}.*");
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}.*");
9191

9292
stat.addStatus(TEST_NAME + "-async",
9393
asyncMatch ? stat.PASS : stat.FAIL);
9494

95-
boolean forwardMatch1 = webTest.run("GET", 200, false, "/AForwardToB", ".*ServletC.MappingImpl\\{matchValue=ServletC,.*pattern=/ServletC,.*servletName=.*,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING:.MappingImpl\\{matchValue=AForwardToB,.pattern=/AForwardToB,.servletName=AForwardToB,.mappingMatch=EXACT\\}.*INCLUDE_MAPPING:.null.*ASYNC_MAPPING:.null.*");
96-
boolean forwardMatch2 = webTest.run("GET", 200, false, "/BForwardToC", ".*ServletC.MappingImpl\\{matchValue=ServletC,.*pattern=/ServletC,.*servletName=.*,.*mappingMatch=EXACT\\}.*FORWARD_MAPPING:.MappingImpl\\{matchValue=BForwardToC,.pattern=/BForwardToC,.servletName=BForwardToC,.mappingMatch=EXACT\\}.*INCLUDE_MAPPING:.null.*ASYNC_MAPPING:.null.*");
95+
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.*");
96+
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.*");
9797

9898
stat.addStatus(TEST_NAME + "-forward", ((forwardMatch1 &&
9999
forwardMatch2)? stat.PASS : stat.FAIL));
100100

101-
boolean includeMatch1 = webTest.run("GET", 200, false, "/AIncludesB", ".*AIncludesB.MappingImpl\\{matchValue=AIncludesB,.pattern=/AIncludesB,.servletName=AIncludesB,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.null.*In.BIncludesC.MappingImpl\\{matchValue=AIncludesB,.pattern=/AIncludesB,.servletName=AIncludesB,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.MappingImpl\\{matchValue=BIncludesC,.pattern=/BIncludesC,.servletName=.*,.mappingMatch=EXACT\\}.*In.ServletC.MappingImpl\\{matchValue=AIncludesB,.pattern=/AIncludesB,.servletName=AIncludesB,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.MappingImpl\\{matchValue=ServletC,.pattern=/ServletC,.servletName=.*,.mappingMatch=EXACT\\}.*ASYNC_MAPPING:.null.*");
102-
boolean includeMatch2 = webTest.run("GET", 200, false, "/BIncludesC", ".*In.BIncludesC.MappingImpl\\{matchValue=BIncludesC,.pattern=/BIncludesC,.servletName=BIncludesC,.mappingMatch=EXACT\\}.*.FORWARD_MAPPING:.null.*.INCLUDE_MAPPING:.null.*In.ServletC.MappingImpl\\{matchValue=BIncludesC,.pattern=/BIncludesC,.servletName=BIncludesC,.mappingMatch=EXACT\\}.*.FORWARD_MAPPING:.null.*.INCLUDE_MAPPING:.MappingImpl\\{matchValue=ServletC,.pattern=/ServletC,.servletName=.*,.mappingMatch=EXACT\\}.*.ASYNC_MAPPING:.null.*");
101+
boolean includeMatch1 = webTest.run("GET", 200, false, "/AIncludesB", ".*AIncludesB.MappingImpl\\{matchValue=AIncludesB,.pattern=/AIncludesB,.servletName=AIncludesB,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.null.*In.BIncludesC.MappingImpl\\{matchValue=AIncludesB,.pattern=/AIncludesB,.servletName=AIncludesB,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.MappingImpl\\{matchValue=BIncludesC,.pattern=/BIncludesC,.servletName=BIncludesC,.mappingMatch=EXACT\\}.*In.ServletC.MappingImpl\\{matchValue=AIncludesB,.pattern=/AIncludesB,.servletName=AIncludesB,.mappingMatch=EXACT\\}.*FORWARD_MAPPING:.null.*INCLUDE_MAPPING:.MappingImpl\\{matchValue=ServletC,.pattern=/ServletC,.servletName=ServletC,.mappingMatch=EXACT\\}.*ASYNC_MAPPING:.null.*");
102+
boolean includeMatch2 = webTest.run("GET", 200, false, "/BIncludesC", ".*In.BIncludesC.MappingImpl\\{matchValue=BIncludesC,.pattern=/BIncludesC,.servletName=BIncludesC,.mappingMatch=EXACT\\}.*.FORWARD_MAPPING:.null.*.INCLUDE_MAPPING:.null.*In.ServletC.MappingImpl\\{matchValue=BIncludesC,.pattern=/BIncludesC,.servletName=BIncludesC,.mappingMatch=EXACT\\}.*.FORWARD_MAPPING:.null.*.INCLUDE_MAPPING:.MappingImpl\\{matchValue=ServletC,.pattern=/ServletC,.servletName=ServletC,.mappingMatch=EXACT\\}.*.ASYNC_MAPPING:.null.*");
103103
stat.addStatus(TEST_NAME + "-include", ((includeMatch1 &&
104104
includeMatch2)? stat.PASS : stat.FAIL));
105105

106106
boolean boundsMatch1 = webTest.run("GET", 200, false, "/a/foo", ".*");
107107
boolean boundsMatch2 = webTest.run("GET", 200, false, "/f", ".*");
108108
stat.addStatus(TEST_NAME + "-bounds", ((boundsMatch1 && boundsMatch2)? stat.PASS : stat.FAIL));
109+
110+
111+
boolean namedDispatchMatch1 = webTest.run("GET", 200, false, "/BForwardToCNamedDispatcher", "..*In.ServletC.MappingImpl\\{matchValue=BForwardToCNamedDispatcher,.pattern=/BForwardToCNamedDispatcher,.servletName=BForwardToCNamedDispatcher,.mappingMatch=EXACT\\}</p><p>.FORWARD_MAPPING:.null</p><p>.INCLUDE_MAPPING:.null</p><p>.ASYNC_MAPPING:.null.*");
112+
boolean namedDispatchMatch2 = webTest.run("GET", 200, false, "/BIncludeCNamedDispatcher", ".*In.ServletC.MappingImpl\\{matchValue=BIncludeCNamedDispatcher,.pattern=/BIncludeCNamedDispatcher,.servletName=BIncludeCNamedDispatcher,.mappingMatch=EXACT\\}</p><p>.FORWARD_MAPPING:.null</p><p>.INCLUDE_MAPPING:.null</p><p>.ASYNC_MAPPING:.null.*");
113+
114+
stat.addStatus(TEST_NAME + "-namedDispatch", ((namedDispatchMatch1 && namedDispatchMatch2)? stat.PASS : stat.FAIL));
115+
109116

110117
} catch( Exception ex) {
111118
ex.printStackTrace();

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,24 @@
9292
<url-pattern>/AAsyncDispatchToC</url-pattern>
9393
</servlet-mapping>
9494

95+
<!-- getNamedDispatcher cases -->
96+
<servlet>
97+
<servlet-name>BForwardToCNamedDispatcher</servlet-name>
98+
<servlet-class>BForwardToCNamedDispatcher</servlet-class>
99+
</servlet>
100+
<servlet-mapping>
101+
<servlet-name>BForwardToCNamedDispatcher</servlet-name>
102+
<url-pattern>/BForwardToCNamedDispatcher</url-pattern>
103+
</servlet-mapping>
104+
105+
<servlet>
106+
<servlet-name>BIncludeCNamedDispatcher</servlet-name>
107+
<servlet-class>BIncludeCNamedDispatcher</servlet-class>
108+
</servlet>
109+
<servlet-mapping>
110+
<servlet-name>BIncludeCNamedDispatcher</servlet-name>
111+
<url-pattern>/BIncludeCNamedDispatcher</url-pattern>
112+
</servlet-mapping>
95113

96114
<!-- The end of the line -->
97115

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 BForwardToCNamedDispatcher 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("ServletC");
76+
rd.forward(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+
}
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 BIncludeCNamedDispatcher 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("ServletC");
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+
}

0 commit comments

Comments
 (0)