1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.controller.impl; |
17 | |
|
18 | |
import javax.servlet.FilterChain; |
19 | |
import javax.servlet.http.HttpServletRequest; |
20 | |
import javax.servlet.http.HttpServletResponse; |
21 | |
|
22 | |
import org.seasar.cubby.action.ActionResult; |
23 | |
import org.seasar.cubby.controller.ActionContext; |
24 | |
import org.seasar.cubby.controller.ActionDef; |
25 | |
import org.seasar.cubby.controller.ActionDefBuilder; |
26 | |
import org.seasar.cubby.controller.ActionProcessor; |
27 | |
import org.seasar.cubby.exception.ActionRuntimeException; |
28 | |
import org.seasar.cubby.filter.CubbyHttpServletRequestWrapper; |
29 | |
import org.seasar.framework.log.Logger; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 3 | public class ActionProcessorImpl implements ActionProcessor { |
38 | |
|
39 | |
|
40 | 1 | private static final Logger logger = Logger |
41 | |
.getLogger(ActionProcessorImpl.class); |
42 | |
|
43 | |
|
44 | |
private ActionContext context; |
45 | |
|
46 | |
|
47 | |
private ActionDefBuilder actionDefBuilder; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
public void setActionContext(final ActionContext context) { |
56 | 1 | this.context = context; |
57 | 1 | } |
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
public void setActionDefBuilder(final ActionDefBuilder actionDefBuilder) { |
66 | 1 | this.actionDefBuilder = actionDefBuilder; |
67 | 1 | } |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
public ActionResult process(final HttpServletRequest request, |
73 | |
final HttpServletResponse response, final FilterChain chain) |
74 | |
throws Exception { |
75 | 0 | final ActionDef actionDef = actionDefBuilder.build(request); |
76 | 0 | if (actionDef != null) { |
77 | 0 | context.initialize(actionDef); |
78 | 0 | if (logger.isDebugEnabled()) { |
79 | 0 | logger |
80 | |
.log("DCUB0004", |
81 | |
new Object[] { request.getRequestURI() }); |
82 | 0 | logger.log("DCUB0005", new Object[] { context.getMethod() }); |
83 | |
} |
84 | 0 | final ActionResult result = context.invoke(); |
85 | 0 | if (result == null) { |
86 | 0 | throw new ActionRuntimeException("ECUB0101", |
87 | |
new Object[] { context.getMethod() }); |
88 | |
} |
89 | 0 | final HttpServletRequest wrappedRequest = new CubbyHttpServletRequestWrapper( |
90 | |
request, context); |
91 | 0 | result.execute(context, wrappedRequest, response); |
92 | 0 | return result; |
93 | |
} else { |
94 | 0 | final HttpServletRequest wrappedRequest = new CubbyHttpServletRequestWrapper( |
95 | |
request, context); |
96 | 0 | chain.doFilter(wrappedRequest, response); |
97 | 0 | return null; |
98 | |
} |
99 | |
} |
100 | |
|
101 | |
} |