Skip to content

Commit 1b2e309

Browse files
authored
Merge pull request #14 from kadampabookings/prod
Mid-February work
2 parents bcca69a + 9d68997 commit 1b2e309

File tree

36 files changed

+288
-132
lines changed

36 files changed

+288
-132
lines changed

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<groupId>org.apache.maven.plugins</groupId>
3636
<artifactId>maven-javadoc-plugin</artifactId>
3737
<configuration>
38-
<skippedModules>webfx-stack-authn-login-ui-gateway-webviewbased-gwt,webfx-stack-authn-login-ui-gateway-webviewbased-openjfx,webfx-stack-com-bus-json-client-websocket-java,webfx-stack-com-bus-json-client-websocket-web,webfx-stack-com-websocket-gwt-j2cl,webfx-stack-com-websocket-java</skippedModules>
38+
<skippedModules>webfx-stack-authn-login-ui-gateway-webviewbased-gwt,webfx-stack-authn-login-ui-gateway-webviewbased-openjfx,webfx-stack-com-bus-json-client-websocket-java,webfx-stack-com-bus-json-client-websocket-web,webfx-stack-com-websocket-gwt-j2cl-native,webfx-stack-com-websocket-gwt-j2cl-sockjs,webfx-stack-com-websocket-java</skippedModules>
3939
</configuration>
4040
</plugin>
4141
</plugins>
@@ -98,7 +98,8 @@
9898
<module>webfx-stack-com-bus-simple</module>
9999
<module>webfx-stack-com-serial</module>
100100
<module>webfx-stack-com-websocket</module>
101-
<module>webfx-stack-com-websocket-gwt-j2cl</module>
101+
<module>webfx-stack-com-websocket-gwt-j2cl-native</module>
102+
<module>webfx-stack-com-websocket-gwt-j2cl-sockjs</module>
102103
<module>webfx-stack-com-websocket-java</module>
103104
<module>webfx-stack-db-datascope</module>
104105
<module>webfx-stack-db-datasource</module>

webfx-stack-authn-login-ui-gateway-password-plugin/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
<version>0.1.0-SNAPSHOT</version>
4646
</dependency>
4747

48+
<dependency>
49+
<groupId>dev.webfx</groupId>
50+
<artifactId>webfx-extras-util-control</artifactId>
51+
<version>0.1.0-SNAPSHOT</version>
52+
</dependency>
53+
4854
<dependency>
4955
<groupId>dev.webfx</groupId>
5056
<artifactId>webfx-extras-util-scene</artifactId>

webfx-stack-authn-login-ui-gateway-password-plugin/src/main/java/dev/webfx/stack/authn/login/ui/spi/impl/gateway/password/UILoginView.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import dev.webfx.extras.panes.ScalePane;
55
import dev.webfx.extras.styles.bootstrap.Bootstrap;
6+
import dev.webfx.extras.util.control.Controls;
7+
import dev.webfx.extras.util.control.HtmlInputAutocomplete;
68
import dev.webfx.platform.uischeduler.UiScheduler;
79
import dev.webfx.platform.windowlocation.WindowLocation;
810
import dev.webfx.stack.authn.AuthenticateWithUsernamePasswordCredentials;
@@ -86,10 +88,11 @@ private void initialiseMainVBox(VBox container) {
8688
emailTextField = newMaterialTextField(PasswordI18nKeys.Email);
8789
VBox.setMargin(emailTextField, new Insets(40, 0, 0, 0));
8890
emailTextField.setPrefWidth(370);
89-
91+
Controls.setHtmlInputTypeAndAutocompleteToEmail(emailTextField);
9092

9193
passwordFieldAndMessageVbox = new VBox(10);
9294
passwordField = newMaterialPasswordField(PasswordI18nKeys.Password);
95+
Controls.setHtmlInputAutocomplete(passwordField, HtmlInputAutocomplete.CURRENT_PASSWORD);
9396
passwordField.setPrefWidth(370);
9497
VBox.setMargin(passwordField, new Insets(15, 0, 0, 0));
9598

webfx-stack-authn-login-ui-gateway-password-plugin/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
requires javafx.graphics;
99
requires webfx.extras.panes;
1010
requires webfx.extras.styles.bootstrap;
11+
requires webfx.extras.util.control;
1112
requires webfx.extras.util.scene;
1213
requires webfx.kit.util;
1314
requires webfx.platform.uischeduler;

webfx-stack-com-bus-json-client-websocket/src/main/java/dev/webfx/stack/com/bus/spi/impl/json/client/websocket/WebSocketBus.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,18 @@ public class WebSocketBus extends JsonClientBus {
5454
ConfigLoader.onConfigLoaded("webfx.stack.com.client.websocket", config -> {
5555
WebSocketBusOptions options = new WebSocketBusOptions();
5656
options.applyConfig(config);
57-
//options.turnUnsetPropertiesToDefault(); // should be already done by the platform but just in case
57+
options.turnUnsetPropertiesToDefault();
5858
onOptions(options);
5959
});
6060
}
6161

6262
protected void onOptions(WebSocketBusOptions options) {
6363
String serverUri =
64-
(options.getProtocol() == WebSocketBusOptions.Protocol.WS ? "ws" : "http")
65-
+ (Booleans.isTrue(options.isServerSSL()) ? "s://" : "://")
64+
(Booleans.isTrue(options.isServerSSL()) ? "wss://" : "ws://")
6665
+ options.getServerHost()
6766
+ ':' + options.getServerPort()
6867
+ '/' + options.getBusPrefix()
69-
+ (options.getProtocol() == WebSocketBusOptions.Protocol.WS ? "/websocket" : "");
68+
+ '/' + options.getWebsocketSuffix();
7069
internalWebSocketHandler = new WebSocketListener() {
7170
@Override
7271
public void onOpen() {

webfx-stack-com-bus-json-client-websocket/src/main/java/dev/webfx/stack/com/bus/spi/impl/json/client/websocket/WebSocketBusOptions.java

Lines changed: 20 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.webfx.stack.com.bus.spi.impl.json.client.websocket;
22

33
import dev.webfx.platform.ast.ReadOnlyAstObject;
4-
import dev.webfx.platform.console.Console;
54
import dev.webfx.platform.util.Objects;
65
import dev.webfx.stack.com.bus.BusOptions;
76

@@ -10,26 +9,20 @@
109
*/
1110
public final class WebSocketBusOptions extends BusOptions {
1211

13-
public enum Protocol {
14-
WS, // Web Socket protocol, to be used by non web applications (Jre, Android, iOS)
15-
HTTP // HTTP protocol, to be used by web applications running in the browser (GWT, TeaVM)
16-
}
17-
18-
private Protocol protocol;
1912
private Boolean serverSSL;
2013
private String serverHost;
2114
private String serverPort;
22-
15+
private String websocketSuffix;
2316
private Integer pingInterval;
2417

2518
private ReadOnlyAstObject socketOptions;
2619

2720
@Override
2821
public WebSocketBusOptions turnUnsetPropertiesToDefault() {
29-
protocol = Objects.coalesce(protocol, Protocol.WS);
3022
serverSSL = Objects.coalesce(serverSSL, Boolean.FALSE);
3123
serverHost = Objects.coalesce(serverHost, "localhost");
3224
serverPort = Objects.coalesce(serverPort, "80");
25+
websocketSuffix = Objects.coalesce(websocketSuffix, "websocket");
3326
pingInterval = Objects.coalesce(pingInterval, 30_000);
3427
super.turnUnsetPropertiesToDefault();
3528
return this;
@@ -41,35 +34,11 @@ public WebSocketBusOptions applyConfig(ReadOnlyAstObject config) {
4134
serverSSL = config.getBoolean("serverSSL");
4235
serverHost = config.getString("serverHost");
4336
serverPort = config.getString("serverPort");
37+
websocketSuffix = config.getString("websocketSuffix");
4438
pingInterval = config.getInteger("pingInterval");
45-
String configProtocol = config.getString("protocol");
46-
if (configProtocol != null) {
47-
switch (configProtocol.toLowerCase()) {
48-
case "https":
49-
serverSSL = true;
50-
case "http":
51-
protocol = Protocol.HTTP;
52-
break;
53-
case "wss":
54-
serverSSL = true;
55-
case "ws":
56-
protocol = Protocol.WS;
57-
break;
58-
}
59-
}
60-
if (protocol == null) {
61-
Console.log("⚠️ Default WS protocol will be applied for WebSocket due to unrecognized protocol configuration value: " + configProtocol);
62-
protocol = Protocol.WS;
63-
}
64-
return this;
65-
}
66-
67-
public Protocol getProtocol() {
68-
return protocol;
69-
}
70-
71-
public WebSocketBusOptions setProtocol(Protocol protocol) {
72-
this.protocol = protocol;
39+
if (serverSSL == null)
40+
serverSSL = "80".equals(serverPort);
41+
socketOptions = config;
7342
return this;
7443
}
7544

@@ -87,6 +56,10 @@ public WebSocketBusOptions setServerSSL(Boolean serverSSL) {
8756
return this;
8857
}
8958

59+
public Boolean isServerSSL() {
60+
return serverSSL;
61+
}
62+
9063
public WebSocketBusOptions setServerPort(String serverPort) {
9164
this.serverPort = serverPort;
9265
return this;
@@ -96,19 +69,25 @@ public String getServerPort() {
9669
return serverPort;
9770
}
9871

99-
public Boolean isServerSSL() {
100-
return serverSSL;
72+
public WebSocketBusOptions setWebsocketSuffix(String websocketSuffix) {
73+
this.websocketSuffix = websocketSuffix;
74+
return this;
10175
}
10276

103-
public int getPingInterval() {
104-
return pingInterval;
77+
public String getWebsocketSuffix() {
78+
return websocketSuffix;
10579
}
10680

10781
public WebSocketBusOptions setPingInterval(Integer pingInterval) {
10882
this.pingInterval = pingInterval;
10983
return this;
11084
}
11185

86+
public int getPingInterval() {
87+
return pingInterval;
88+
}
89+
90+
11291
public ReadOnlyAstObject getSocketOptions() {
11392
return socketOptions;
11493
}

webfx-stack-com-bus/src/main/java/dev/webfx/stack/com/bus/BusOptions.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@
1010
public class BusOptions {
1111

1212
private String busPrefix;
13-
private String clientBusAddressPrefix;
14-
private String serverBusAddress;
1513

1614
public BusOptions turnUnsetPropertiesToDefault() {
1715
busPrefix = Objects.coalesce(busPrefix, "eventbus");
18-
clientBusAddressPrefix = Objects.coalesce(clientBusAddressPrefix, "client");
19-
serverBusAddress = Objects.coalesce(serverBusAddress, "server");
2016
return this;
2117
}
2218

2319
public BusOptions applyConfig(ReadOnlyAstObject config) {
2420
busPrefix = config.getString("busPrefix", busPrefix);
25-
clientBusAddressPrefix = config.getString("clientBusAddressPrefix", clientBusAddressPrefix);
26-
serverBusAddress = config.getString("serverBusAddress", serverBusAddress);
2721
return this;
2822
}
2923

webfx-stack-com-websocket-gwt-j2cl/pom.xml renamed to webfx-stack-com-websocket-gwt-j2cl-native/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<version>0.1.0-SNAPSHOT</version>
1212
</parent>
1313

14-
<artifactId>webfx-stack-com-websocket-gwt-j2cl</artifactId>
14+
<artifactId>webfx-stack-com-websocket-gwt-j2cl-native</artifactId>
1515

1616
<dependencies>
1717

@@ -22,12 +22,12 @@
2222

2323
<dependency>
2424
<groupId>com.google.elemental2</groupId>
25-
<artifactId>elemental2-dom</artifactId>
25+
<artifactId>elemental2-core</artifactId>
2626
</dependency>
2727

2828
<dependency>
29-
<groupId>com.google.jsinterop</groupId>
30-
<artifactId>jsinterop-annotations</artifactId>
29+
<groupId>com.google.elemental2</groupId>
30+
<artifactId>elemental2-dom</artifactId>
3131
</dependency>
3232

3333
<dependency>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package dev.webfx.stack.com.websocket.spi.impl.gwtj2cl.nativ;
2+
3+
import dev.webfx.platform.ast.AST;
4+
import dev.webfx.stack.com.websocket.WebSocket;
5+
import dev.webfx.stack.com.websocket.WebSocketListener;
6+
import elemental2.core.ArrayBuffer;
7+
import elemental2.dom.Blob;
8+
import jsinterop.base.Js;
9+
10+
/**
11+
* @author Bruno Salmon
12+
*/
13+
final class GwtJ2clNativeWebSocket implements WebSocket {
14+
15+
private final elemental2.dom.WebSocket nativeWebSocket;
16+
17+
public GwtJ2clNativeWebSocket(elemental2.dom.WebSocket nativeWebSocket) {
18+
this.nativeWebSocket = nativeWebSocket;
19+
}
20+
21+
@Override
22+
public void send(String data) {
23+
nativeWebSocket.send(data);
24+
}
25+
26+
@Override
27+
public void close() {
28+
nativeWebSocket.close();
29+
}
30+
31+
@Override
32+
public State getReadyState() {
33+
int sockJsState = nativeWebSocket.readyState;
34+
if (sockJsState == elemental2.dom.WebSocket.OPEN)
35+
return State.OPEN;
36+
if (sockJsState == elemental2.dom.WebSocket.CONNECTING)
37+
return State.CONNECTING;
38+
if (sockJsState == elemental2.dom.WebSocket.CLOSING)
39+
return State.CLOSING;
40+
if (sockJsState == elemental2.dom.WebSocket.CLOSED)
41+
return State.CLOSED;
42+
throw new IllegalStateException("Unrecognized readyState");
43+
}
44+
45+
@Override
46+
public void setListener(WebSocketListener listener) {
47+
nativeWebSocket.onopen = e -> listener.onOpen();
48+
nativeWebSocket.onmessage = e -> {
49+
String dataType = Js.typeof(e.data);
50+
if ("String".equals(dataType))
51+
listener.onMessage(e.data.asString());
52+
else if (e.data instanceof Blob) {
53+
((Blob) e.data).text().then(text -> {
54+
listener.onMessage(text);
55+
return null;
56+
});
57+
} else if (e.data instanceof ArrayBuffer) {
58+
// TODO: implement this case
59+
}
60+
};
61+
nativeWebSocket.onclose = e -> listener.onClose(AST.createObject().set("code", e.code).set("reason", e.reason));
62+
nativeWebSocket.onerror = e -> listener.onError(e.toString());
63+
}
64+
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dev.webfx.stack.com.websocket.spi.impl.gwtj2cl.nativ;
2+
3+
import dev.webfx.platform.ast.ReadOnlyAstObject;
4+
import dev.webfx.stack.com.websocket.spi.WebSocketServiceProvider;
5+
6+
/**
7+
* @author Bruno Salmon
8+
*/
9+
public final class GwtJ2clNativeWebSocketServiceProvider implements WebSocketServiceProvider {
10+
11+
@Override
12+
public GwtJ2clNativeWebSocket createWebSocket(String url, ReadOnlyAstObject options) {
13+
// Otherwise we create a brand new SockJS connection
14+
return new GwtJ2clNativeWebSocket(new elemental2.dom.WebSocket(url));
15+
};
16+
17+
}

0 commit comments

Comments
 (0)