1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.dispatcher.ng;
22
23 import org.apache.struts2.dispatcher.Dispatcher;
24 import org.apache.struts2.dispatcher.StaticContentLoader;
25 import org.apache.struts2.dispatcher.mapper.ActionMapping;
26 import org.apache.struts2.RequestUtils;
27
28 import javax.servlet.ServletContext;
29 import javax.servlet.ServletException;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import java.io.IOException;
33
34 /***
35 * Contains execution operations for filters
36 */
37 public class ExecuteOperations {
38 private ServletContext servletContext;
39 private Dispatcher dispatcher;
40
41 public ExecuteOperations(ServletContext servletContext, Dispatcher dispatcher) {
42 this.dispatcher = dispatcher;
43 this.servletContext = servletContext;
44 }
45
46 /***
47 * Tries to execute a request for a static resource
48 * @return True if it was handled, false if the filter should fall through
49 * @throws IOException
50 * @throws ServletException
51 */
52 public boolean executeStaticResourceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
53
54 String resourcePath = RequestUtils.getServletPath(request);
55
56 if ("".equals(resourcePath) && null != request.getPathInfo()) {
57 resourcePath = request.getPathInfo();
58 }
59
60 StaticContentLoader staticResourceLoader = dispatcher.getContainer().getInstance(StaticContentLoader.class);
61 if (staticResourceLoader.canHandle(resourcePath)) {
62 staticResourceLoader.findStaticResource(resourcePath, request, response);
63
64 return true;
65
66 } else {
67
68 return false;
69 }
70 }
71
72 /***
73 * Executes an action
74 * @throws ServletException
75 */
76 public void executeAction(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws ServletException {
77 dispatcher.serviceAction(request, response, servletContext, mapping);
78 }
79 }