Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
spring-stomp-chat
=================

This is the sourcecode for the [theotherian's blog article](http://www.theotherian.com/2014/03/spring-boot-websockets-stomp-chat.html).

See also [the documentation of stomp in spring](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-overview).

```sh
mvn package
java -jar ./target/spring-stomp-chat-trunk-SNAPSHOT.jar
```

The accounts available are:

```java
auth.inMemoryAuthentication().withUser("ian").password("ian").roles("USER");
auth.inMemoryAuthentication().withUser("dan").password("dan").roles("USER");
auth.inMemoryAuthentication().withUser("chris").password("chris").roles("USER");
```

Please note you need to users to login and one of them to select the other to open the chat window.

7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,20 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.0.0.RC1</version>
<version>1.2.7.RELEASE</version>
</parent>

<properties>
<start-class>com.theotherian.chat.Application</start-class>
<spring.version>4.0.1.RELEASE</spring.version>
</properties>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/theotherian/chat/WebSocketConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.converter.MessageConverter;
import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver;
import org.springframework.messaging.handler.invocation.HandlerMethodReturnValueHandler;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketTransportRegistration;

/**
* Set up our websocket configuration, which uses STOMP, and configure our endpoints
Expand Down Expand Up @@ -47,4 +50,19 @@ public ActiveUserService activeUserService() {
return new ActiveUserService();
}

@Override
public void configureWebSocketTransport(WebSocketTransportRegistration arg0) {
// TODO Auto-generated method stub
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> arg0) {
// TODO Auto-generated method stub
}

@Override
public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> arg0) {
// TODO Auto-generated method stub
}

}
8 changes: 8 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
<script src="sockjs-0.3.4.js"></script>
<script src="stomp.js"></script>
<script src="jquery-2.1.0.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
<link href="chat.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
<div id="userList">
</div>
<div class="alert alert-info" style="position:absolute; bottom:0;">
<div id="login-output" style="margin-top: 10px;">
Please note you need two users logged in to use this application.<br/>
One user must selec the other shown in the pick list to open the chat windows.
</div>
</div>
</div>
<script type="text/javascript">
var stompClient = null;
Expand Down