This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new bec674513c Add tests for the <c:redirect> tag plugin
bec674513c is described below
commit bec674513c2cd2bc6fcb44ed850059473aa859d9
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Sep 17 22:15:28 2026 +0100
Add tests for the <c:redirect> tag plugin
authored-by: CoPilot / GPT-5.6
---
.../tagplugins/jstl/core/AbstractTestTag.java | 8 +-
.../jasper/tagplugins/jstl/core/TestRedirect.java | 110 +++++++++++++++++++++
.../tagplugins/jstl/core/redirect-tagPlugins.xml | 23 +++++
test/webapp/WEB-INF/jstl-redirect.tld | 43 ++++++++
test/webapp/WEB-INF/tags/jstl/redirect.tag | 19 ++++
test/webapp/jstl/redirect-fragment.jsp | 24 +++++
test/webapp/jstl/redirect-nested.jsp | 24 +++++
test/webapp/jstl/redirect-tag-file.jsp | 21 ++++
test/webapp/jstl/redirect-target.jsp | 18 ++++
test/webapp/jstl/redirect.jsp | 21 ++++
10 files changed, 309 insertions(+), 2 deletions(-)
diff --git a/test/org/apache/jasper/tagplugins/jstl/core/AbstractTestTag.java
b/test/org/apache/jasper/tagplugins/jstl/core/AbstractTestTag.java
index 1599348f86..dab70d4108 100644
--- a/test/org/apache/jasper/tagplugins/jstl/core/AbstractTestTag.java
+++ b/test/org/apache/jasper/tagplugins/jstl/core/AbstractTestTag.java
@@ -47,8 +47,7 @@ public abstract class AbstractTestTag extends TomcatBaseTest {
lib.getAbsolutePath(), null, "/");
// Configure the use of the plug-in rather than the standard impl
- File plugin = new File(
- "java/org/apache/jasper/tagplugins/jstl/tagPlugins.xml");
+ File plugin = getTagPluginsFile();
Assert.assertTrue(plugin.isFile());
ctx.getResources().createWebResourceSet(
WebResourceRoot.ResourceSetType.POST,
"/WEB-INF/tagPlugins.xml",
@@ -56,4 +55,9 @@ public abstract class AbstractTestTag extends TomcatBaseTest {
tomcat.start();
}
+
+
+ protected File getTagPluginsFile() {
+ return new
File("java/org/apache/jasper/tagplugins/jstl/tagPlugins.xml");
+ }
}
diff --git a/test/org/apache/jasper/tagplugins/jstl/core/TestRedirect.java
b/test/org/apache/jasper/tagplugins/jstl/core/TestRedirect.java
new file mode 100644
index 0000000000..99de0c16d1
--- /dev/null
+++ b/test/org/apache/jasper/tagplugins/jstl/core/TestRedirect.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.jasper.tagplugins.jstl.core;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.servlet.jsp.JspException;
+import jakarta.servlet.jsp.tagext.SimpleTagSupport;
+import jakarta.servlet.jsp.tagext.TagSupport;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestRedirect extends AbstractTestTag {
+
+ private static volatile CountDownLatch pageStarted;
+ private static volatile CountDownLatch pageProcessingContinued;
+
+
+ public static class InvokeBodyTag extends SimpleTagSupport {
+
+ @Override
+ public void doTag() throws JspException, IOException {
+ getJspBody().invoke(null);
+ }
+ }
+
+
+ public static class InvokeBodyClassicTag extends TagSupport {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public int doStartTag() {
+ return EVAL_BODY_INCLUDE;
+ }
+ }
+
+
+ public static void markPageStarted() {
+ pageStarted.countDown();
+ }
+
+
+ public static void markPageProcessingContinued() {
+ pageProcessingContinued.countDown();
+ }
+
+
+ @Override
+ protected File getTagPluginsFile() {
+ return new
File("test/org/apache/jasper/tagplugins/jstl/core/redirect-tagPlugins.xml");
+ }
+
+
+ @Test
+ public void testRedirectSkipsPage() throws Exception {
+ doTestRedirectSkipsPage("redirect.jsp");
+ }
+
+
+ @Test
+ public void testRedirectSkipsPageFromTagFile() throws Exception {
+ doTestRedirectSkipsPage("redirect-tag-file.jsp");
+ }
+
+
+ @Test
+ public void testRedirectSkipsPageFromFragment() throws Exception {
+ doTestRedirectSkipsPage("redirect-fragment.jsp");
+ }
+
+
+ @Test
+ public void testRedirectSkipsPageFromNestedMethod() throws Exception {
+ doTestRedirectSkipsPage("redirect-nested.jsp");
+ }
+
+
+ private void doTestRedirectSkipsPage(String jsp) throws Exception {
+ pageStarted = new CountDownLatch(1);
+ pageProcessingContinued = new CountDownLatch(1);
+ ByteChunk res = new ByteChunk();
+
+ int rc = getUrl("http://localhost:" + getPort() + "/test/jstl/" + jsp,
res, false);
+ Assert.assertEquals(HttpServletResponse.SC_FOUND, rc);
+ Assert.assertTrue(pageStarted.await(1, TimeUnit.SECONDS));
+ Assert.assertFalse(pageProcessingContinued.await(1, TimeUnit.SECONDS));
+ }
+}
diff --git
a/test/org/apache/jasper/tagplugins/jstl/core/redirect-tagPlugins.xml
b/test/org/apache/jasper/tagplugins/jstl/core/redirect-tagPlugins.xml
new file mode 100644
index 0000000000..94441bb2eb
--- /dev/null
+++ b/test/org/apache/jasper/tagplugins/jstl/core/redirect-tagPlugins.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<tag-plugins>
+ <tag-plugin>
+ <tag-class>org.apache.taglibs.standard.tag.rt.core.RedirectTag</tag-class>
+
<plugin-class>org.apache.jasper.tagplugins.jstl.core.Redirect</plugin-class>
+ </tag-plugin>
+</tag-plugins>
diff --git a/test/webapp/WEB-INF/jstl-redirect.tld
b/test/webapp/WEB-INF/jstl-redirect.tld
new file mode 100644
index 0000000000..eb45d30158
--- /dev/null
+++ b/test/webapp/WEB-INF/jstl-redirect.tld
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+<taglib xmlns="https://jakarta.ee/xml/ns/jakartaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
+
https://jakarta.ee/xml/ns/jakartaee/web-jsptaglibrary_4_0.xsd"
+ version="4.0">
+ <tlib-version>1.0</tlib-version>
+ <short-name>Redirect test tags</short-name>
+ <uri>https://tomcat.apache.org/redirect-test-tags</uri>
+
+ <tag>
+ <name>invokeBody</name>
+
<tag-class>org.apache.jasper.tagplugins.jstl.core.TestRedirect$InvokeBodyTag</tag-class>
+ <body-content>scriptless</body-content>
+ <variable>
+ <name-given>fragmentVariable</name-given>
+ <variable-class>java.lang.String</variable-class>
+ <scope>NESTED</scope>
+ </variable>
+ </tag>
+
+ <tag>
+ <name>invokeBodyClassic</name>
+
<tag-class>org.apache.jasper.tagplugins.jstl.core.TestRedirect$InvokeBodyClassicTag</tag-class>
+ <body-content>JSP</body-content>
+ </tag>
+</taglib>
diff --git a/test/webapp/WEB-INF/tags/jstl/redirect.tag
b/test/webapp/WEB-INF/tags/jstl/redirect.tag
new file mode 100644
index 0000000000..f736c35d5f
--- /dev/null
+++ b/test/webapp/WEB-INF/tags/jstl/redirect.tag
@@ -0,0 +1,19 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+--%>
+<%@ tag body-content="empty" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<c:redirect url="/jstl/redirect-target.jsp"/>
diff --git a/test/webapp/jstl/redirect-fragment.jsp
b/test/webapp/jstl/redirect-fragment.jsp
new file mode 100644
index 0000000000..f4feb6a443
--- /dev/null
+++ b/test/webapp/jstl/redirect-fragment.jsp
@@ -0,0 +1,24 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+--%>
+<%@ page session="false"
import="org.apache.jasper.tagplugins.jstl.core.TestRedirect" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="/WEB-INF/jstl-redirect.tld" prefix="test" %>
+<% TestRedirect.markPageStarted(); %>
+<test:invokeBody>
+ <c:redirect url="/jstl/redirect-target.jsp"/>
+</test:invokeBody>
+<% TestRedirect.markPageProcessingContinued(); %>
diff --git a/test/webapp/jstl/redirect-nested.jsp
b/test/webapp/jstl/redirect-nested.jsp
new file mode 100644
index 0000000000..19cb43d7c2
--- /dev/null
+++ b/test/webapp/jstl/redirect-nested.jsp
@@ -0,0 +1,24 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+--%>
+<%@ page session="false"
import="org.apache.jasper.tagplugins.jstl.core.TestRedirect" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="/WEB-INF/jstl-redirect.tld" prefix="test" %>
+<% TestRedirect.markPageStarted(); %>
+<test:invokeBodyClassic>
+ <c:redirect url="/jstl/redirect-target.jsp"/>
+</test:invokeBodyClassic>
+<% TestRedirect.markPageProcessingContinued(); %>
diff --git a/test/webapp/jstl/redirect-tag-file.jsp
b/test/webapp/jstl/redirect-tag-file.jsp
new file mode 100644
index 0000000000..007f2fdfe8
--- /dev/null
+++ b/test/webapp/jstl/redirect-tag-file.jsp
@@ -0,0 +1,21 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+--%>
+<%@ page session="false"
import="org.apache.jasper.tagplugins.jstl.core.TestRedirect" %>
+<%@ taglib prefix="tags" tagdir="/WEB-INF/tags/jstl" %>
+<% TestRedirect.markPageStarted(); %>
+<tags:redirect/>
+<% TestRedirect.markPageProcessingContinued(); %>
diff --git a/test/webapp/jstl/redirect-target.jsp
b/test/webapp/jstl/redirect-target.jsp
new file mode 100644
index 0000000000..c8668b45d0
--- /dev/null
+++ b/test/webapp/jstl/redirect-target.jsp
@@ -0,0 +1,18 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+--%>
+<%@ page session="false" %>
+OK
diff --git a/test/webapp/jstl/redirect.jsp b/test/webapp/jstl/redirect.jsp
new file mode 100644
index 0000000000..c3dd303df9
--- /dev/null
+++ b/test/webapp/jstl/redirect.jsp
@@ -0,0 +1,21 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+--%>
+<%@ page session="false"
import="org.apache.jasper.tagplugins.jstl.core.TestRedirect" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<% TestRedirect.markPageStarted(); %>
+<c:redirect url="/jstl/redirect-target.jsp"/>
+<% TestRedirect.markPageProcessingContinued(); %>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]