diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-06-18 17:39:27 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-06-18 17:49:03 +0200 |
commit | 8fe6d4b9abe14fdc84f5b7a41e8f6e956f03b0dc (patch) | |
tree | 6d6e342b019a1f3ad0baae710cf520a5dffe4b9e /subprojects/language-web/src/main | |
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/main')
-rw-r--r-- | subprojects/language-web/src/main/java/tools/refinery/language/web/xtext/servlet/XtextWebSocket.java | 39 |
1 files changed, 19 insertions, 20 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 | } |