Skip to content

Commit 97da71d

Browse files
author
Igor Polevoy
committed
#193 Adding a non-ActiveWeb annotation on action method causes IllegalArgumentException
1 parent e87ad71 commit 97da71d

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

activeweb/src/main/java/org/javalite/activeweb/AppController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,11 @@ protected List<HttpMethod> allowedActions(String actionMethodName) {
198198
if (annotations.length == 0) {
199199
return Collections.singletonList(HttpMethod.GET);
200200
} else {
201-
List<HttpMethod> res = new ArrayList<HttpMethod>();
201+
List<HttpMethod> res = new ArrayList<>();
202202
for (Annotation annotation : annotations) {
203-
res.add(HttpMethod.valueOf(annotation.annotationType().getSimpleName()));
203+
try {
204+
res.add(HttpMethod.valueOf(annotation.annotationType().getSimpleName()));
205+
} catch (IllegalArgumentException ignore) {} // we do not know this annotation
204206
}
205207
return res;
206208
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package app.controllers;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* @author Igor Polevoy on 12/10/15.
10+
*/
11+
@Retention(RetentionPolicy.RUNTIME)
12+
@Target(ElementType.METHOD)
13+
public @interface BlahAnnotation {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package app.controllers;
2+
3+
import org.javalite.activeweb.AppController;
4+
import org.javalite.activeweb.annotations.GET;
5+
6+
/**
7+
* @author Igor Polevoy on 12/10/15.
8+
*/
9+
public class Issue193Controller extends AppController {
10+
11+
@GET @BlahAnnotation
12+
public void index(){
13+
respond("ok");
14+
}
15+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.javalite.activeweb;
2+
3+
import org.junit.Test;
4+
5+
import javax.servlet.ServletException;
6+
import java.io.IOException;
7+
8+
/**
9+
* @author Igor Polevoy on 12/10/15.
10+
*/
11+
public class Issue193Spec extends RequestSpec{
12+
13+
@Test //https://github.com/javalite/activeweb/issues/244
14+
public void shouldSanitizeBadContent() throws IOException, ServletException {
15+
request.setServletPath("/issue193");
16+
request.setMethod("GET");
17+
18+
dispatcher.doFilter(request, response, filterChain);
19+
String result = response.getContentAsString();
20+
a(result).shouldBeEqual("ok");
21+
}
22+
}

0 commit comments

Comments
 (0)