diff options
author | 2023-06-18 17:39:27 +0200 | |
---|---|---|
committer | 2023-06-18 17:49:03 +0200 | |
commit | 8fe6d4b9abe14fdc84f5b7a41e8f6e956f03b0dc (patch) | |
tree | 6d6e342b019a1f3ad0baae710cf520a5dffe4b9e /subprojects/language-web/src | |
parent | refactor: prefer Query.of over Dnf.of (diff) | |
download | refinery-8fe6d4b9abe14fdc84f5b7a41e8f6e956f03b0dc.tar.gz refinery-8fe6d4b9abe14fdc84f5b7a41e8f6e956f03b0dc.tar.zst refinery-8fe6d4b9abe14fdc84f5b7a41e8f6e956f03b0dc.zip |
chore(deps): bump dependencies
Diffstat (limited to 'subprojects/language-web/src')
3 files changed, 56 insertions, 46 deletions
diff --git a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/servlet/XtextWebSocket.java b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/servlet/XtextWebSocket.java index f7d33e9e..043d318c 100644 --- a/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/servlet/XtextWebSocket.java +++ b/subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/servlet/XtextWebSocket.java | |||
@@ -8,10 +8,10 @@ package tools.refinery.language.web.xtext.servlet; | |||
8 | import com.google.gson.Gson; | 8 | import com.google.gson.Gson; |
9 | import com.google.gson.JsonIOException; | 9 | import com.google.gson.JsonIOException; |
10 | import com.google.gson.JsonParseException; | 10 | import com.google.gson.JsonParseException; |
11 | import org.eclipse.jetty.ee10.websocket.api.Session; | 11 | import org.eclipse.jetty.websocket.api.Callback; |
12 | import org.eclipse.jetty.ee10.websocket.api.StatusCode; | 12 | import org.eclipse.jetty.websocket.api.Session; |
13 | import org.eclipse.jetty.ee10.websocket.api.WriteCallback; | 13 | import org.eclipse.jetty.websocket.api.StatusCode; |
14 | import org.eclipse.jetty.ee10.websocket.api.annotations.*; | 14 | import org.eclipse.jetty.websocket.api.annotations.*; |
15 | import org.eclipse.xtext.resource.IResourceServiceProvider; | 15 | import org.eclipse.xtext.resource.IResourceServiceProvider; |
16 | import org.eclipse.xtext.web.server.ISession; | 16 | import org.eclipse.xtext.web.server.ISession; |
17 | import org.slf4j.Logger; | 17 | import org.slf4j.Logger; |
@@ -25,7 +25,7 @@ import tools.refinery.language.web.xtext.server.message.XtextWebResponse; | |||
25 | import java.io.Reader; | 25 | import java.io.Reader; |
26 | 26 | ||
27 | @WebSocket | 27 | @WebSocket |
28 | public class XtextWebSocket implements WriteCallback, ResponseHandler { | 28 | public class XtextWebSocket implements ResponseHandler { |
29 | private static final Logger LOG = LoggerFactory.getLogger(XtextWebSocket.class); | 29 | private static final Logger LOG = LoggerFactory.getLogger(XtextWebSocket.class); |
30 | 30 | ||
31 | private final Gson gson = new Gson(); | 31 | private final Gson gson = new Gson(); |
@@ -43,13 +43,13 @@ public class XtextWebSocket implements WriteCallback, ResponseHandler { | |||
43 | this(new TransactionExecutor(session, resourceServiceProviderRegistry)); | 43 | this(new TransactionExecutor(session, resourceServiceProviderRegistry)); |
44 | } | 44 | } |
45 | 45 | ||
46 | @OnWebSocketConnect | 46 | @OnWebSocketOpen |
47 | public void onConnect(Session webSocketSession) { | 47 | public void onOpen(Session webSocketSession) { |
48 | if (this.webSocketSession != null) { | 48 | if (this.webSocketSession != null) { |
49 | LOG.error("Websocket session onConnect when already connected"); | 49 | LOG.error("Websocket session onConnect when already connected"); |
50 | return; | 50 | return; |
51 | } | 51 | } |
52 | LOG.debug("New websocket connection from {}", webSocketSession.getRemoteAddress()); | 52 | LOG.debug("New websocket connection from {}", webSocketSession.getRemoteSocketAddress()); |
53 | this.webSocketSession = webSocketSession; | 53 | this.webSocketSession = webSocketSession; |
54 | } | 54 | } |
55 | 55 | ||
@@ -60,10 +60,10 @@ public class XtextWebSocket implements WriteCallback, ResponseHandler { | |||
60 | return; | 60 | return; |
61 | } | 61 | } |
62 | if (statusCode == StatusCode.NORMAL || statusCode == StatusCode.SHUTDOWN) { | 62 | if (statusCode == StatusCode.NORMAL || statusCode == StatusCode.SHUTDOWN) { |
63 | LOG.debug("{} closed connection normally: {}", webSocketSession.getRemoteAddress(), reason); | 63 | LOG.debug("{} closed connection normally: {}", webSocketSession.getRemoteSocketAddress(), reason); |
64 | } else { | 64 | } else { |
65 | LOG.warn("{} closed connection with status code {}: {}", webSocketSession.getRemoteAddress(), statusCode, | 65 | LOG.warn("{} closed connection with status code {}: {}", webSocketSession.getRemoteSocketAddress(), |
66 | reason); | 66 | statusCode, reason); |
67 | } | 67 | } |
68 | webSocketSession = null; | 68 | webSocketSession = null; |
69 | } | 69 | } |
@@ -73,7 +73,7 @@ public class XtextWebSocket implements WriteCallback, ResponseHandler { | |||
73 | if (webSocketSession == null) { | 73 | if (webSocketSession == null) { |
74 | return; | 74 | return; |
75 | } | 75 | } |
76 | LOG.error("Internal websocket error in connection from" + webSocketSession.getRemoteAddress(), error); | 76 | LOG.error("Internal websocket error in connection from" + webSocketSession.getRemoteSocketAddress(), error); |
77 | } | 77 | } |
78 | 78 | ||
79 | @OnWebSocketMessage | 79 | @OnWebSocketMessage |
@@ -86,14 +86,14 @@ public class XtextWebSocket implements WriteCallback, ResponseHandler { | |||
86 | try { | 86 | try { |
87 | request = gson.fromJson(reader, XtextWebRequest.class); | 87 | request = gson.fromJson(reader, XtextWebRequest.class); |
88 | } catch (JsonIOException e) { | 88 | } catch (JsonIOException e) { |
89 | LOG.error("Cannot read from websocket from" + webSocketSession.getRemoteAddress(), e); | 89 | LOG.error("Cannot read from websocket from" + webSocketSession.getRemoteSocketAddress(), e); |
90 | if (webSocketSession.isOpen()) { | 90 | if (webSocketSession.isOpen()) { |
91 | webSocketSession.close(StatusCode.SERVER_ERROR, "Cannot read payload"); | 91 | webSocketSession.close(StatusCode.SERVER_ERROR, "Cannot read payload", Callback.NOOP); |
92 | } | 92 | } |
93 | return; | 93 | return; |
94 | } catch (JsonParseException e) { | 94 | } catch (JsonParseException e) { |
95 | LOG.warn("Malformed websocket request from" + webSocketSession.getRemoteAddress(), e); | 95 | LOG.warn("Malformed websocket request from" + webSocketSession.getRemoteSocketAddress(), e); |
96 | webSocketSession.close(XtextStatusCode.INVALID_JSON, "Invalid JSON payload"); | 96 | webSocketSession.close(XtextStatusCode.INVALID_JSON, "Invalid JSON payload", Callback.NOOP); |
97 | return; | 97 | return; |
98 | } | 98 | } |
99 | try { | 99 | try { |
@@ -101,7 +101,7 @@ public class XtextWebSocket implements WriteCallback, ResponseHandler { | |||
101 | } catch (ResponseHandlerException e) { | 101 | } catch (ResponseHandlerException e) { |
102 | LOG.warn("Cannot write websocket response", e); | 102 | LOG.warn("Cannot write websocket response", e); |
103 | if (webSocketSession.isOpen()) { | 103 | if (webSocketSession.isOpen()) { |
104 | webSocketSession.close(StatusCode.SERVER_ERROR, "Cannot write response"); | 104 | webSocketSession.close(StatusCode.SERVER_ERROR, "Cannot write response", Callback.NOOP); |
105 | } | 105 | } |
106 | } | 106 | } |
107 | } | 107 | } |
@@ -112,15 +112,14 @@ public class XtextWebSocket implements WriteCallback, ResponseHandler { | |||
112 | throw new ResponseHandlerException("Trying to send message when websocket is disconnected"); | 112 | throw new ResponseHandlerException("Trying to send message when websocket is disconnected"); |
113 | } | 113 | } |
114 | var responseString = gson.toJson(response); | 114 | var responseString = gson.toJson(response); |
115 | webSocketSession.getRemote().sendPartialString(responseString, true, this); | 115 | webSocketSession.sendText(responseString, Callback.from(() -> {}, this::writeFailed)); |
116 | } | 116 | } |
117 | 117 | ||
118 | @Override | ||
119 | public void writeFailed(Throwable x) { | 118 | public void writeFailed(Throwable x) { |
120 | if (webSocketSession == null) { | 119 | if (webSocketSession == null) { |
121 | LOG.error("Cannot complete async write to disconnected websocket", x); | 120 | LOG.error("Cannot complete async write to disconnected websocket", x); |
122 | return; | 121 | return; |
123 | } | 122 | } |
124 | LOG.warn("Cannot complete async write to websocket " + webSocketSession.getRemoteAddress(), x); | 123 | LOG.warn("Cannot complete async write to websocket " + webSocketSession.getRemoteSocketAddress(), x); |
125 | } | 124 | } |
126 | } | 125 | } |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java index 40f5281d..927eeab1 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/ProblemWebSocketServletIntegrationTest.java | |||
@@ -7,17 +7,18 @@ package tools.refinery.language.web; | |||
7 | 7 | ||
8 | import org.eclipse.jetty.ee10.servlet.ServletContextHandler; | 8 | import org.eclipse.jetty.ee10.servlet.ServletContextHandler; |
9 | import org.eclipse.jetty.ee10.servlet.ServletHolder; | 9 | import org.eclipse.jetty.ee10.servlet.ServletHolder; |
10 | import org.eclipse.jetty.ee10.websocket.api.Session; | ||
11 | import org.eclipse.jetty.ee10.websocket.api.StatusCode; | ||
12 | import org.eclipse.jetty.ee10.websocket.api.annotations.WebSocket; | ||
13 | import org.eclipse.jetty.ee10.websocket.api.exceptions.UpgradeException; | ||
14 | import org.eclipse.jetty.ee10.websocket.client.ClientUpgradeRequest; | ||
15 | import org.eclipse.jetty.ee10.websocket.client.WebSocketClient; | ||
16 | import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletContainerInitializer; | 10 | import org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketServletContainerInitializer; |
17 | import org.eclipse.jetty.http.HttpHeader; | 11 | import org.eclipse.jetty.http.HttpHeader; |
18 | import org.eclipse.jetty.http.HttpStatus; | 12 | import org.eclipse.jetty.http.HttpStatus; |
19 | import org.eclipse.jetty.server.Server; | 13 | import org.eclipse.jetty.server.Server; |
20 | import org.eclipse.jetty.util.thread.QueuedThreadPool; | 14 | import org.eclipse.jetty.util.thread.QueuedThreadPool; |
15 | import org.eclipse.jetty.websocket.api.Callback; | ||
16 | import org.eclipse.jetty.websocket.api.Session; | ||
17 | import org.eclipse.jetty.websocket.api.StatusCode; | ||
18 | import org.eclipse.jetty.websocket.api.annotations.WebSocket; | ||
19 | import org.eclipse.jetty.websocket.api.exceptions.UpgradeException; | ||
20 | import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; | ||
21 | import org.eclipse.jetty.websocket.client.WebSocketClient; | ||
21 | import org.eclipse.xtext.testing.GlobalRegistries; | 22 | import org.eclipse.xtext.testing.GlobalRegistries; |
22 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; | 23 | import org.eclipse.xtext.testing.GlobalRegistries.GlobalStateMemento; |
23 | import org.junit.jupiter.api.AfterEach; | 24 | import org.junit.jupiter.api.AfterEach; |
@@ -95,23 +96,34 @@ class ProblemWebSocketServletIntegrationTest { | |||
95 | assertThat(responses, hasSize(5)); | 96 | assertThat(responses, hasSize(5)); |
96 | assertThat(responses.get(0), equalTo("{\"id\":\"foo\",\"response\":{\"stateId\":\"-80000000\"}}")); | 97 | assertThat(responses.get(0), equalTo("{\"id\":\"foo\",\"response\":{\"stateId\":\"-80000000\"}}")); |
97 | assertThat(responses.get(1), startsWith( | 98 | assertThat(responses.get(1), startsWith( |
98 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"highlight\",\"push\":{\"regions\":[")); | 99 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"highlight\"," + |
100 | "\"push\":{\"regions\":[")); | ||
99 | assertThat(responses.get(2), equalTo( | 101 | assertThat(responses.get(2), equalTo( |
100 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"validate\",\"push\":{\"issues\":[]}}")); | 102 | "{\"resource\":\"test.problem\",\"stateId\":\"-80000000\",\"service\":\"validate\"," + |
103 | "\"push\":{\"issues\":[]}}")); | ||
101 | assertThat(responses.get(3), equalTo("{\"id\":\"bar\",\"response\":{\"stateId\":\"-7fffffff\"}}")); | 104 | assertThat(responses.get(3), equalTo("{\"id\":\"bar\",\"response\":{\"stateId\":\"-7fffffff\"}}")); |
102 | assertThat(responses.get(4), startsWith( | 105 | assertThat(responses.get(4), startsWith( |
103 | "{\"resource\":\"test.problem\",\"stateId\":\"-7fffffff\",\"service\":\"highlight\",\"push\":{\"regions\":[")); | 106 | "{\"resource\":\"test.problem\",\"stateId\":\"-7fffffff\",\"service\":\"highlight\"," + |
107 | "\"push\":{\"regions\":[")); | ||
104 | } | 108 | } |
105 | 109 | ||
106 | @WebSocket | 110 | @WebSocket |
107 | public static class UpdateTestClient extends WebSocketIntegrationTestClient { | 111 | public static class UpdateTestClient extends WebSocketIntegrationTestClient { |
108 | @Override | 112 | @Override |
109 | protected void arrange(Session session, int responsesReceived) throws IOException { | 113 | protected void arrange(Session session, int responsesReceived) { |
110 | switch (responsesReceived) { | 114 | switch (responsesReceived) { |
111 | case 0 -> session.getRemote().sendString( | 115 | case 0 -> session.sendText( |
112 | "{\"id\":\"foo\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\",\"fullText\":\"class Person.\n\"}}"); | 116 | "{\"id\":\"foo\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\"," + |
113 | case 3 -> session.getRemote().sendString( | 117 | "\"fullText\":\"class Person.\n\"}}", |
114 | "{\"id\":\"bar\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\",\"requiredStateId\":\"-80000000\",\"deltaText\":\"indiv q.\nnode(q).\n\",\"deltaOffset\":\"0\",\"deltaReplaceLength\":\"0\"}}"); | 118 | Callback.NOOP |
119 | ); | ||
120 | case 3 -> //noinspection TextBlockMigration | ||
121 | session.sendText( | ||
122 | "{\"id\":\"bar\",\"request\":{\"resource\":\"test.problem\",\"serviceType\":\"update\"," + | ||
123 | "\"requiredStateId\":\"-80000000\",\"deltaText\":\"indiv q.\nnode(q).\n\"," + | ||
124 | "\"deltaOffset\":\"0\",\"deltaReplaceLength\":\"0\"}}", | ||
125 | Callback.NOOP | ||
126 | ); | ||
115 | case 5 -> session.close(); | 127 | case 5 -> session.close(); |
116 | } | 128 | } |
117 | } | 129 | } |
@@ -161,13 +173,13 @@ class ProblemWebSocketServletIntegrationTest { | |||
161 | @WebSocket | 173 | @WebSocket |
162 | public static class InvalidJsonTestClient extends WebSocketIntegrationTestClient { | 174 | public static class InvalidJsonTestClient extends WebSocketIntegrationTestClient { |
163 | @Override | 175 | @Override |
164 | protected void arrange(Session session, int responsesReceived) throws IOException { | 176 | protected void arrange(Session session, int responsesReceived) { |
165 | session.getRemote().sendString("<invalid json>"); | 177 | session.sendText("<invalid json>", Callback.NOOP); |
166 | } | 178 | } |
167 | } | 179 | } |
168 | 180 | ||
169 | @ParameterizedTest(name = "validOriginTest(\"{0}\")") | 181 | @ParameterizedTest(name = "validOriginTest(\"{0}\")") |
170 | @ValueSource(strings = { "https://refinery.example", "https://refinery.example:443", "HTTPS://REFINERY.EXAMPLE" }) | 182 | @ValueSource(strings = {"https://refinery.example", "https://refinery.example:443", "HTTPS://REFINERY.EXAMPLE"}) |
171 | void validOriginTest(String origin) { | 183 | void validOriginTest(String origin) { |
172 | startServer("https://refinery.example,https://refinery.example:443"); | 184 | startServer("https://refinery.example,https://refinery.example:443"); |
173 | var clientSocket = new CloseImmediatelyTestClient(); | 185 | var clientSocket = new CloseImmediatelyTestClient(); |
diff --git a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java index 46220777..6ccf1760 100644 --- a/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java +++ b/subprojects/language-web/src/test/java/tools/refinery/language/web/tests/WebSocketIntegrationTestClient.java | |||
@@ -5,13 +5,12 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.language.web.tests; | 6 | package tools.refinery.language.web.tests; |
7 | 7 | ||
8 | import org.eclipse.jetty.ee10.websocket.api.Session; | 8 | import org.eclipse.jetty.websocket.api.Session; |
9 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketClose; | 9 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; |
10 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketConnect; | 10 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; |
11 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketError; | 11 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; |
12 | import org.eclipse.jetty.ee10.websocket.api.annotations.OnWebSocketMessage; | 12 | import org.eclipse.jetty.websocket.api.annotations.OnWebSocketOpen; |
13 | 13 | ||
14 | import java.io.IOException; | ||
15 | import java.time.Duration; | 14 | import java.time.Duration; |
16 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
17 | import java.util.List; | 16 | import java.util.List; |
@@ -39,8 +38,8 @@ public abstract class WebSocketIntegrationTestClient { | |||
39 | return responses; | 38 | return responses; |
40 | } | 39 | } |
41 | 40 | ||
42 | @OnWebSocketConnect | 41 | @OnWebSocketOpen |
43 | public void onConnect(Session session) { | 42 | public void onOpen(Session session) { |
44 | arrangeAndCatchErrors(session); | 43 | arrangeAndCatchErrors(session); |
45 | } | 44 | } |
46 | 45 | ||
@@ -52,7 +51,7 @@ public abstract class WebSocketIntegrationTestClient { | |||
52 | } | 51 | } |
53 | } | 52 | } |
54 | 53 | ||
55 | protected abstract void arrange(Session session, int responsesReceived) throws IOException; | 54 | protected abstract void arrange(Session session, int responsesReceived); |
56 | 55 | ||
57 | @OnWebSocketClose | 56 | @OnWebSocketClose |
58 | public void onClose(int statusCode, String reason) { | 57 | public void onClose(int statusCode, String reason) { |