This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch WW-5190-match-action-proxy
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 8e468a368eca28646ca7e24a2ff91f122802e048
Author: Lukasz Lenart <lukaszlen...@apache.org>
AuthorDate: Sat Jun 18 09:45:10 2022 +0200

    WW-5190 Defines two examples with Dispatcher result and integration tests
---
 .../src/main/resources/struts-dispatcher.xml       | 40 +++++++++++++++++
 apps/showcase/src/main/resources/struts.xml        |  2 +
 .../src/main/webapp/WEB-INF/decorators/main.jsp    |  2 +
 .../webapp/WEB-INF/dispatcher/dispatch-result.jsp  | 42 ++++++++++++++++++
 apps/showcase/src/main/webapp/WEB-INF/web.xml      | 10 ++++-
 .../struts2/showcase/DispatcherResultTest.java     | 51 ++++++++++++++++++++++
 6 files changed, 145 insertions(+), 2 deletions(-)

diff --git a/apps/showcase/src/main/resources/struts-dispatcher.xml 
b/apps/showcase/src/main/resources/struts-dispatcher.xml
new file mode 100644
index 000000000..659b3f235
--- /dev/null
+++ b/apps/showcase/src/main/resources/struts-dispatcher.xml
@@ -0,0 +1,40 @@
+<?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.
+ */
+-->
+<!DOCTYPE struts PUBLIC
+        "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN"
+        "http://struts.apache.org/dtds/struts-6.0.dtd";>
+
+<struts>
+    <package name="dispatcher" extends="struts-default" 
namespace="/dispatcher">
+
+        <action name="dispatch">
+            <result type="dispatcher">
+                /WEB-INF/dispatcher/dispatch-result.jsp
+            </result>
+        </action>
+
+        <action name="forward">
+            <result type="dispatcher">/dispatcher/dispatch.action</result>
+        </action>
+
+    </package>
+</struts>
diff --git a/apps/showcase/src/main/resources/struts.xml 
b/apps/showcase/src/main/resources/struts.xml
index 36d0370c3..cfdac4b39 100644
--- a/apps/showcase/src/main/resources/struts.xml
+++ b/apps/showcase/src/main/resources/struts.xml
@@ -78,6 +78,8 @@
 
     <include file="struts-async.xml" />
 
+    <include file="struts-dispatcher.xml" />
+
     <package name="default" extends="struts-default">
         <interceptors>
             <interceptor-stack name="crudStack">
diff --git a/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp 
b/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
index 0d09eb647..d63f61f9a 100644
--- a/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
+++ b/apps/showcase/src/main/webapp/WEB-INF/decorators/main.jsp
@@ -244,6 +244,8 @@
                             <li><s:url var="url" namespace="/modelDriven" 
action="modelDriven"/><s:a
                                     href="%{url}">Model Driven</s:a></li>
                             <li><s:a value="/async/index.html">Async</s:a></li>
+                            <li><s:a 
value="/dispatcher/dispatch.action">Dispatcher result - dispatch</s:a></li>
+                            <li><s:a 
value="/dispatcher/forward.action">Dispatcher result - forward</s:a></li>
                         </ul>
                     </li>
                     <li class="dropdown">
diff --git 
a/apps/showcase/src/main/webapp/WEB-INF/dispatcher/dispatch-result.jsp 
b/apps/showcase/src/main/webapp/WEB-INF/dispatcher/dispatch-result.jsp
new file mode 100644
index 000000000..d493b146b
--- /dev/null
+++ b/apps/showcase/src/main/webapp/WEB-INF/dispatcher/dispatch-result.jsp
@@ -0,0 +1,42 @@
+<!--
+/*
+* 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 contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
+<%@ taglib prefix="s" uri="/struts-tags" %>
+<html>
+<head>
+    <title>Struts2 Showcase - Dispatcher result Example</title>
+    <s:head theme="xhtml"/>
+</head>
+<body>
+
+<div class="page-header">
+    <h1>Dispatcher Result Example</h1>
+</div>
+
+<div class="container-fluid">
+    <div class="row">
+        <div id="dispatcher-result" class="col-md-12">
+            This page is a result of &quot;dispatching&quot; to it from an 
action
+        </div>
+    </div>
+</div>
+</body>
+</html>
diff --git a/apps/showcase/src/main/webapp/WEB-INF/web.xml 
b/apps/showcase/src/main/webapp/WEB-INF/web.xml
index d76908275..fe12ba235 100644
--- a/apps/showcase/src/main/webapp/WEB-INF/web.xml
+++ b/apps/showcase/src/main/webapp/WEB-INF/web.xml
@@ -60,16 +60,22 @@
     <filter-mapping>
         <filter-name>struts-prepare</filter-name>
         <url-pattern>/*</url-pattern>
+        <dispatcher>FORWARD</dispatcher>
+        <dispatcher>REQUEST</dispatcher>
     </filter-mapping>
 
     <filter-mapping>
         <filter-name>sitemesh</filter-name>
         <url-pattern>/*</url-pattern>
+        <dispatcher>FORWARD</dispatcher>
+        <dispatcher>REQUEST</dispatcher>
     </filter-mapping>
 
     <filter-mapping>
         <filter-name>struts-execute</filter-name>
         <url-pattern>/*</url-pattern>
+        <dispatcher>FORWARD</dispatcher>
+        <dispatcher>REQUEST</dispatcher>
     </filter-mapping>
 
     <listener>
@@ -81,7 +87,7 @@
             org.apache.struts2.tiles.StrutsTilesListener
         </listener-class>
     </listener>
-    
+
     <!-- Chat Example in Showcase -->
     <listener>
        <listener-class>
@@ -92,7 +98,7 @@
     <listener>
         
<listener-class>org.apache.struts2.dispatcher.listener.StrutsListener</listener-class>
     </listener>
-       
+
     <!-- SNIPPET START: dwr -->
 
     <servlet>
diff --git 
a/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
 
b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
new file mode 100644
index 000000000..2fcbb82ff
--- /dev/null
+++ 
b/apps/showcase/src/test/java/it/org/apache/struts2/showcase/DispatcherResultTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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 it.org.apache.struts2.showcase;
+
+import com.gargoylesoftware.htmlunit.WebClient;
+import com.gargoylesoftware.htmlunit.html.DomElement;
+import com.gargoylesoftware.htmlunit.html.HtmlPage;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class DispatcherResultTest {
+
+    @Test
+    public void testDispatchingToJSP() throws Exception {
+        try (final WebClient webClient = new WebClient()) {
+            final HtmlPage page = 
webClient.getPage(ParameterUtils.getBaseUrl() + "/dispatcher/dispatch.action");
+
+            DomElement div = page.getElementById("dispatcher-result");
+
+            Assert.assertEquals("This page is a result of \"dispatching\" to 
it from an action", div.asNormalizedText());
+        }
+    }
+
+    @Test
+    public void testDispatchingToAction() throws Exception {
+        try (final WebClient webClient = new WebClient()) {
+            final HtmlPage page = 
webClient.getPage(ParameterUtils.getBaseUrl() + "/dispatcher/forward.action");
+
+            DomElement div = page.getElementById("dispatcher-result");
+
+            Assert.assertEquals("This page is a result of \"dispatching\" to 
it from an action", div.asNormalizedText());
+        }
+    }
+
+}

Reply via email to