You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/06/23 17:36:45 UTC
[1/2] struts git commit: WW-4518 Moves the new filters to proper
package
Repository: struts
Updated Branches:
refs/heads/master 6bc99ab93 -> fd0db8656
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java
deleted file mode 100644
index 970d8e7..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareAndExecuteFilter.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng.filter;
-
-import org.apache.struts2.StrutsStatics;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.dispatcher.ng.ExecuteOperations;
-import org.apache.struts2.dispatcher.ng.InitOperations;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.List;
-import java.util.regex.Pattern;
-
-/**
- * Handles both the preparation and execution phases of the Struts dispatching process. This filter is better to use
- * when you don't have another filter that needs access to action context information, such as Sitemesh.
- */
-public class StrutsPrepareAndExecuteFilter implements StrutsStatics, Filter {
- protected PrepareOperations prepare;
- protected ExecuteOperations execute;
- protected List<Pattern> excludedPatterns = null;
-
- public void init(FilterConfig filterConfig) throws ServletException {
- InitOperations init = new InitOperations();
- Dispatcher dispatcher = null;
- try {
- FilterHostConfig config = new FilterHostConfig(filterConfig);
- init.initLogging(config);
- dispatcher = init.initDispatcher(config);
- init.initStaticContentLoader(config, dispatcher);
-
- prepare = new PrepareOperations(dispatcher);
- execute = new ExecuteOperations(dispatcher);
- this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);
-
- postInit(dispatcher, filterConfig);
- } finally {
- if (dispatcher != null) {
- dispatcher.cleanUpAfterInit();
- }
- init.cleanup();
- }
- }
-
- /**
- * Callback for post initialization
- */
- protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
- }
-
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
-
- HttpServletRequest request = (HttpServletRequest) req;
- HttpServletResponse response = (HttpServletResponse) res;
-
- try {
- if (excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
- chain.doFilter(request, response);
- } else {
- prepare.setEncodingAndLocale(request, response);
- prepare.createActionContext(request, response);
- prepare.assignDispatcherToThread();
- request = prepare.wrapRequest(request);
- ActionMapping mapping = prepare.findActionMapping(request, response, true);
- if (mapping == null) {
- boolean handled = execute.executeStaticResourceRequest(request, response);
- if (!handled) {
- chain.doFilter(request, response);
- }
- } else {
- execute.executeAction(request, response, mapping);
- }
- }
- } finally {
- prepare.cleanupRequest(request);
- }
- }
-
- public void destroy() {
- prepare.cleanupDispatcher();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareFilter.java
deleted file mode 100644
index 27ce17e..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsPrepareFilter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng.filter;
-
-import org.apache.struts2.StrutsStatics;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.ng.InitOperations;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
-
-import javax.servlet.Filter;
-import javax.servlet.FilterChain;
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.List;
-import java.util.regex.Pattern;
-
-/**
- * Prepares the request for execution by a later {@link org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter} filter instance.
- */
-public class StrutsPrepareFilter implements StrutsStatics, Filter {
-
- protected static final String REQUEST_EXCLUDED_FROM_ACTION_MAPPING = StrutsPrepareFilter.class.getName() + ".REQUEST_EXCLUDED_FROM_ACTION_MAPPING";
-
- protected PrepareOperations prepare;
- protected List<Pattern> excludedPatterns = null;
-
- public void init(FilterConfig filterConfig) throws ServletException {
- InitOperations init = new InitOperations();
- Dispatcher dispatcher = null;
- try {
- FilterHostConfig config = new FilterHostConfig(filterConfig);
- init.initLogging(config);
- dispatcher = init.initDispatcher(config);
-
- prepare = new PrepareOperations(dispatcher);
- this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);
-
- postInit(dispatcher, filterConfig);
- } finally {
- if (dispatcher != null) {
- dispatcher.cleanUpAfterInit();
- }
- init.cleanup();
- }
- }
-
- /**
- * Callback for post initialization
- */
- protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
- }
-
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
-
- HttpServletRequest request = (HttpServletRequest) req;
- HttpServletResponse response = (HttpServletResponse) res;
-
- try {
- if (excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
- request.setAttribute(REQUEST_EXCLUDED_FROM_ACTION_MAPPING, new Object());
- } else {
- prepare.setEncodingAndLocale(request, response);
- prepare.createActionContext(request, response);
- prepare.assignDispatcherToThread();
- request = prepare.wrapRequest(request);
- prepare.findActionMapping(request, response);
- }
- chain.doFilter(request, response);
- } finally {
- prepare.cleanupRequest(request);
- }
- }
-
- public void destroy() {
- prepare.cleanupDispatcher();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/ListenerHostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/ListenerHostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/ListenerHostConfig.java
deleted file mode 100644
index 4545e79..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/ListenerHostConfig.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * $Id$
- *
- * 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.struts2.dispatcher.ng.listener;
-
-import org.apache.struts2.dispatcher.ng.HostConfig;
-
-import javax.servlet.ServletContext;
-import java.util.Iterator;
-import java.util.Collections;
-
-/**
- * Host configuration that just holds a ServletContext
- */
-public class ListenerHostConfig implements HostConfig {
- private ServletContext servletContext;
-
- public ListenerHostConfig(ServletContext servletContext) {
- this.servletContext = servletContext;
- }
-
- public String getInitParameter(String key) {
- return null;
- }
-
- public Iterator<String> getInitParameterNames() {
- return Collections.<String>emptyList().iterator();
- }
-
- public ServletContext getServletContext() {
- return servletContext;
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/StrutsListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/StrutsListener.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/StrutsListener.java
deleted file mode 100644
index 92c49ac..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/listener/StrutsListener.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * $Id$
- *
- * 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.struts2.dispatcher.ng.listener;
-
-import org.apache.struts2.StrutsStatics;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.ng.InitOperations;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-/**
- * Servlet listener for Struts. The preferred way to use Struts is as a filter via the
- * {@link org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter} and its variants.
- * This might be useful if Struts config information is needed from other servlet listeners, like
- * Sitemesh or OSGi
- */
-public class StrutsListener implements ServletContextListener {
- private PrepareOperations prepare;
-
- public void contextInitialized(ServletContextEvent sce) {
- InitOperations init = new InitOperations();
- Dispatcher dispatcher = null;
- try {
- ListenerHostConfig config = new ListenerHostConfig(sce.getServletContext());
- init.initLogging(config);
- dispatcher = init.initDispatcher(config);
- init.initStaticContentLoader(config, dispatcher);
-
- prepare = new PrepareOperations(dispatcher);
- sce.getServletContext().setAttribute(StrutsStatics.SERVLET_DISPATCHER, dispatcher);
- } finally {
- if (dispatcher != null) {
- dispatcher.cleanUpAfterInit();
- }
- init.cleanup();
- }
- }
-
- public void contextDestroyed(ServletContextEvent sce) {
- prepare.cleanupDispatcher();
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/package-info.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/package-info.java
deleted file mode 100644
index 1f3fba4..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/package-info.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.
- */
-/**
- * This package contains a reimagining of the traditional Struts filter dispatchers. Each specific deployment has
- * their own filters to prevent confusion. In addition, the operations have been explicitly pulled into *Operations
- * objects that try to document through method naming what is happening at every step. Here are a few common use
- * cases and how you would manage the Struts deployment:
- *
- * <h3>Simple Dispatcher</h3>
- * <pre>
- * <filter>
- * <filter-name>struts2</filter-name>
- * <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- * </filter>
- *
- * <filter-mapping>
- * <filter-name>struts2</filter-name>
- * <url-pattern>/*</url-pattern>
- * </filter-mapping>
- * </pre>
- *
- * <h3>Deployment with Sitemesh</h3>
- * <pre>
- * <filter>
- * <filter-name>struts2-prepare</filter-name>
- * <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
- * </filter>
- * <filter>
- * <filter-name>sitemesh</filter-name>
- * <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
- * </filter>
- * <filter>
- * <filter-name>struts2-execute</filter-name>
- * <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
- * </filter>
- *
- * <filter-mapping>
- * <filter-name>struts2-prepare</filter-name>
- * <url-pattern>/*</url-pattern>
- * </filter-mapping>
- * <filter-mapping>
- * <filter-name>sitemesh</filter-name>
- * <url-pattern>/*</url-pattern>
- * </filter-mapping>
- * <filter-mapping>
- * <filter-name>struts2-execute</filter-name>
- * <url-pattern>/*</url-pattern>
- * </filter-mapping>
- * </pre>
- *
- */
-package org.apache.struts2.dispatcher.ng;
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/ServletHostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/ServletHostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/ServletHostConfig.java
deleted file mode 100644
index 098f6cd..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/ServletHostConfig.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng.servlet;
-
-import org.apache.struts2.util.MakeIterator;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import java.util.Iterator;
-
-import org.apache.struts2.dispatcher.ng.HostConfig;
-
-/**
- * Host configuration that wraps a ServletConfig
- */
-public class ServletHostConfig implements HostConfig {
- private ServletConfig config;
-
- public ServletHostConfig(ServletConfig config) {
- this.config = config;
- }
- public String getInitParameter(String key) {
- return config.getInitParameter(key);
- }
-
- public Iterator<String> getInitParameterNames() {
- return MakeIterator.convert(config.getInitParameterNames());
- }
-
- public ServletContext getServletContext() {
- return config.getServletContext();
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/StrutsServlet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/StrutsServlet.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/StrutsServlet.java
deleted file mode 100644
index 19c8c73..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/servlet/StrutsServlet.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng.servlet;
-
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.dispatcher.ng.ExecuteOperations;
-import org.apache.struts2.dispatcher.ng.InitOperations;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
-
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * Servlet dispatcher for Struts. The preferred way to use Struts is as a filter via the
- * {@link org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter} and its variants. This servlet dispatcher
- * is only for those that really know what they are doing as it may not support every feature of Struts, particularly
- * static resource serving.
- */
-public class StrutsServlet extends HttpServlet {
-
- private PrepareOperations prepare;
- private ExecuteOperations execute;
-
- @Override
- public void init(ServletConfig filterConfig) throws ServletException {
- InitOperations init = new InitOperations();
- Dispatcher dispatcher = null;
- try {
- ServletHostConfig config = new ServletHostConfig(filterConfig);
- init.initLogging(config);
- dispatcher = init.initDispatcher(config);
- init.initStaticContentLoader(config, dispatcher);
-
- prepare = new PrepareOperations(dispatcher);
- execute = new ExecuteOperations(dispatcher);
- } finally {
- if (dispatcher != null) {
- dispatcher.cleanUpAfterInit();
- }
- init.cleanup();
- }
- }
-
- @Override
- public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
-
- try {
- prepare.createActionContext(request, response);
- prepare.assignDispatcherToThread();
- prepare.setEncodingAndLocale(request, response);
- request = prepare.wrapRequest(request);
- ActionMapping mapping = prepare.findActionMapping(request, response);
- if (mapping == null) {
- boolean handled = execute.executeStaticResourceRequest(request, response);
- if (!handled)
- throw new ServletException("Resource loading not supported, use the StrutsPrepareAndExecuteFilter instead.");
- } else {
- execute.executeAction(request, response, mapping);
- }
- } finally {
- prepare.cleanupRequest(request);
- }
- }
-
- @Override
- public void destroy() {
- prepare.cleanupDispatcher();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/package-info.java b/core/src/main/java/org/apache/struts2/dispatcher/package-info.java
new file mode 100644
index 0000000..eb22fd9
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/package-info.java
@@ -0,0 +1,70 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.
+ */
+/**
+ * This package contains a reimagining of the traditional Struts filter dispatchers. Each specific deployment has
+ * their own filters to prevent confusion. In addition, the operations have been explicitly pulled into *Operations
+ * objects that try to document through method naming what is happening at every step. Here are a few common use
+ * cases and how you would manage the Struts deployment:
+ *
+ * <h3>Simple Dispatcher</h3>
+ * <pre>
+ * <filter>
+ * <filter-name>struts2</filter-name>
+ * <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ * </filter>
+ *
+ * <filter-mapping>
+ * <filter-name>struts2</filter-name>
+ * <url-pattern>/*</url-pattern>
+ * </filter-mapping>
+ * </pre>
+ *
+ * <h3>Deployment with Sitemesh</h3>
+ * <pre>
+ * <filter>
+ * <filter-name>struts2-prepare</filter-name>
+ * <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
+ * </filter>
+ * <filter>
+ * <filter-name>sitemesh</filter-name>
+ * <filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
+ * </filter>
+ * <filter>
+ * <filter-name>struts2-execute</filter-name>
+ * <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
+ * </filter>
+ *
+ * <filter-mapping>
+ * <filter-name>struts2-prepare</filter-name>
+ * <url-pattern>/*</url-pattern>
+ * </filter-mapping>
+ * <filter-mapping>
+ * <filter-name>sitemesh</filter-name>
+ * <url-pattern>/*</url-pattern>
+ * </filter-mapping>
+ * <filter-mapping>
+ * <filter-name>struts2-execute</filter-name>
+ * <url-pattern>/*</url-pattern>
+ * </filter-mapping>
+ * </pre>
+ *
+ */
+package org.apache.struts2.dispatcher;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/package.html
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/package.html b/core/src/main/java/org/apache/struts2/dispatcher/package.html
deleted file mode 100644
index c8be145..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/package.html
+++ /dev/null
@@ -1,23 +0,0 @@
-<!--
-/*
- * $Id$
- *
- * 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.
- */
--->
-<body>Classes for action dispatching in Struts (the Controller part of MVC).</body>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/servlet/ServletHostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/servlet/ServletHostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/servlet/ServletHostConfig.java
new file mode 100644
index 0000000..b449304
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/servlet/ServletHostConfig.java
@@ -0,0 +1,51 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher.servlet;
+
+import org.apache.struts2.util.MakeIterator;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Iterator;
+
+import org.apache.struts2.dispatcher.HostConfig;
+
+/**
+ * Host configuration that wraps a ServletConfig
+ */
+public class ServletHostConfig implements HostConfig {
+ private ServletConfig config;
+
+ public ServletHostConfig(ServletConfig config) {
+ this.config = config;
+ }
+ public String getInitParameter(String key) {
+ return config.getInitParameter(key);
+ }
+
+ public Iterator<String> getInitParameterNames() {
+ return MakeIterator.convert(config.getInitParameterNames());
+ }
+
+ public ServletContext getServletContext() {
+ return config.getServletContext();
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java b/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java
new file mode 100644
index 0000000..6a7e364
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/servlet/StrutsServlet.java
@@ -0,0 +1,94 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher.servlet;
+
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.ExecuteOperations;
+import org.apache.struts2.dispatcher.InitOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
+import org.apache.struts2.dispatcher.servlet.ServletHostConfig;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Servlet dispatcher for Struts. The preferred way to use Struts is as a filter via the
+ * {@link org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter} and its variants. This servlet dispatcher
+ * is only for those that really know what they are doing as it may not support every feature of Struts, particularly
+ * static resource serving.
+ */
+public class StrutsServlet extends HttpServlet {
+
+ private PrepareOperations prepare;
+ private ExecuteOperations execute;
+
+ @Override
+ public void init(ServletConfig filterConfig) throws ServletException {
+ InitOperations init = new InitOperations();
+ Dispatcher dispatcher = null;
+ try {
+ ServletHostConfig config = new ServletHostConfig(filterConfig);
+ init.initLogging(config);
+ dispatcher = init.initDispatcher(config);
+ init.initStaticContentLoader(config, dispatcher);
+
+ prepare = new PrepareOperations(dispatcher);
+ execute = new ExecuteOperations(dispatcher);
+ } finally {
+ if (dispatcher != null) {
+ dispatcher.cleanUpAfterInit();
+ }
+ init.cleanup();
+ }
+ }
+
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+
+ try {
+ prepare.createActionContext(request, response);
+ prepare.assignDispatcherToThread();
+ prepare.setEncodingAndLocale(request, response);
+ request = prepare.wrapRequest(request);
+ ActionMapping mapping = prepare.findActionMapping(request, response);
+ if (mapping == null) {
+ boolean handled = execute.executeStaticResourceRequest(request, response);
+ if (!handled)
+ throw new ServletException("Resource loading not supported, use the StrutsPrepareAndExecuteFilter instead.");
+ } else {
+ execute.executeAction(request, response, mapping);
+ }
+ } finally {
+ prepare.cleanupRequest(request);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ prepare.cleanupDispatcher();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
index 43752ce..33b19f4 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/debugging/DebuggingInterceptor.java
@@ -32,7 +32,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.freemarker.FreemarkerResult;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java b/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
index 607394f..693a52f 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/StaticContentLoaderTest.java
@@ -26,7 +26,6 @@ import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
-import org.apache.struts2.dispatcher.ng.HostConfig;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockServletContext;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java b/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java
index 9cd9bcf..564f0f9 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/ng/StrutsPrepareAndExecuteFilterIntegrationTest.java
@@ -23,7 +23,7 @@ package org.apache.struts2.dispatcher.ng;
import com.opensymphony.xwork2.ActionContext;
import junit.framework.TestCase;
import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
+import org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter;
import org.springframework.mock.web.MockFilterChain;
import org.springframework.mock.web.MockFilterConfig;
import org.springframework.mock.web.MockHttpServletRequest;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/test/java/org/apache/struts2/dispatcher/ng/TwoFilterIntegrationTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ng/TwoFilterIntegrationTest.java b/core/src/test/java/org/apache/struts2/dispatcher/ng/TwoFilterIntegrationTest.java
index 52c98a5..e392155 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/ng/TwoFilterIntegrationTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/ng/TwoFilterIntegrationTest.java
@@ -23,8 +23,9 @@ package org.apache.struts2.dispatcher.ng;
import com.opensymphony.xwork2.ActionContext;
import junit.framework.TestCase;
import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter;
-import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter;
+import org.apache.struts2.dispatcher.PrepareOperations;
+import org.apache.struts2.dispatcher.filter.StrutsExecuteFilter;
+import org.apache.struts2.dispatcher.filter.StrutsPrepareFilter;
import org.springframework.mock.web.*;
import javax.servlet.*;
@@ -145,4 +146,4 @@ public class TwoFilterIntegrationTest extends TestCase {
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java
----------------------------------------------------------------------
diff --git a/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java b/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java
index f81609f..553f08c 100644
--- a/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java
+++ b/plugins/json/src/main/java/org/apache/struts2/json/JSONInterceptor.java
@@ -31,7 +31,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
import org.apache.struts2.json.annotations.SMDMethod;
import org.apache.struts2.json.rpc.RPCError;
import org.apache.struts2.json.rpc.RPCErrorCode;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
----------------------------------------------------------------------
diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
index 573fe61..b2d9ef5 100644
--- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
+++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
@@ -31,7 +31,7 @@ import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.Dispatcher;
import org.apache.struts2.dispatcher.StrutsRequestWrapper;
-import org.apache.struts2.dispatcher.ng.listener.StrutsListener;
+import org.apache.struts2.dispatcher.listener.StrutsListener;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.freemarker.ScopesHashModel;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
----------------------------------------------------------------------
diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
index 5ddcdd5..416dfd5 100644
--- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
+++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
@@ -31,7 +31,7 @@ import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.ng.listener.StrutsListener;
+import org.apache.struts2.dispatcher.listener.StrutsListener;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.velocity.Template;
import org.apache.velocity.context.Context;
[2/2] struts git commit: WW-4518 Moves the new filters to proper
package
Posted by lu...@apache.org.
WW-4518 Moves the new filters to proper package
Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/fd0db865
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/fd0db865
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/fd0db865
Branch: refs/heads/master
Commit: fd0db86560edeee7418ce3bec4e21c8f75e3aa81
Parents: 6bc99ab
Author: Lukasz Lenart <lu...@apache.org>
Authored: Tue Jun 23 17:36:32 2015 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Tue Jun 23 17:36:32 2015 +0200
----------------------------------------------------------------------
apps/portlet/src/main/etc/exo/web.xml | 2 +-
apps/portlet/src/main/etc/gridsphere/web.xml | 2 +-
apps/portlet/src/main/etc/liferay3.6.1/web.xml | 2 +-
.../src/main/webapp/WEB-INF/web.xml | 2 +-
apps/showcase/src/main/webapp/WEB-INF/web.xml | 6 +-
.../src/main/webapp/WEB-INF/web.xml | 2 +-
.../src/main/webapp/WEB-INF/web.xml | 2 +-
.../src/main/webapp/WEB-INF/web.xml | 2 +-
.../src/main/webapp/WEB-INF/web.xml | 2 +-
.../src/main/webapp/WEB-INF/web.xml | 2 +-
.../src/main/webapp/WEB-INF/web.xml | 4 +-
.../DefaultDispatcherErrorHandler.java | 2 -
.../dispatcher/DefaultStaticContentLoader.java | 1 -
.../apache/struts2/dispatcher/Dispatcher.java | 2 +-
.../struts2/dispatcher/ExecuteOperations.java | 75 ++++++
.../apache/struts2/dispatcher/HostConfig.java | 46 ++++
.../struts2/dispatcher/InitOperations.java | 139 +++++++++++
.../struts2/dispatcher/PrepareOperations.java | 227 ++++++++++++++++++
.../struts2/dispatcher/StaticContentLoader.java | 4 +-
.../dispatcher/filter/FilterHostConfig.java | 52 +++++
.../dispatcher/filter/StrutsExecuteFilter.java | 102 +++++++++
.../filter/StrutsPrepareAndExecuteFilter.java | 111 +++++++++
.../dispatcher/filter/StrutsPrepareFilter.java | 101 ++++++++
.../dispatcher/listener/ListenerHostConfig.java | 50 ++++
.../dispatcher/listener/StrutsListener.java | 62 +++++
.../dispatcher/ng/ExecuteOperations.java | 78 -------
.../struts2/dispatcher/ng/HostConfig.java | 46 ----
.../struts2/dispatcher/ng/InitOperations.java | 141 ------------
.../dispatcher/ng/PrepareOperations.java | 229 -------------------
.../dispatcher/ng/filter/FilterHostConfig.java | 52 -----
.../ng/filter/StrutsExecuteFilter.java | 102 ---------
.../filter/StrutsPrepareAndExecuteFilter.java | 111 ---------
.../ng/filter/StrutsPrepareFilter.java | 101 --------
.../ng/listener/ListenerHostConfig.java | 50 ----
.../dispatcher/ng/listener/StrutsListener.java | 62 -----
.../struts2/dispatcher/ng/package-info.java | 70 ------
.../ng/servlet/ServletHostConfig.java | 51 -----
.../dispatcher/ng/servlet/StrutsServlet.java | 93 --------
.../apache/struts2/dispatcher/package-info.java | 70 ++++++
.../org/apache/struts2/dispatcher/package.html | 23 --
.../dispatcher/servlet/ServletHostConfig.java | 51 +++++
.../dispatcher/servlet/StrutsServlet.java | 94 ++++++++
.../debugging/DebuggingInterceptor.java | 2 +-
.../dispatcher/StaticContentLoaderTest.java | 1 -
...sPrepareAndExecuteFilterIntegrationTest.java | 2 +-
.../dispatcher/ng/TwoFilterIntegrationTest.java | 7 +-
.../apache/struts2/json/JSONInterceptor.java | 2 +-
.../sitemesh/FreemarkerDecoratorServlet.java | 2 +-
.../sitemesh/VelocityDecoratorServlet.java | 2 +-
49 files changed, 1205 insertions(+), 1239 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/apps/portlet/src/main/etc/exo/web.xml
----------------------------------------------------------------------
diff --git a/apps/portlet/src/main/etc/exo/web.xml b/apps/portlet/src/main/etc/exo/web.xml
index b56d9fa..a6357e9 100644
--- a/apps/portlet/src/main/etc/exo/web.xml
+++ b/apps/portlet/src/main/etc/exo/web.xml
@@ -10,7 +10,7 @@
<filter>
<filter-name>action2</filter-name>
<filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
+ org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/apps/portlet/src/main/etc/gridsphere/web.xml
----------------------------------------------------------------------
diff --git a/apps/portlet/src/main/etc/gridsphere/web.xml b/apps/portlet/src/main/etc/gridsphere/web.xml
index f7fee3a..0653b25 100644
--- a/apps/portlet/src/main/etc/gridsphere/web.xml
+++ b/apps/portlet/src/main/etc/gridsphere/web.xml
@@ -10,7 +10,7 @@
<filter>
<filter-name>action2</filter-name>
<filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
+ org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/apps/portlet/src/main/etc/liferay3.6.1/web.xml
----------------------------------------------------------------------
diff --git a/apps/portlet/src/main/etc/liferay3.6.1/web.xml b/apps/portlet/src/main/etc/liferay3.6.1/web.xml
index bffebfb..73c769f 100644
--- a/apps/portlet/src/main/etc/liferay3.6.1/web.xml
+++ b/apps/portlet/src/main/etc/liferay3.6.1/web.xml
@@ -13,7 +13,7 @@
<filter>
<filter-name>action2</filter-name>
<filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
+ org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml b/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml
index 694c349..ddd928d 100644
--- a/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml
+++ b/apps/rest-showcase/src/main/webapp/WEB-INF/web.xml
@@ -12,7 +12,7 @@
<!-- START SNIPPET: filter -->
<filter>
<filter-name>action2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<!-- END SNIPPET: filter -->
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/apps/showcase/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/apps/showcase/src/main/webapp/WEB-INF/web.xml b/apps/showcase/src/main/webapp/WEB-INF/web.xml
index 788c0b4..5b7f48a 100644
--- a/apps/showcase/src/main/webapp/WEB-INF/web.xml
+++ b/apps/showcase/src/main/webapp/WEB-INF/web.xml
@@ -8,12 +8,12 @@
<filter>
<filter-name>struts-prepare</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
</filter>
@@ -55,7 +55,7 @@
</listener>
<listener>
- <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
+ <listener-class>org.apache.struts2.dispatcher.listener.StrutsListener</listener-class>
</listener>
<!-- SNIPPET START: dwr -->
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index e2fb09c..8d08c0b 100644
--- a/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/archetypes/struts2-archetype-angularjs/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -6,7 +6,7 @@
<filter>
<filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/archetypes/struts2-archetype-blank/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-blank/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetypes/struts2-archetype-blank/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index d6897e8..8858656 100644
--- a/archetypes/struts2-archetype-blank/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/archetypes/struts2-archetype-blank/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -8,7 +8,7 @@
<filter>
<filter-name>struts2</filter-name>
<filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
+ org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/archetypes/struts2-archetype-convention/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-convention/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetypes/struts2-archetype-convention/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index 4cb27b5..1eaebba 100644
--- a/archetypes/struts2-archetype-convention/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/archetypes/struts2-archetype-convention/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -11,7 +11,7 @@
<filter>
<filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index 7c8e596..d22380f 100644
--- a/archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -9,7 +9,7 @@
<filter id="filterdispatcher">
<filter-name>struts</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/archetypes/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetypes/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index 3492c91..9139463 100644
--- a/archetypes/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/archetypes/struts2-archetype-portlet/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -6,7 +6,7 @@
<filter>
<filter-name>struts2</filter-name>
<filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
+ org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
index a2d3101..58c84c6 100644
--- a/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
+++ b/archetypes/struts2-archetype-starter/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml
@@ -15,7 +15,7 @@
<!-- Filters -->
<filter>
<filter-name>struts2-prepare</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
@@ -23,7 +23,7 @@
</filter>
<filter>
<filter-name>struts2-execute</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
+ <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/DefaultDispatcherErrorHandler.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/DefaultDispatcherErrorHandler.java b/core/src/main/java/org/apache/struts2/dispatcher/DefaultDispatcherErrorHandler.java
index 13523ce..4abb23f 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/DefaultDispatcherErrorHandler.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/DefaultDispatcherErrorHandler.java
@@ -9,8 +9,6 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
-import org.apache.struts2.dispatcher.ng.ExecuteOperations;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import javax.servlet.ServletContext;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java b/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
index fcdc7cf..ef8505b 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/DefaultStaticContentLoader.java
@@ -26,7 +26,6 @@ import org.apache.commons.lang3.BooleanUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.dispatcher.ng.HostConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
index d33fa61..a63e503 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
@@ -72,7 +72,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* of the primary dispatcher holds an instance of this dispatcher to be shared for
* all requests.
*
- * @see org.apache.struts2.dispatcher.ng.InitOperations
+ * @see InitOperations
*/
public class Dispatcher {
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ExecuteOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ExecuteOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/ExecuteOperations.java
new file mode 100644
index 0000000..43f00f4
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/ExecuteOperations.java
@@ -0,0 +1,75 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher;
+
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.RequestUtils;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Contains execution operations for filters
+ */
+public class ExecuteOperations {
+
+ private Dispatcher dispatcher;
+
+ public ExecuteOperations(Dispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+
+ /**
+ * Tries to execute a request for a static resource
+ * @return True if it was handled, false if the filter should fall through
+ * @throws IOException
+ * @throws ServletException
+ */
+ public boolean executeStaticResourceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
+ // there is no action in this request, should we look for a static resource?
+ String resourcePath = RequestUtils.getServletPath(request);
+
+ if ("".equals(resourcePath) && null != request.getPathInfo()) {
+ resourcePath = request.getPathInfo();
+ }
+
+ StaticContentLoader staticResourceLoader = dispatcher.getContainer().getInstance(StaticContentLoader.class);
+ if (staticResourceLoader.canHandle(resourcePath)) {
+ staticResourceLoader.findStaticResource(resourcePath, request, response);
+ // The framework did its job here
+ return true;
+
+ } else {
+ // this is a normal request, let it pass through
+ return false;
+ }
+ }
+
+ /**
+ * Executes an action
+ * @throws ServletException
+ */
+ public void executeAction(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException {
+ dispatcher.serviceAction(request, response, mapping);
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/HostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/HostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/HostConfig.java
new file mode 100644
index 0000000..2dd12b4
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/HostConfig.java
@@ -0,0 +1,46 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher;
+
+import javax.servlet.ServletContext;
+import java.util.Iterator;
+
+/**
+ * Abstraction for host configuration information such as init params or the servlet context.
+ */
+public interface HostConfig {
+
+ /**
+ * @param key The parameter key
+ * @return The parameter value
+ */
+ String getInitParameter(String key);
+
+ /**
+ * @return A list of parameter names
+ */
+ Iterator<String> getInitParameterNames();
+
+ /**
+ * @return The servlet context
+ */
+ ServletContext getServletContext();
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java
new file mode 100644
index 0000000..da0f163
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/InitOperations.java
@@ -0,0 +1,139 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.util.ClassLoaderUtil;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.StrutsConstants;
+
+import java.util.*;
+import java.util.regex.Pattern;
+
+/**
+ * Contains initialization operations
+ */
+public class InitOperations {
+
+ public InitOperations() {
+ }
+
+ /**
+ * Initializes the internal Struts logging
+ *
+ * @deprecated since 2.5
+ */
+ @Deprecated
+ public void initLogging( HostConfig filterConfig ) {
+ String factoryName = filterConfig.getInitParameter("loggerFactory");
+ if (factoryName != null) {
+ try {
+ Class cls = ClassLoaderUtil.loadClass(factoryName, this.getClass());
+ LoggerFactory fac = (LoggerFactory) cls.newInstance();
+ LoggerFactory.setLoggerFactory(fac);
+ } catch ( InstantiationException e ) {
+ System.err.println("Unable to instantiate logger factory: " + factoryName + ", using default");
+ e.printStackTrace();
+ } catch ( IllegalAccessException e ) {
+ System.err.println("Unable to access logger factory: " + factoryName + ", using default");
+ e.printStackTrace();
+ } catch ( ClassNotFoundException e ) {
+ System.err.println("Unable to locate logger factory class: " + factoryName + ", using default");
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * Creates and initializes the dispatcher
+ */
+ public Dispatcher initDispatcher( HostConfig filterConfig ) {
+ Dispatcher dispatcher = createDispatcher(filterConfig);
+ dispatcher.init();
+ return dispatcher;
+ }
+
+ /**
+ * Initializes the static content loader with the filter configuration
+ */
+ public StaticContentLoader initStaticContentLoader( HostConfig filterConfig, Dispatcher dispatcher ) {
+ StaticContentLoader loader = dispatcher.getContainer().getInstance(StaticContentLoader.class);
+ loader.setHostConfig(filterConfig);
+ return loader;
+ }
+
+ /**
+ * @return The dispatcher on the thread.
+ *
+ * @throws IllegalStateException If there is no dispatcher available
+ */
+ public Dispatcher findDispatcherOnThread() {
+ Dispatcher dispatcher = Dispatcher.getInstance();
+ if (dispatcher == null) {
+ throw new IllegalStateException("Must have the StrutsPrepareFilter execute before this one");
+ }
+ return dispatcher;
+ }
+
+ /**
+ * Create a {@link Dispatcher}
+ */
+ private Dispatcher createDispatcher( HostConfig filterConfig ) {
+ Map<String, String> params = new HashMap<>();
+ for ( Iterator e = filterConfig.getInitParameterNames(); e.hasNext(); ) {
+ String name = (String) e.next();
+ String value = filterConfig.getInitParameter(name);
+ params.put(name, value);
+ }
+ return new Dispatcher(filterConfig.getServletContext(), params);
+ }
+
+ public void cleanup() {
+ ActionContext.setContext(null);
+ }
+
+ /**
+ * Extract a list of patterns to exclude from request filtering
+ *
+ * @param dispatcher The dispatcher to check for exclude pattern configuration
+ *
+ * @return a List of Patterns for request to exclude if apply, or <tt>null</tt>
+ *
+ * @see org.apache.struts2.StrutsConstants#STRUTS_ACTION_EXCLUDE_PATTERN
+ */
+ public List<Pattern> buildExcludedPatternsList( Dispatcher dispatcher ) {
+ return buildExcludedPatternsList(dispatcher.getContainer().getInstance(String.class, StrutsConstants.STRUTS_ACTION_EXCLUDE_PATTERN));
+ }
+
+ private List<Pattern> buildExcludedPatternsList( String patterns ) {
+ if (null != patterns && patterns.trim().length() != 0) {
+ List<Pattern> list = new ArrayList<>();
+ String[] tokens = patterns.split(",");
+ for ( String token : tokens ) {
+ list.add(Pattern.compile(token.trim()));
+ }
+ return Collections.unmodifiableList(list);
+ } else {
+ return null;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
new file mode 100644
index 0000000..ab6861f
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/PrepareOperations.java
@@ -0,0 +1,227 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.RequestUtils;
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.dispatcher.mapper.ActionMapper;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * Contains preparation operations for a request before execution
+ */
+public class PrepareOperations {
+
+ private static final Logger LOG = LogManager.getLogger(PrepareOperations.class);
+
+ /**
+ * Maintains per-request override of devMode configuration.
+ */
+ private static ThreadLocal<Boolean> devModeOverride = new InheritableThreadLocal<>();
+
+
+ private Dispatcher dispatcher;
+ private static final String STRUTS_ACTION_MAPPING_KEY = "struts.actionMapping";
+ public static final String CLEANUP_RECURSION_COUNTER = "__cleanup_recursion_counter";
+
+ public PrepareOperations(Dispatcher dispatcher) {
+ this.dispatcher = dispatcher;
+ }
+
+ /**
+ * Creates the action context and initializes the thread local
+ */
+ public ActionContext createActionContext(HttpServletRequest request, HttpServletResponse response) {
+ ActionContext ctx;
+ Integer counter = 1;
+ Integer oldCounter = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
+ if (oldCounter != null) {
+ counter = oldCounter + 1;
+ }
+
+ ActionContext oldContext = ActionContext.getContext();
+ if (oldContext != null) {
+ // detected existing context, so we are probably in a forward
+ ctx = new ActionContext(new HashMap<>(oldContext.getContextMap()));
+ } else {
+ ValueStack stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack();
+ stack.getContext().putAll(dispatcher.createContextMap(request, response, null));
+ ctx = new ActionContext(stack.getContext());
+ }
+ request.setAttribute(CLEANUP_RECURSION_COUNTER, counter);
+ ActionContext.setContext(ctx);
+ return ctx;
+ }
+
+ /**
+ * Cleans up a request of thread locals
+ */
+ public void cleanupRequest(HttpServletRequest request) {
+ Integer counterVal = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
+ if (counterVal != null) {
+ counterVal -= 1;
+ request.setAttribute(CLEANUP_RECURSION_COUNTER, counterVal);
+ if (counterVal > 0 ) {
+ LOG.debug("skipping cleanup counter={}", counterVal);
+ return;
+ }
+ }
+ // always clean up the thread request, even if an action hasn't been executed
+ try {
+ dispatcher.cleanUpRequest(request);
+ } finally {
+ ActionContext.setContext(null);
+ Dispatcher.setInstance(null);
+ devModeOverride.remove();
+ }
+ }
+
+ /**
+ * Assigns the dispatcher to the dispatcher thread local
+ */
+ public void assignDispatcherToThread() {
+ Dispatcher.setInstance(dispatcher);
+ }
+
+ /**
+ * Sets the request encoding and locale on the response
+ */
+ public void setEncodingAndLocale(HttpServletRequest request, HttpServletResponse response) {
+ dispatcher.prepare(request, response);
+ }
+
+ /**
+ * Wraps the request with the Struts wrapper that handles multipart requests better
+ * @return The new request, if there is one
+ * @throws ServletException
+ */
+ public HttpServletRequest wrapRequest(HttpServletRequest oldRequest) throws ServletException {
+ HttpServletRequest request = oldRequest;
+ try {
+ // Wrap request first, just in case it is multipart/form-data
+ // parameters might not be accessible through before encoding (ww-1278)
+ request = dispatcher.wrapRequest(request);
+ } catch (IOException e) {
+ throw new ServletException("Could not wrap servlet request with MultipartRequestWrapper!", e);
+ }
+ return request;
+ }
+
+ /**
+ * Finds and optionally creates an {@link ActionMapping}. It first looks in the current request to see if one
+ * has already been found, otherwise, it creates it and stores it in the request. No mapping will be created in the
+ * case of static resource requests or unidentifiable requests for other servlets, for example.
+ */
+ public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response) {
+ return findActionMapping(request, response, false);
+ }
+
+ /**
+ * Finds and optionally creates an {@link ActionMapping}. if forceLookup is false, it first looks in the current request to see if one
+ * has already been found, otherwise, it creates it and stores it in the request. No mapping will be created in the
+ * case of static resource requests or unidentifiable requests for other servlets, for example.
+ * @param forceLookup if true, the action mapping will be looked up from the ActionMapper instance, ignoring if there is one
+ * in the request or not
+ */
+ public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response, boolean forceLookup) {
+ ActionMapping mapping = (ActionMapping) request.getAttribute(STRUTS_ACTION_MAPPING_KEY);
+ if (mapping == null || forceLookup) {
+ try {
+ mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
+ if (mapping != null) {
+ request.setAttribute(STRUTS_ACTION_MAPPING_KEY, mapping);
+ }
+ } catch (Exception ex) {
+ dispatcher.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
+ }
+ }
+
+ return mapping;
+ }
+
+ /**
+ * Cleans up the dispatcher instance
+ */
+ public void cleanupDispatcher() {
+ if (dispatcher == null) {
+ throw new StrutsException("Something is seriously wrong, Dispatcher is not initialized (null) ");
+ } else {
+ try {
+ dispatcher.cleanup();
+ } finally {
+ ActionContext.setContext(null);
+ }
+ }
+ }
+
+ /**
+ * Check whether the request matches a list of exclude patterns.
+ *
+ * @param request The request to check patterns against
+ * @param excludedPatterns list of patterns for exclusion
+ *
+ * @return <tt>true</tt> if the request URI matches one of the given patterns
+ */
+ public boolean isUrlExcluded( HttpServletRequest request, List<Pattern> excludedPatterns ) {
+ if (excludedPatterns != null) {
+ String uri = RequestUtils.getUri(request);
+ for ( Pattern pattern : excludedPatterns ) {
+ if (pattern.matcher(uri).matches()) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Set an override of the static devMode value. Do not set this via a
+ * request parameter or any other unprotected method. Using a signed
+ * cookie is one safe way to turn it on per request.
+ *
+ * @param devMode the override value
+ */
+ public static void overrideDevMode(boolean devMode) {
+ devModeOverride.set(devMode);
+ }
+
+ /**
+ * @return Boolean override value, or null if no override
+ */
+ public static Boolean getDevModeOverride()
+ {
+ return devModeOverride.get();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java b/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
index f323128..5b6d294 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/StaticContentLoader.java
@@ -20,8 +20,6 @@
*/
package org.apache.struts2.dispatcher;
-import org.apache.struts2.dispatcher.ng.HostConfig;
-
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@@ -60,4 +58,4 @@ public interface StaticContentLoader {
public abstract void findStaticResource(String path, HttpServletRequest request, HttpServletResponse response)
throws IOException;
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/filter/FilterHostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/FilterHostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/FilterHostConfig.java
new file mode 100644
index 0000000..6df1761
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/FilterHostConfig.java
@@ -0,0 +1,52 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher.filter;
+
+import org.apache.struts2.util.MakeIterator;
+
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletContext;
+import java.util.Iterator;
+
+import org.apache.struts2.dispatcher.HostConfig;
+
+/**
+ * Host configuration that wraps FilterConfig
+ */
+public class FilterHostConfig implements HostConfig {
+
+ private FilterConfig config;
+
+ public FilterHostConfig(FilterConfig config) {
+ this.config = config;
+ }
+ public String getInitParameter(String key) {
+ return config.getInitParameter(key);
+ }
+
+ public Iterator<String> getInitParameterNames() {
+ return MakeIterator.convert(config.getInitParameterNames());
+ }
+
+ public ServletContext getServletContext() {
+ return config.getServletContext();
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
new file mode 100644
index 0000000..8ab98e6
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsExecuteFilter.java
@@ -0,0 +1,102 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher.filter;
+
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.ExecuteOperations;
+import org.apache.struts2.dispatcher.InitOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+
+/**
+ * Executes the discovered request information. This filter requires the {@link StrutsPrepareFilter} to have already
+ * been executed in the current chain.
+ */
+public class StrutsExecuteFilter implements StrutsStatics, Filter {
+ protected PrepareOperations prepare;
+ protected ExecuteOperations execute;
+
+ protected FilterConfig filterConfig;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ this.filterConfig = filterConfig;
+ }
+
+ protected synchronized void lazyInit() {
+ if (execute == null) {
+ InitOperations init = new InitOperations();
+ Dispatcher dispatcher = init.findDispatcherOnThread();
+ init.initStaticContentLoader(new FilterHostConfig(filterConfig), dispatcher);
+
+ prepare = new PrepareOperations(dispatcher);
+ execute = new ExecuteOperations(dispatcher);
+ }
+
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
+
+ HttpServletRequest request = (HttpServletRequest) req;
+ HttpServletResponse response = (HttpServletResponse) res;
+
+ if (excludeUrl(request)) {
+ chain.doFilter(request, response);
+ return;
+ }
+
+ // This is necessary since we need the dispatcher instance, which was created by the prepare filter
+ if (execute == null) {
+ lazyInit();
+ }
+
+ ActionMapping mapping = prepare.findActionMapping(request, response);
+
+ //if recursion counter is > 1, it means we are in a "forward", in that case a mapping will still be
+ //in the request, if we handle it, it will lead to an infinite loop, see WW-3077
+ Integer recursionCounter = (Integer) request.getAttribute(PrepareOperations.CLEANUP_RECURSION_COUNTER);
+
+ if (mapping == null || recursionCounter > 1) {
+ boolean handled = execute.executeStaticResourceRequest(request, response);
+ if (!handled) {
+ chain.doFilter(request, response);
+ }
+ } else {
+ execute.executeAction(request, response, mapping);
+ }
+ }
+
+ private boolean excludeUrl(HttpServletRequest request) {
+ return request.getAttribute(StrutsPrepareFilter.REQUEST_EXCLUDED_FROM_ACTION_MAPPING) != null;
+ }
+
+ public void destroy() {
+ prepare = null;
+ execute = null;
+ filterConfig = null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java
new file mode 100644
index 0000000..c728e19
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareAndExecuteFilter.java
@@ -0,0 +1,111 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher.filter;
+
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.dispatcher.ExecuteOperations;
+import org.apache.struts2.dispatcher.InitOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * Handles both the preparation and execution phases of the Struts dispatching process. This filter is better to use
+ * when you don't have another filter that needs access to action context information, such as Sitemesh.
+ */
+public class StrutsPrepareAndExecuteFilter implements StrutsStatics, Filter {
+ protected PrepareOperations prepare;
+ protected ExecuteOperations execute;
+ protected List<Pattern> excludedPatterns = null;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ InitOperations init = new InitOperations();
+ Dispatcher dispatcher = null;
+ try {
+ FilterHostConfig config = new FilterHostConfig(filterConfig);
+ init.initLogging(config);
+ dispatcher = init.initDispatcher(config);
+ init.initStaticContentLoader(config, dispatcher);
+
+ prepare = new PrepareOperations(dispatcher);
+ execute = new ExecuteOperations(dispatcher);
+ this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);
+
+ postInit(dispatcher, filterConfig);
+ } finally {
+ if (dispatcher != null) {
+ dispatcher.cleanUpAfterInit();
+ }
+ init.cleanup();
+ }
+ }
+
+ /**
+ * Callback for post initialization
+ */
+ protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
+
+ HttpServletRequest request = (HttpServletRequest) req;
+ HttpServletResponse response = (HttpServletResponse) res;
+
+ try {
+ if (excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
+ chain.doFilter(request, response);
+ } else {
+ prepare.setEncodingAndLocale(request, response);
+ prepare.createActionContext(request, response);
+ prepare.assignDispatcherToThread();
+ request = prepare.wrapRequest(request);
+ ActionMapping mapping = prepare.findActionMapping(request, response, true);
+ if (mapping == null) {
+ boolean handled = execute.executeStaticResourceRequest(request, response);
+ if (!handled) {
+ chain.doFilter(request, response);
+ }
+ } else {
+ execute.executeAction(request, response, mapping);
+ }
+ }
+ } finally {
+ prepare.cleanupRequest(request);
+ }
+ }
+
+ public void destroy() {
+ prepare.cleanupDispatcher();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
new file mode 100644
index 0000000..8331c6a
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/filter/StrutsPrepareFilter.java
@@ -0,0 +1,101 @@
+/*
+ * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
+ *
+ * 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.struts2.dispatcher.filter;
+
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.InitOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * Prepares the request for execution by a later {@link org.apache.struts2.dispatcher.filter.StrutsExecuteFilter} filter instance.
+ */
+public class StrutsPrepareFilter implements StrutsStatics, Filter {
+
+ protected static final String REQUEST_EXCLUDED_FROM_ACTION_MAPPING = StrutsPrepareFilter.class.getName() + ".REQUEST_EXCLUDED_FROM_ACTION_MAPPING";
+
+ protected PrepareOperations prepare;
+ protected List<Pattern> excludedPatterns = null;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ InitOperations init = new InitOperations();
+ Dispatcher dispatcher = null;
+ try {
+ FilterHostConfig config = new FilterHostConfig(filterConfig);
+ init.initLogging(config);
+ dispatcher = init.initDispatcher(config);
+
+ prepare = new PrepareOperations(dispatcher);
+ this.excludedPatterns = init.buildExcludedPatternsList(dispatcher);
+
+ postInit(dispatcher, filterConfig);
+ } finally {
+ if (dispatcher != null) {
+ dispatcher.cleanUpAfterInit();
+ }
+ init.cleanup();
+ }
+ }
+
+ /**
+ * Callback for post initialization
+ */
+ protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
+
+ HttpServletRequest request = (HttpServletRequest) req;
+ HttpServletResponse response = (HttpServletResponse) res;
+
+ try {
+ if (excludedPatterns != null && prepare.isUrlExcluded(request, excludedPatterns)) {
+ request.setAttribute(REQUEST_EXCLUDED_FROM_ACTION_MAPPING, new Object());
+ } else {
+ prepare.setEncodingAndLocale(request, response);
+ prepare.createActionContext(request, response);
+ prepare.assignDispatcherToThread();
+ request = prepare.wrapRequest(request);
+ prepare.findActionMapping(request, response);
+ }
+ chain.doFilter(request, response);
+ } finally {
+ prepare.cleanupRequest(request);
+ }
+ }
+
+ public void destroy() {
+ prepare.cleanupDispatcher();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/listener/ListenerHostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/listener/ListenerHostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/listener/ListenerHostConfig.java
new file mode 100644
index 0000000..13290a5
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/listener/ListenerHostConfig.java
@@ -0,0 +1,50 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.dispatcher.listener;
+
+import org.apache.struts2.dispatcher.HostConfig;
+
+import javax.servlet.ServletContext;
+import java.util.Iterator;
+import java.util.Collections;
+
+/**
+ * Host configuration that just holds a ServletContext
+ */
+public class ListenerHostConfig implements HostConfig {
+ private ServletContext servletContext;
+
+ public ListenerHostConfig(ServletContext servletContext) {
+ this.servletContext = servletContext;
+ }
+
+ public String getInitParameter(String key) {
+ return null;
+ }
+
+ public Iterator<String> getInitParameterNames() {
+ return Collections.<String>emptyList().iterator();
+ }
+
+ public ServletContext getServletContext() {
+ return servletContext;
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java b/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java
new file mode 100644
index 0000000..b009893
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/dispatcher/listener/StrutsListener.java
@@ -0,0 +1,62 @@
+/*
+ * $Id$
+ *
+ * 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.struts2.dispatcher.listener;
+
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.dispatcher.InitOperations;
+import org.apache.struts2.dispatcher.PrepareOperations;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+/**
+ * Servlet listener for Struts. The preferred way to use Struts is as a filter via the
+ * {@link org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter} and its variants.
+ * This might be useful if Struts config information is needed from other servlet listeners, like
+ * Sitemesh or OSGi
+ */
+public class StrutsListener implements ServletContextListener {
+ private PrepareOperations prepare;
+
+ public void contextInitialized(ServletContextEvent sce) {
+ InitOperations init = new InitOperations();
+ Dispatcher dispatcher = null;
+ try {
+ ListenerHostConfig config = new ListenerHostConfig(sce.getServletContext());
+ init.initLogging(config);
+ dispatcher = init.initDispatcher(config);
+ init.initStaticContentLoader(config, dispatcher);
+
+ prepare = new PrepareOperations(dispatcher);
+ sce.getServletContext().setAttribute(StrutsStatics.SERVLET_DISPATCHER, dispatcher);
+ } finally {
+ if (dispatcher != null) {
+ dispatcher.cleanUpAfterInit();
+ }
+ init.cleanup();
+ }
+ }
+
+ public void contextDestroyed(ServletContextEvent sce) {
+ prepare.cleanupDispatcher();
+ }
+}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/ExecuteOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/ExecuteOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/ExecuteOperations.java
deleted file mode 100644
index 1db7cef..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/ExecuteOperations.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng;
-
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.StaticContentLoader;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.RequestUtils;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * Contains execution operations for filters
- */
-public class ExecuteOperations {
-
- private Dispatcher dispatcher;
-
- public ExecuteOperations(Dispatcher dispatcher) {
- this.dispatcher = dispatcher;
- }
-
- /**
- * Tries to execute a request for a static resource
- * @return True if it was handled, false if the filter should fall through
- * @throws IOException
- * @throws ServletException
- */
- public boolean executeStaticResourceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
- // there is no action in this request, should we look for a static resource?
- String resourcePath = RequestUtils.getServletPath(request);
-
- if ("".equals(resourcePath) && null != request.getPathInfo()) {
- resourcePath = request.getPathInfo();
- }
-
- StaticContentLoader staticResourceLoader = dispatcher.getContainer().getInstance(StaticContentLoader.class);
- if (staticResourceLoader.canHandle(resourcePath)) {
- staticResourceLoader.findStaticResource(resourcePath, request, response);
- // The framework did its job here
- return true;
-
- } else {
- // this is a normal request, let it pass through
- return false;
- }
- }
-
- /**
- * Executes an action
- * @throws ServletException
- */
- public void executeAction(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException {
- dispatcher.serviceAction(request, response, mapping);
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/HostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/HostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/HostConfig.java
deleted file mode 100644
index 9ac9e25..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/HostConfig.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng;
-
-import javax.servlet.ServletContext;
-import java.util.Iterator;
-
-/**
- * Abstraction for host configuration information such as init params or the servlet context.
- */
-public interface HostConfig {
-
- /**
- * @param key The parameter key
- * @return The parameter value
- */
- String getInitParameter(String key);
-
- /**
- * @return A list of parameter names
- */
- Iterator<String> getInitParameterNames();
-
- /**
- * @return The servlet context
- */
- ServletContext getServletContext();
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/InitOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/InitOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/InitOperations.java
deleted file mode 100644
index d913b71..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/InitOperations.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.util.ClassLoaderUtil;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-import org.apache.struts2.StrutsConstants;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.StaticContentLoader;
-
-import java.util.*;
-import java.util.regex.Pattern;
-
-/**
- * Contains initialization operations
- */
-public class InitOperations {
-
- public InitOperations() {
- }
-
- /**
- * Initializes the internal Struts logging
- *
- * @deprecated since 2.5
- */
- @Deprecated
- public void initLogging( HostConfig filterConfig ) {
- String factoryName = filterConfig.getInitParameter("loggerFactory");
- if (factoryName != null) {
- try {
- Class cls = ClassLoaderUtil.loadClass(factoryName, this.getClass());
- LoggerFactory fac = (LoggerFactory) cls.newInstance();
- LoggerFactory.setLoggerFactory(fac);
- } catch ( InstantiationException e ) {
- System.err.println("Unable to instantiate logger factory: " + factoryName + ", using default");
- e.printStackTrace();
- } catch ( IllegalAccessException e ) {
- System.err.println("Unable to access logger factory: " + factoryName + ", using default");
- e.printStackTrace();
- } catch ( ClassNotFoundException e ) {
- System.err.println("Unable to locate logger factory class: " + factoryName + ", using default");
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Creates and initializes the dispatcher
- */
- public Dispatcher initDispatcher( HostConfig filterConfig ) {
- Dispatcher dispatcher = createDispatcher(filterConfig);
- dispatcher.init();
- return dispatcher;
- }
-
- /**
- * Initializes the static content loader with the filter configuration
- */
- public StaticContentLoader initStaticContentLoader( HostConfig filterConfig, Dispatcher dispatcher ) {
- StaticContentLoader loader = dispatcher.getContainer().getInstance(StaticContentLoader.class);
- loader.setHostConfig(filterConfig);
- return loader;
- }
-
- /**
- * @return The dispatcher on the thread.
- *
- * @throws IllegalStateException If there is no dispatcher available
- */
- public Dispatcher findDispatcherOnThread() {
- Dispatcher dispatcher = Dispatcher.getInstance();
- if (dispatcher == null) {
- throw new IllegalStateException("Must have the StrutsPrepareFilter execute before this one");
- }
- return dispatcher;
- }
-
- /**
- * Create a {@link Dispatcher}
- */
- private Dispatcher createDispatcher( HostConfig filterConfig ) {
- Map<String, String> params = new HashMap<>();
- for ( Iterator e = filterConfig.getInitParameterNames(); e.hasNext(); ) {
- String name = (String) e.next();
- String value = filterConfig.getInitParameter(name);
- params.put(name, value);
- }
- return new Dispatcher(filterConfig.getServletContext(), params);
- }
-
- public void cleanup() {
- ActionContext.setContext(null);
- }
-
- /**
- * Extract a list of patterns to exclude from request filtering
- *
- * @param dispatcher The dispatcher to check for exclude pattern configuration
- *
- * @return a List of Patterns for request to exclude if apply, or <tt>null</tt>
- *
- * @see org.apache.struts2.StrutsConstants#STRUTS_ACTION_EXCLUDE_PATTERN
- */
- public List<Pattern> buildExcludedPatternsList( Dispatcher dispatcher ) {
- return buildExcludedPatternsList(dispatcher.getContainer().getInstance(String.class, StrutsConstants.STRUTS_ACTION_EXCLUDE_PATTERN));
- }
-
- private List<Pattern> buildExcludedPatternsList( String patterns ) {
- if (null != patterns && patterns.trim().length() != 0) {
- List<Pattern> list = new ArrayList<>();
- String[] tokens = patterns.split(",");
- for ( String token : tokens ) {
- list.add(Pattern.compile(token.trim()));
- }
- return Collections.unmodifiableList(list);
- } else {
- return null;
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java
deleted file mode 100644
index a8cf930..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/PrepareOperations.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng;
-
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.apache.struts2.RequestUtils;
-import org.apache.struts2.StrutsException;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.mapper.ActionMapper;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.regex.Pattern;
-
-/**
- * Contains preparation operations for a request before execution
- */
-public class PrepareOperations {
-
- private static final Logger LOG = LogManager.getLogger(PrepareOperations.class);
-
- /**
- * Maintains per-request override of devMode configuration.
- */
- private static ThreadLocal<Boolean> devModeOverride = new InheritableThreadLocal<>();
-
-
- private Dispatcher dispatcher;
- private static final String STRUTS_ACTION_MAPPING_KEY = "struts.actionMapping";
- public static final String CLEANUP_RECURSION_COUNTER = "__cleanup_recursion_counter";
-
- public PrepareOperations(Dispatcher dispatcher) {
- this.dispatcher = dispatcher;
- }
-
- /**
- * Creates the action context and initializes the thread local
- */
- public ActionContext createActionContext(HttpServletRequest request, HttpServletResponse response) {
- ActionContext ctx;
- Integer counter = 1;
- Integer oldCounter = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
- if (oldCounter != null) {
- counter = oldCounter + 1;
- }
-
- ActionContext oldContext = ActionContext.getContext();
- if (oldContext != null) {
- // detected existing context, so we are probably in a forward
- ctx = new ActionContext(new HashMap<>(oldContext.getContextMap()));
- } else {
- ValueStack stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack();
- stack.getContext().putAll(dispatcher.createContextMap(request, response, null));
- ctx = new ActionContext(stack.getContext());
- }
- request.setAttribute(CLEANUP_RECURSION_COUNTER, counter);
- ActionContext.setContext(ctx);
- return ctx;
- }
-
- /**
- * Cleans up a request of thread locals
- */
- public void cleanupRequest(HttpServletRequest request) {
- Integer counterVal = (Integer) request.getAttribute(CLEANUP_RECURSION_COUNTER);
- if (counterVal != null) {
- counterVal -= 1;
- request.setAttribute(CLEANUP_RECURSION_COUNTER, counterVal);
- if (counterVal > 0 ) {
- LOG.debug("skipping cleanup counter={}", counterVal);
- return;
- }
- }
- // always clean up the thread request, even if an action hasn't been executed
- try {
- dispatcher.cleanUpRequest(request);
- } finally {
- ActionContext.setContext(null);
- Dispatcher.setInstance(null);
- devModeOverride.remove();
- }
- }
-
- /**
- * Assigns the dispatcher to the dispatcher thread local
- */
- public void assignDispatcherToThread() {
- Dispatcher.setInstance(dispatcher);
- }
-
- /**
- * Sets the request encoding and locale on the response
- */
- public void setEncodingAndLocale(HttpServletRequest request, HttpServletResponse response) {
- dispatcher.prepare(request, response);
- }
-
- /**
- * Wraps the request with the Struts wrapper that handles multipart requests better
- * @return The new request, if there is one
- * @throws ServletException
- */
- public HttpServletRequest wrapRequest(HttpServletRequest oldRequest) throws ServletException {
- HttpServletRequest request = oldRequest;
- try {
- // Wrap request first, just in case it is multipart/form-data
- // parameters might not be accessible through before encoding (ww-1278)
- request = dispatcher.wrapRequest(request);
- } catch (IOException e) {
- throw new ServletException("Could not wrap servlet request with MultipartRequestWrapper!", e);
- }
- return request;
- }
-
- /**
- * Finds and optionally creates an {@link ActionMapping}. It first looks in the current request to see if one
- * has already been found, otherwise, it creates it and stores it in the request. No mapping will be created in the
- * case of static resource requests or unidentifiable requests for other servlets, for example.
- */
- public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response) {
- return findActionMapping(request, response, false);
- }
-
- /**
- * Finds and optionally creates an {@link ActionMapping}. if forceLookup is false, it first looks in the current request to see if one
- * has already been found, otherwise, it creates it and stores it in the request. No mapping will be created in the
- * case of static resource requests or unidentifiable requests for other servlets, for example.
- * @param forceLookup if true, the action mapping will be looked up from the ActionMapper instance, ignoring if there is one
- * in the request or not
- */
- public ActionMapping findActionMapping(HttpServletRequest request, HttpServletResponse response, boolean forceLookup) {
- ActionMapping mapping = (ActionMapping) request.getAttribute(STRUTS_ACTION_MAPPING_KEY);
- if (mapping == null || forceLookup) {
- try {
- mapping = dispatcher.getContainer().getInstance(ActionMapper.class).getMapping(request, dispatcher.getConfigurationManager());
- if (mapping != null) {
- request.setAttribute(STRUTS_ACTION_MAPPING_KEY, mapping);
- }
- } catch (Exception ex) {
- dispatcher.sendError(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex);
- }
- }
-
- return mapping;
- }
-
- /**
- * Cleans up the dispatcher instance
- */
- public void cleanupDispatcher() {
- if (dispatcher == null) {
- throw new StrutsException("Something is seriously wrong, Dispatcher is not initialized (null) ");
- } else {
- try {
- dispatcher.cleanup();
- } finally {
- ActionContext.setContext(null);
- }
- }
- }
-
- /**
- * Check whether the request matches a list of exclude patterns.
- *
- * @param request The request to check patterns against
- * @param excludedPatterns list of patterns for exclusion
- *
- * @return <tt>true</tt> if the request URI matches one of the given patterns
- */
- public boolean isUrlExcluded( HttpServletRequest request, List<Pattern> excludedPatterns ) {
- if (excludedPatterns != null) {
- String uri = RequestUtils.getUri(request);
- for ( Pattern pattern : excludedPatterns ) {
- if (pattern.matcher(uri).matches()) {
- return true;
- }
- }
- }
- return false;
- }
-
- /**
- * Set an override of the static devMode value. Do not set this via a
- * request parameter or any other unprotected method. Using a signed
- * cookie is one safe way to turn it on per request.
- *
- * @param devMode the override value
- */
- public static void overrideDevMode(boolean devMode) {
- devModeOverride.set(devMode);
- }
-
- /**
- * @return Boolean override value, or null if no override
- */
- public static Boolean getDevModeOverride()
- {
- return devModeOverride.get();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/FilterHostConfig.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/FilterHostConfig.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/FilterHostConfig.java
deleted file mode 100644
index 67f9d0b..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/FilterHostConfig.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng.filter;
-
-import org.apache.struts2.util.MakeIterator;
-
-import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
-import java.util.Iterator;
-
-import org.apache.struts2.dispatcher.ng.HostConfig;
-
-/**
- * Host configuration that wraps FilterConfig
- */
-public class FilterHostConfig implements HostConfig {
-
- private FilterConfig config;
-
- public FilterHostConfig(FilterConfig config) {
- this.config = config;
- }
- public String getInitParameter(String key) {
- return config.getInitParameter(key);
- }
-
- public Iterator<String> getInitParameterNames() {
- return MakeIterator.convert(config.getInitParameterNames());
- }
-
- public ServletContext getServletContext() {
- return config.getServletContext();
- }
-}
http://git-wip-us.apache.org/repos/asf/struts/blob/fd0db865/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsExecuteFilter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsExecuteFilter.java b/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsExecuteFilter.java
deleted file mode 100644
index d2e23c9..0000000
--- a/core/src/main/java/org/apache/struts2/dispatcher/ng/filter/StrutsExecuteFilter.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * $Id: DefaultActionSupport.java 651946 2008-04-27 13:41:38Z apetrelli $
- *
- * 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.struts2.dispatcher.ng.filter;
-
-import org.apache.struts2.StrutsStatics;
-import org.apache.struts2.dispatcher.Dispatcher;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.dispatcher.ng.ExecuteOperations;
-import org.apache.struts2.dispatcher.ng.InitOperations;
-import org.apache.struts2.dispatcher.ng.PrepareOperations;
-
-import javax.servlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * Executes the discovered request information. This filter requires the {@link StrutsPrepareFilter} to have already
- * been executed in the current chain.
- */
-public class StrutsExecuteFilter implements StrutsStatics, Filter {
- protected PrepareOperations prepare;
- protected ExecuteOperations execute;
-
- protected FilterConfig filterConfig;
-
- public void init(FilterConfig filterConfig) throws ServletException {
- this.filterConfig = filterConfig;
- }
-
- protected synchronized void lazyInit() {
- if (execute == null) {
- InitOperations init = new InitOperations();
- Dispatcher dispatcher = init.findDispatcherOnThread();
- init.initStaticContentLoader(new FilterHostConfig(filterConfig), dispatcher);
-
- prepare = new PrepareOperations(dispatcher);
- execute = new ExecuteOperations(dispatcher);
- }
-
- }
-
- public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
-
- HttpServletRequest request = (HttpServletRequest) req;
- HttpServletResponse response = (HttpServletResponse) res;
-
- if (excludeUrl(request)) {
- chain.doFilter(request, response);
- return;
- }
-
- // This is necessary since we need the dispatcher instance, which was created by the prepare filter
- if (execute == null) {
- lazyInit();
- }
-
- ActionMapping mapping = prepare.findActionMapping(request, response);
-
- //if recursion counter is > 1, it means we are in a "forward", in that case a mapping will still be
- //in the request, if we handle it, it will lead to an infinite loop, see WW-3077
- Integer recursionCounter = (Integer) request.getAttribute(PrepareOperations.CLEANUP_RECURSION_COUNTER);
-
- if (mapping == null || recursionCounter > 1) {
- boolean handled = execute.executeStaticResourceRequest(request, response);
- if (!handled) {
- chain.doFilter(request, response);
- }
- } else {
- execute.executeAction(request, response, mapping);
- }
- }
-
- private boolean excludeUrl(HttpServletRequest request) {
- return request.getAttribute(StrutsPrepareFilter.REQUEST_EXCLUDED_FROM_ACTION_MAPPING) != null;
- }
-
- public void destroy() {
- prepare = null;
- execute = null;
- filterConfig = null;
- }
-
-}