1.1 --- a/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Thu Jul 02 08:19:25 2015 +0200
1.2 +++ b/json/src/main/java/org/netbeans/html/json/impl/ModelProcessor.java Thu Jul 02 08:27:47 2015 +0200
1.3 @@ -1084,6 +1084,9 @@
1.4 error("@OnReceive method needs at least two parameters", e);
1.5 }
1.6 final boolean isWebSocket = "WebSocket".equals(onR.method());
1.7 + if (isWebSocket && dataMirror == null) {
1.8 + error("WebSocket method needs to specify a data() class", e);
1.9 + }
1.10 int expectsList = 0;
1.11 List<String> args = new ArrayList<String>();
1.12 List<String> params = new ArrayList<String>();
1.13 @@ -1190,7 +1193,7 @@
1.14 for (int i = 2; i < e.getParameters().size(); i++) {
1.15 if (isWebSocket) {
1.16 error("@OnReceive(method=\"WebSocket\") can only have two arguments", e);
1.17 - return false;
1.18 + ok = false;
1.19 }
1.20
1.21 VariableElement ve = e.getParameters().get(i);
2.1 --- a/json/src/test/java/net/java/html/json/ModelProcessorTest.java Thu Jul 02 08:19:25 2015 +0200
2.2 +++ b/json/src/test/java/net/java/html/json/ModelProcessorTest.java Thu Jul 02 08:27:47 2015 +0200
2.3 @@ -324,6 +324,35 @@
2.4
2.5 }
2.6
2.7 + @Test public void webSocketsWithoutDataIsError() throws Exception {
2.8 + String html = "<html><body>"
2.9 + + "</body></html>";
2.10 + String code = "package x.y.z;\n"
2.11 + + "import net.java.html.json.Model;\n"
2.12 + + "import net.java.html.json.Property;\n"
2.13 + + "import net.java.html.json.OnReceive;\n"
2.14 + + "@Model(className=\"XModel\", properties={\n"
2.15 + + " @Property(name=\"prop\", type=long.class)\n"
2.16 + + "})\n"
2.17 + + "class X {\n"
2.18 + + " @Model(className=\"PQ\", properties={})\n"
2.19 + + " class PImpl {\n"
2.20 + + " }\n"
2.21 + + " @OnReceive(method=\"WebSocket\", url=\"whereever\")\n"
2.22 + + " static void obtained(XModel m, PQ p) { }\n"
2.23 + + "}\n";
2.24 +
2.25 + Compile c = Compile.create(html, code);
2.26 + assertFalse(c.getErrors().isEmpty(), "One error: " + c.getErrors());
2.27 + for (Diagnostic<? extends JavaFileObject> diagnostic : c.getErrors()) {
2.28 + String msg = diagnostic.getMessage(Locale.ENGLISH);
2.29 + if (msg.contains("eeds to specify a data()")) {
2.30 + return;
2.31 + }
2.32 + }
2.33 + fail("Needs data attribute :\n" + c.getErrors());
2.34 + }
2.35 +
2.36 @Test public void noNewLinesInHeaderLines() throws Exception {
2.37 String html = "<html><body>"
2.38 + "</body></html>";
2.39 @@ -467,7 +496,7 @@
2.40 + " @net.java.html.json.Property(name=\"x\", type=String.class)\n"
2.41 + "})\n"
2.42 + "class UseOnReceive {\n"
2.43 - + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\", method=\"WebSocket\")\n"
2.44 + + " @net.java.html.json.OnReceive(url=\"http://nowhere.com\", method=\"WebSocket\", data=String.class)\n"
2.45 + " static void onMessage(MyModel model, String value, int arg) {\n"
2.46 + " }\n"
2.47 + "}\n"