File tree Expand file tree Collapse file tree 5 files changed +44
-10
lines changed
src/main/java/valandur/webapi/servlet
webapi-api/src/main/java/valandur/webapi/api/servlet Expand file tree Collapse file tree 5 files changed +44
-10
lines changed Original file line number Diff line number Diff line change @@ -65,12 +65,6 @@ shadowJar {
6565}
6666shadowJar. dependsOn([' :webapi-api:build' ])
6767
68- task cleanJars () {
69- project. file(' artifacts' ). listFiles(). each {
70- x -> if (x. name. endsWith(" jar" )) { x. delete() }
71- }
72- }
73-
7468task copyJars (type : Copy , dependsOn : ' :webapi-api:build' ) {
7569 from([subprojects. jar, shadowJar])
7670 into project. file(' artifacts' )
@@ -80,7 +74,5 @@ artifacts {
8074 archives shadowJar
8175}
8276
83- clean. dependsOn(cleanJars)
84- copyJars. mustRunAfter(cleanJars)
8577build. dependsOn(shadowJar)
8678build. dependsOn(copyJars)
Original file line number Diff line number Diff line change 1- version =4.1.0
1+ version =4.1.1
22minecraftVersion =1.11.2
33spongeVersion =6.1
Original file line number Diff line number Diff line change 55import com .fasterxml .jackson .databind .ObjectMapper ;
66import com .fasterxml .jackson .databind .node .JsonNodeFactory ;
77import com .fasterxml .jackson .databind .node .ObjectNode ;
8+ import valandur .webapi .api .servlet .IServletData ;
89import valandur .webapi .json .JsonConverter ;
910import valandur .webapi .misc .TreeNode ;
1011import valandur .webapi .misc .Util ;
1718import java .util .Map ;
1819import java .util .Optional ;
1920
20- public class ServletData {
21+ public class ServletData implements IServletData {
2122
2223 private HttpServletRequest req ;
2324 private HttpServletResponse resp ;
Original file line number Diff line number Diff line change 66import valandur .webapi .api .annotation .WebAPIRoute ;
77import valandur .webapi .api .annotation .WebAPIServlet ;
88import valandur .webapi .api .servlet .IServlet ;
9+ import valandur .webapi .api .servlet .IServletData ;
910import valandur .webapi .misc .Util ;
1011
1112import java .lang .reflect .Method ;
@@ -46,6 +47,15 @@ public static void init() {
4647 for (Tuple <WebAPIRoute , Method > tuple : newMethods ) {
4748 WebAPIRoute route = tuple .getFirst ();
4849 Method method = tuple .getSecond ();
50+ if (method .getParameterTypes ().length != 1 ) {
51+ logger .error (" Method " + method .getName () + " may only have 1 argument" );
52+ continue ;
53+ }
54+ if (method .getParameterTypes ()[0 ] != IServletData .class &&
55+ method .getParameterTypes ()[0 ] != ServletData .class ) {
56+ logger .error (" Method " + method .getName () + " parameter is not of type IServletData" );
57+ continue ;
58+ }
4959 method .setAccessible (true );
5060 logger .debug (" [" + route .method () + "] " + route .path () + " -> " +method .getName ());
5161 }
Original file line number Diff line number Diff line change 1+ package valandur .webapi .api .servlet ;
2+
3+ import com .fasterxml .jackson .databind .JsonNode ;
4+ import com .fasterxml .jackson .databind .node .ObjectNode ;
5+
6+ import java .util .Optional ;
7+
8+ public interface IServletData {
9+
10+ ObjectNode getNode ();
11+
12+ Exception getLastParseError ();
13+
14+ boolean isErrorSent ();
15+
16+ JsonNode getRequestBody ();
17+
18+ <T > Optional <T > getRequestBody (Class <T > clazz );
19+
20+ void setHeader (String name , String value );
21+
22+ void setStatus (int status );
23+
24+ void addJson (String key , Object value , boolean details );
25+
26+ String getPathParam (String key );
27+
28+ Optional <String > getQueryParam (String key );
29+
30+ void sendError (int error , String message );
31+ }
You can’t perform that action at this time.
0 commit comments