1
1
/*
2
2
Copyright 2009-2014 Igor Polevoy
3
3
4
- Licensed under the Apache License, Version 2.0 (the "License");
5
- you may not use this file except in compliance with the License.
6
- You may obtain a copy of the License at
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
7
8
- http://www.apache.org/licenses/LICENSE-2.0
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
9
10
- Unless required by applicable law or agreed to in writing, software
11
- distributed under the License is distributed on an "AS IS" BASIS,
12
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- See the License for the specific language governing permissions and
14
- limitations under the License.
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
15
*/
16
16
package org .javalite .activeweb ;
17
17
33
33
34
34
/**
35
35
* One of the main classes of the framework, responsible for execution of controllers and filters.
36
- *
36
+ *
37
37
* @author Igor Polevoy
38
38
*/
39
39
class ControllerRunner {
@@ -193,6 +193,9 @@ private void processFlash() {
193
193
}
194
194
}
195
195
196
+ /**
197
+ * Checks if the action method supports requested HTTP method
198
+ */
196
199
private boolean checkActionMethod (AppController controller , String actionMethod ) {
197
200
HttpMethod method = HttpMethod .getMethod (Context .getHttpRequest ());
198
201
if (!controller .actionSupportsHttpMethod (actionMethod , method )) {
@@ -201,6 +204,8 @@ private boolean checkActionMethod(AppController controller, String actionMethod)
201
204
res .setStatus (405 );
202
205
logger .warn ("Requested action does not support HTTP method: " + method .name () + ", returning status code 405." );
203
206
Context .setControllerResponse (res );
207
+
208
+ //TODO: candidate for caching below, list of allowed HTTP methods
204
209
//see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
205
210
Context .getHttpResponse ().setHeader ("Allow" , join (controller .allowedActions (actionMethod ), ", " ));
206
211
return false ;
@@ -287,10 +292,14 @@ private void filterAfter(Route route, List<ControllerRegistry.FilterList> global
287
292
private void executeAction (Object controller , String actionName ) {
288
293
try {
289
294
Method m = controller .getClass ().getMethod (actionName );
295
+ Class c = m .getDeclaringClass ();
296
+ if (!AppController .class .isAssignableFrom (m .getDeclaringClass ())){ // see https://github.com/javalite/activeweb/issues/272
297
+ throw new ActionNotFoundException ("Cannot execute action '" + actionName + "' on controller: " + controller );
298
+ }
290
299
m .invoke (controller );
291
300
}catch (InvocationTargetException e ){
292
301
if (e .getCause () != null && e .getCause () instanceof WebException ){
293
- throw (WebException )e .getCause ();
302
+ throw (WebException )e .getCause ();
294
303
}else if (e .getCause () != null && e .getCause () instanceof RuntimeException ){
295
304
throw (RuntimeException )e .getCause ();
296
305
}else if (e .getCause () != null ){
0 commit comments