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;
