Skip to content

Commit

Permalink
don't use sockjs, build fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gtiwari333 committed Oct 8, 2023
1 parent 5c1e351 commit ad52473
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: browser-actions/setup-firefox@v1
- uses: browser-actions/setup-chrome@v1

- name: Set up JDK 21
uses: actions/setup-java@v1
Expand Down
8 changes: 0 additions & 8 deletions main-app/main-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,6 @@
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>jquery-toast-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public void configureMessageBroker(MessageBrokerRegistry config) {

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

}
36 changes: 30 additions & 6 deletions main-app/main-webapp/src/main/resources/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,30 @@
displayUserInfo(ev);
});

initSockJS();
initStompJs();
});


function initSockJS() {
function initStompJs() {

//TODO: implement auto reconnect on disconnect

var socket = new SockJS('/app-websockets-main-endpoint');
stompClient = Stomp.over(socket);
stompClient.connect({}, function (frame) {

stompClient = new StompJs.Client({
brokerURL: 'ws://localhost:8081/app-websockets-main-endpoint',
connectHeaders: {
login: 'user',
passcode: 'password',
},
debug: function (str) {
console.log(str);
},
reconnectDelay: 5000,
heartbeatIncoming: 4000,
heartbeatOutgoing: 4000,
});

stompClient.onConnect = function(frame){

console.log('Connected: ' + frame);
stompClient.subscribe('/topic/global-messages', function (msg) {
Expand All @@ -62,6 +75,17 @@
position: 'top-right',
});
});
});
}

stompClient.onStompError = function (frame) {
// Will be invoked in case of error encountered at Broker
// Bad login/passcode typically will cause an error
// Complaint brokers will set `message` header with a brief message. Body may contain details.
// Compliant brokers will terminate the connection after any error
console.log('Broker reported error: ' + frame.headers['message']);
console.log('Additional details: ' + frame.body);
};

stompClient.activate();
}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<script src="/webjars/jquery/3.6.1/jquery.min.js"></script>
<script src="/webjars/bootstrap/5.0.1/js/bootstrap.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@stomp/[email protected]/bundles/stomp.umd.min.js"></script>
<script src="/webjars/jquery-toast-plugin/1.3.2/dist/jquery.toast.min.js"></script>
<script th:src="@{/static/js/wro-commons.js}"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void loadIndexPageAndVerifyResultIsCached(@Autowired MockMvc mvc) throws Excepti
.andReturn();

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

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

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

Expand Down
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
<commons-io.version>2.14.0</commons-io.version>
<webjar-jquery.version>3.6.1</webjar-jquery.version>
<webjar-bootstrap.version>5.0.1</webjar-bootstrap.version>
<webjar-sockjs-client.version>1.5.1</webjar-sockjs-client.version>
<webjar-stomp-websocket.version>2.3.4</webjar-stomp-websocket.version>
<webjar-jquery-toast-plugin.version>1.3.2</webjar-jquery-toast-plugin.version>

<spock-version>2.4-M1-groovy-4.0</spock-version>
Expand Down Expand Up @@ -206,16 +204,6 @@
<artifactId>bootstrap</artifactId>
<version>${webjar-bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>${webjar-sockjs-client.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>${webjar-stomp-websocket.version}</version>
</dependency>
<dependency>
<groupId>org.webjars.bower</groupId>
<artifactId>jquery-toast-plugin</artifactId>
Expand Down

0 comments on commit ad52473

Please sign in to comment.