20
20
import io .netty .channel .ChannelHandlerContext ;
21
21
import io .netty .handler .codec .http .FullHttpRequest ;
22
22
import io .netty .handler .codec .http .FullHttpResponse ;
23
- import java .lang .reflect .Method ;
24
- import java .util .HashMap ;
25
- import java .util .Locale ;
26
- import java .util .Map ;
27
23
import net .jrouter .ActionFactory ;
28
24
import net .jrouter .ActionInvocation ;
29
25
import net .jrouter .JRouterException ;
32
28
import net .jrouter .impl .PathActionFactory ;
33
29
import net .jrouter .support .ActionInvocationDelegate ;
34
30
31
+ import java .lang .reflect .Method ;
32
+ import java .util .HashMap ;
33
+ import java .util .Locale ;
34
+ import java .util .Map ;
35
+
35
36
/**
36
37
* {@code HttpServerActionFactory} invoke Action with Http parameters.
37
38
*/
38
39
public interface HttpServerActionFactory extends ActionFactory <String > {
39
40
40
41
/**
41
- * Use this instead of {@link #invokeAction(Object, Object...)} to pass Http parameters.
42
- *
42
+ * Use this instead of {@link #invokeAction(Object, Object...)} to pass Http
43
+ * parameters.
43
44
* @param <T> Generic type.
44
45
* @param path Action path.
45
46
* @param request FullHttpRequest.
46
47
* @param response FullHttpResponse.
47
48
* @param context ChannelHandlerContext.
48
- *
49
49
* @return Action invoked result.
50
- *
51
- * @throws JRouterException if error occurrs.
50
+ * @throws JRouterException if error occurs.
52
51
* @see #invokeAction(Object, Object...)
53
52
*/
54
53
<T > T invokeAction (String path , FullHttpRequest request , FullHttpResponse response , ChannelHandlerContext context )
@@ -57,7 +56,7 @@ <T> T invokeAction(String path, FullHttpRequest request, FullHttpResponse respon
57
56
/**
58
57
* 提供{@code ServletActionFactory}接口默认实现。覆写{@link #createActionInvocation}方法创建{@code HttpServerActionFactory}接口对象。
59
58
*
60
- * @see #createActionInvocation(java.lang.String, java.lang.Object...)
59
+ * @see #createActionInvocation
61
60
*/
62
61
class DefaultHttpActionFactory extends PathActionFactory implements HttpServerActionFactory {
63
62
@@ -69,7 +68,6 @@ class DefaultHttpActionFactory extends PathActionFactory implements HttpServerAc
69
68
70
69
/**
71
70
* Constructor.
72
- *
73
71
* @param properties Properties
74
72
*/
75
73
public DefaultHttpActionFactory (Properties properties ) {
@@ -79,15 +77,14 @@ public DefaultHttpActionFactory(Properties properties) {
79
77
80
78
@ Override
81
79
public <T > T invokeAction (String path , FullHttpRequest request , FullHttpResponse response ,
82
- ChannelHandlerContext sc ) throws JRouterException {
80
+ ChannelHandlerContext sc ) throws JRouterException {
83
81
// invoke and pass http parameters
84
82
return (T ) super .invokeAction (actionPathCaseSensitive ? path : path .toLowerCase (Locale .getDefault ()),
85
83
request , response , sc );
86
84
}
87
85
88
86
/**
89
87
* 创建并返回{@link ChannelHandlerContext}接口对象。
90
- *
91
88
* @return {@link ChannelHandlerContext}接口对象。
92
89
*/
93
90
@ Override
@@ -98,12 +95,8 @@ protected ActionInvocation<String> createActionInvocation(String path, Object...
98
95
99
96
// 优先从invokeAction参数中获取Http参数对象,已由invokeAction方法指定参数顺序
100
97
if (checkHttpParameters (params )) {
101
- httpInvocation = new DefaultHttpActionInvocation (invocation ,
102
- (FullHttpRequest ) params [0 ],
103
- (FullHttpResponse ) params [1 ],
104
- (ChannelHandlerContext ) params [2 ],
105
- new HashMap <>(4 )
106
- );
98
+ httpInvocation = new DefaultHttpActionInvocation (invocation , (FullHttpRequest ) params [0 ],
99
+ (FullHttpResponse ) params [1 ], (ChannelHandlerContext ) params [2 ], new HashMap <>(4 ));
107
100
return httpInvocation ;
108
101
}
109
102
// return ActionInvocation if can't get any http parameters
@@ -112,18 +105,15 @@ protected ActionInvocation<String> createActionInvocation(String path, Object...
112
105
113
106
/**
114
107
* 检测{@link #invokeAction}方法传递过来参数的正确性。
115
- *
116
108
* @param params 由{@link #invokeAction}方法传递过来参数。
117
- *
118
109
* @return 参数是否为正确的Http参数对象。
119
110
*
120
- * @see #invokeAction(String, FullHttpRequest, FullHttpResponse, ChannelHandlerContext)
111
+ * @see #invokeAction(String, FullHttpRequest,
112
+ * FullHttpResponse,ChannelHandlerContext)
121
113
*/
122
114
private boolean checkHttpParameters (Object ... params ) {
123
- return params != null && params .length == 3
124
- && (params [0 ] instanceof FullHttpRequest )
125
- && (params [1 ] instanceof FullHttpResponse )
126
- && (params [2 ] instanceof ChannelHandlerContext );
115
+ return params != null && params .length == 3 && (params [0 ] instanceof FullHttpRequest )
116
+ && (params [1 ] instanceof FullHttpResponse ) && (params [2 ] instanceof ChannelHandlerContext );
127
117
}
128
118
129
119
/**
@@ -153,7 +143,9 @@ protected String buildActionPath(String namespace, String aname, Method method)
153
143
}
154
144
super .afterPropertiesSet ();
155
145
}
146
+
156
147
}
148
+
157
149
}
158
150
159
151
/**
@@ -182,8 +174,10 @@ class DefaultHttpActionInvocation extends ActionInvocationDelegate<String> imple
182
174
*/
183
175
private final Map <String , Object > contextMap ;
184
176
185
- public DefaultHttpActionInvocation (ActionInvocation <String > invocation , FullHttpRequest request , //NOPMD ExcessiveParameterList
186
- FullHttpResponse response , ChannelHandlerContext channelHandlerContext , Map <String , Object > contextMap ) {
177
+ public DefaultHttpActionInvocation (ActionInvocation <String > invocation , FullHttpRequest request , // NOPMD
178
+ // ExcessiveParameterList
179
+ FullHttpResponse response , ChannelHandlerContext channelHandlerContext ,
180
+ Map <String , Object > contextMap ) {
187
181
super ();
188
182
this .delegate = invocation ;
189
183
this .request = request ;
@@ -212,6 +206,7 @@ public ChannelHandlerContext getChannelHandlerContext() {
212
206
public Map <String , Object > getContextMap () {
213
207
return contextMap ;
214
208
}
209
+
215
210
}
216
211
217
212
}
0 commit comments