Merge branch 'master' of https://github.com/ivanp81/tutorials into ivanp81-master

This commit is contained in:
David Morley
2016-05-12 05:30:15 -05:00
9 changed files with 3053 additions and 1 deletions
@@ -0,0 +1,15 @@
package com.baeldung.model;
public class Message {
private String from;
private String text;
public String getText() {
return text;
}
public String getFrom() {
return from;
}
}
@@ -0,0 +1,27 @@
package com.baeldung.model;
public class OutputMessage {
private String from;
private String text;
private String time;
public OutputMessage(final String from, final String text, final String time) {
this.from = from;
this.text = text;
this.time = time;
}
public String getText() {
return text;
}
public String getTime() {
return time;
}
public String getFrom() {
return from;
}
}
@@ -14,7 +14,7 @@ import org.springframework.web.servlet.DispatcherServlet;
public class MainWebAppInitializer implements WebApplicationInitializer {
private static final String TMP_FOLDER = "C:/Users/ivan/Desktop/tmp";
private static final String TMP_FOLDER = "/tmp";
private static final int MAX_UPLOAD_SIZE = 5 * 1024 * 1024; // 5 MB
/**
@@ -0,0 +1,24 @@
package com.baeldung.spring.web.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(final MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(final StompEndpointRegistry registry) {
registry.addEndpoint("/chat").withSockJS();
}
}
@@ -0,0 +1,23 @@
package com.baeldung.web.controller;
import com.baeldung.model.Message;
import com.baeldung.model.OutputMessage;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;
import java.text.SimpleDateFormat;
import java.util.Date;
@Controller
public class ChatController {
@MessageMapping("/chat")
@SendTo("/topic/messages")
public OutputMessage send(final Message message) throws Exception {
final String time = new SimpleDateFormat("HH:mm").format(new Date());
return new OutputMessage(message.getFrom(), message.getText(), time);
}
}