Skip to content

Commit ad52473

Browse files
committed
don't use sockjs, build fix
1 parent 5c1e351 commit ad52473

File tree

7 files changed

+34
-33
lines changed

7 files changed

+34
-33
lines changed

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
steps:
1818
- uses: actions/checkout@v2
19-
- uses: browser-actions/setup-firefox@v1
19+
- uses: browser-actions/setup-chrome@v1
2020

2121
- name: Set up JDK 21
2222
uses: actions/setup-java@v1

main-app/main-webapp/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,6 @@
165165
<groupId>org.webjars</groupId>
166166
<artifactId>bootstrap</artifactId>
167167
</dependency>
168-
<dependency>
169-
<groupId>org.webjars</groupId>
170-
<artifactId>sockjs-client</artifactId>
171-
</dependency>
172-
<dependency>
173-
<groupId>org.webjars</groupId>
174-
<artifactId>stomp-websocket</artifactId>
175-
</dependency>
176168
<dependency>
177169
<groupId>org.webjars.bower</groupId>
178170
<artifactId>jquery-toast-plugin</artifactId>

main-app/main-webapp/src/main/java/gt/app/config/WebSocketConfig.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ public void configureMessageBroker(MessageBrokerRegistry config) {
1919

2020
@Override
2121
public void registerStompEndpoints(StompEndpointRegistry registry) {
22-
registry.addEndpoint("/app-websockets-main-endpoint")
23-
.setAllowedOrigins("http://localhost:8081") //TODO: fix this before prod release
24-
.withSockJS();
22+
registry.addEndpoint("/app-websockets-main-endpoint");
2523
}
2624

2725
}

main-app/main-webapp/src/main/resources/static/js/app.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,30 @@
2727
displayUserInfo(ev);
2828
});
2929

30-
initSockJS();
30+
initStompJs();
3131
});
3232

3333

34-
function initSockJS() {
34+
function initStompJs() {
3535

3636
//TODO: implement auto reconnect on disconnect
3737

38-
var socket = new SockJS('/app-websockets-main-endpoint');
39-
stompClient = Stomp.over(socket);
40-
stompClient.connect({}, function (frame) {
38+
39+
stompClient = new StompJs.Client({
40+
brokerURL: 'ws://localhost:8081/app-websockets-main-endpoint',
41+
connectHeaders: {
42+
login: 'user',
43+
passcode: 'password',
44+
},
45+
debug: function (str) {
46+
console.log(str);
47+
},
48+
reconnectDelay: 5000,
49+
heartbeatIncoming: 4000,
50+
heartbeatOutgoing: 4000,
51+
});
52+
53+
stompClient.onConnect = function(frame){
4154

4255
console.log('Connected: ' + frame);
4356
stompClient.subscribe('/topic/global-messages', function (msg) {
@@ -62,6 +75,17 @@
6275
position: 'top-right',
6376
});
6477
});
65-
});
78+
}
79+
80+
stompClient.onStompError = function (frame) {
81+
// Will be invoked in case of error encountered at Broker
82+
// Bad login/passcode typically will cause an error
83+
// Complaint brokers will set `message` header with a brief message. Body may contain details.
84+
// Compliant brokers will terminate the connection after any error
85+
console.log('Broker reported error: ' + frame.headers['message']);
86+
console.log('Additional details: ' + frame.body);
87+
};
88+
89+
stompClient.activate();
6690
}
6791
})();

main-app/main-webapp/src/main/resources/templates/_fragments/footer.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<script src="/webjars/jquery/3.6.1/jquery.min.js"></script>
2121
<script src="/webjars/bootstrap/5.0.1/js/bootstrap.min.js"></script>
2222

23-
<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js"></script>
2423
<script src="https://cdn.jsdelivr.net/npm/@stomp/stompjs@7.0.0/bundles/stomp.umd.min.js"></script>
2524
<script src="/webjars/jquery-toast-plugin/1.3.2/dist/jquery.toast.min.js"></script>
2625
<script th:src="@{/static/js/wro-commons.js}"></script>

main-app/main-webapp/src/test/java/gt/app/e2e/PublicPageIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void loadIndexPageAndVerifyResultIsCached(@Autowired MockMvc mvc) throws Excepti
4343
.andReturn();
4444

4545
String content = result.getResponse().getContentAsString();
46-
assertTrue(content.contains("<title> Article App - HOME</title>"));
46+
assertTrue(content.contains("<title>Article App - HOME</title>"));
4747
assertTrue(content.contains("User2 Article"));
4848
assertTrue(content.contains("Ganesh Tiwari"));
4949

@@ -68,7 +68,7 @@ void testCacheAndDBBothAreResetBetweenTests(@Autowired MockMvc mvc) throws Excep
6868
.andReturn();
6969

7070
String content = result.getResponse().getContentAsString();
71-
assertTrue(content.contains("<title> Article App - HOME</title>"));
71+
assertTrue(content.contains("<title>Article App - HOME</title>"));
7272
assertTrue(content.contains("User2 Article"));
7373
assertTrue(content.contains("Ganesh Tiwari"));
7474

pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@
5151
<commons-io.version>2.14.0</commons-io.version>
5252
<webjar-jquery.version>3.6.1</webjar-jquery.version>
5353
<webjar-bootstrap.version>5.0.1</webjar-bootstrap.version>
54-
<webjar-sockjs-client.version>1.5.1</webjar-sockjs-client.version>
55-
<webjar-stomp-websocket.version>2.3.4</webjar-stomp-websocket.version>
5654
<webjar-jquery-toast-plugin.version>1.3.2</webjar-jquery-toast-plugin.version>
5755

5856
<spock-version>2.4-M1-groovy-4.0</spock-version>
@@ -206,16 +204,6 @@
206204
<artifactId>bootstrap</artifactId>
207205
<version>${webjar-bootstrap.version}</version>
208206
</dependency>
209-
<dependency>
210-
<groupId>org.webjars</groupId>
211-
<artifactId>sockjs-client</artifactId>
212-
<version>${webjar-sockjs-client.version}</version>
213-
</dependency>
214-
<dependency>
215-
<groupId>org.webjars</groupId>
216-
<artifactId>stomp-websocket</artifactId>
217-
<version>${webjar-stomp-websocket.version}</version>
218-
</dependency>
219207
<dependency>
220208
<groupId>org.webjars.bower</groupId>
221209
<artifactId>jquery-toast-plugin</artifactId>

0 commit comments

Comments
 (0)